names

How to use reference variables by character string in a formula?

时光怂恿深爱的人放手 提交于 2019-11-26 03:38:05
问题 In the minimal example below, I am trying to use the values of a character string vars in a regression formula. However, I am only able to pass the string of variable names (\"v2+v3+v4\") to the formula, not the real meaning of this string (e.g., \"v2\" is dat$v2). I know there are better ways to run the regression (e.g., lm(v1 ~ v2 + v3 + v4, data=dat) ). My situation is more complex, and I am trying to figure out how to use a character string in a formula. Any thoughts? Updated below code #

How to use reference variables by character string in a formula?

房东的猫 提交于 2019-11-26 03:11:12
问题 In the minimal example below, I am trying to use the values of a character string vars in a regression formula. However, I am only able to pass the string of variable names (\"v2+v3+v4\") to the formula, not the real meaning of this string (e.g., \"v2\" is dat$v2). I know there are better ways to run the regression (e.g., lm(v1 ~ v2 + v3 + v4, data=dat) ). My situation is more complex, and I am trying to figure out how to use a character string in a formula. Any thoughts? Updated below code #

Access lapply index names inside FUN

梦想的初衷 提交于 2019-11-26 01:29:28
问题 Is there a way to get the list index name in my lapply() function? n = names(mylist) lapply(mylist, function(list.elem) { cat(\"What is the name of this list element?\\n\" }) I asked before if it\'s possible to preserve the index names in the lapply() returned list, but I still don\'t know if there is an easy way to fetch each element name inside the custom function. I would like to avoid to call lapply on the names themselves, I\'d rather get the name in the function parameters. 回答1: