[R] puzzles with assign()

David.Epstein David.Epstein at warwick.ac.uk
Wed May 5 11:47:47 CEST 2010

I'm trying to get code along the following lines to work:
temp.name <- paste(TimePt,'df',sep='.') # invent a relevant name/symbol as a
character string.
assign(temp.name,IGF.df[IGF.df$TPt==TimePt,]) # this works. The relevant
variable is now a data frame
lm(b ~ Strain+BWt+PWt+PanPix, data=temp.name)) # this gives an error, namely
Error in eval(predvars, data, env) : invalid 'envir' argument

I think it's obvious what I want to achieve, but how is it done? I tried
but that also didn't work. I can't find anything relevant in "Introduction
to R".

Here is a secondary question:
While trying to understand what assign() does, I looked up help(assign) and
found the example
a <- 1:4
assign("a[1]", 2)
a[1] == 2          #FALSE
get("a[1]") == 2   #TRUE
Could someone explain this puzzling example, or point me to an explanation
of environments and how to operate with them?


View this message in context: http://r.789695.n4.nabble.com/puzzles-with-assign-tp2130691p2130691.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list