Just like the title, I would like to replace certain cells in a data.frame which is accessed through get
, a reproducible example to clarify my question:
df <- data.frame( x = rnorm(10),
y = rnorm(10))
I want to replace, say the first element of column x
, in df
as 'A', which is quite easy in the common ways:
df[1,'x']<-NA
However, how could I do this if I have to access df
through another function like get
, what I want to do is something like:
get('df')[1,'x']<-NA
which will throw out an error:
target of assignment expands to non-language object
.
I searched here and other places on Google for a while, a similar question here, but no solution so far.
Is this possible? How if it is.
============ EDIT based on MKR's comment =============== here is the solution:
a<-get('df')
a[1,'x']<-NA
assign('df',a)
rm(a)