I have a string like that
我有一个这样的字符串
mystring<-"A+B+C"
a data where A, B and C as varialles. How do I get this into a command like
数据,其中A,B和C为变量。我怎么把它变成像这样的命令
x<-A+B+C
using mystring as above. Thanks for any hint
使用如上所述的mystring。谢谢你的任何提示
1 个解决方案
#1
1
You can use eval
and parse
您可以使用eval和parse
A <- 1
B <- 2
C <- 3
x <- eval(parse(text = "A+B+C"))
x
## [1] 6
#1
1
You can use eval
and parse
您可以使用eval和parse
A <- 1
B <- 2
C <- 3
x <- eval(parse(text = "A+B+C"))
x
## [1] 6