문제

Suppose I have the following code

a<-c(1,2,3)
b<-'a'

Now I was to treat the string in 'b' as the variable 'a' when I input it into some function or operation. Like imagine that "treat.as.variable()" was a real function it would do this:

treat.as.variable(b)+c(1,2,4)
[1] 2 4 7

is there a function like this, predefined? Or a way to do this in general?

도움이 되었습니까?

해결책

Use get function

> get(b) + c(1,2,4)
[1] 2 4 7
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top