Now I have a data frame which is defined as below.
df=data.frame(x1=c(1,2,3),x2=c(4,5,6))
And I only have the string variable of that data.frame
df.str = 'df'
How to change a column of df
(say, assign 0 to df$x1
) without using variable name df
? Only df.str
is allowed therefore you can't write df$x1=0
.
I tried a lot of ways but none of them worked:
df.str$x1=0
df.str[[x1]]=0
df.str[,'x1']=0