c*******o 发帖数: 8869 | 1 写一个R PROGRAM 用来分析不同的PROJECT, 每个PROJECT VARIABLE 名字不同, 想大
概写成这样:
VARNAME<- "STUDY1_VAR"
#############################
DATA$VARNAME<- @%^@%^#$%^@#$%^#$%^@
#############################
这样每次分析不同的DATA只要改最前面一行, 输入新的VARNAME就行了, 而不用在
CODE里改来改去。 但是我的思路不工作, 请问怎样是正确的做法呢?
谢了 |
g**********t 发帖数: 475 | 2 VARNAME<- "STUDY1_VAR"
DATA[[VARNAME]]<- @%^@%^#$%^@#$%^#$%^@
这样应该可以。 |
c*******o 发帖数: 8869 | 3 多谢了, DATA[[VARNAME]] WORK了!但是建模的时候又不行了
attach(data)
test<- lme(data=data, data[[VARNAME]]~X*Y, random=-1|Z/U)
DATA[[VARNAME]] 在lme里不好使, 有什么建议吗?
【在 g**********t 的大作中提到】 : VARNAME<- "STUDY1_VAR" : DATA[[VARNAME]]<- @%^@%^#$%^@#$%^#$%^@ : 这样应该可以。
|
g********r 发帖数: 8017 | 4 现抓出来赋给另一个变量也不行么?
【在 c*******o 的大作中提到】 : 多谢了, DATA[[VARNAME]] WORK了!但是建模的时候又不行了 : attach(data) : test<- lme(data=data, data[[VARNAME]]~X*Y, random=-1|Z/U) : DATA[[VARNAME]] 在lme里不好使, 有什么建议吗?
|
z****g 发帖数: 1978 | 5 as.formula( paste( VARNAME, '~X*Y', collapse = '') );
【在 c*******o 的大作中提到】 : 多谢了, DATA[[VARNAME]] WORK了!但是建模的时候又不行了 : attach(data) : test<- lme(data=data, data[[VARNAME]]~X*Y, random=-1|Z/U) : DATA[[VARNAME]] 在lme里不好使, 有什么建议吗?
|
c*******o 发帖数: 8869 | 6 thanks, I will go for goldmember's solution, which make the code more
readable. Your solution should be more suitable in other circumstance.....
【在 z****g 的大作中提到】 : as.formula( paste( VARNAME, '~X*Y', collapse = '') );
|
g********r 发帖数: 8017 | 7 还有as.formula这么个东西呢。又学了一招。
【在 z****g 的大作中提到】 : as.formula( paste( VARNAME, '~X*Y', collapse = '') );
|
z****g 发帖数: 1978 | 8 covert string to formula object.
The formula you put into function is actually a object of class formula,
not a string. So if dynamically parameter binding is wanted, you need to
cast a string as a formula object
?formula
【在 g********r 的大作中提到】 : 还有as.formula这么个东西呢。又学了一招。
|
z****g 发帖数: 1978 | 9 I suggest you use the same formula when running analysis, since you
probably need to extract the result by name from the result object
returned from the function. And the name in the result object, is the name
you pass into the formula.
circumstance.....
【在 c*******o 的大作中提到】 : thanks, I will go for goldmember's solution, which make the code more : readable. Your solution should be more suitable in other circumstance.....
|