[R] for loop in assigning column names
Luis Ridao Cruz
Luisr at frs.fo
Wed Mar 21 16:14:16 CET 2007
R-help,
I have a data frame (df) and I want to add some columns whose names
should correspond to the "i" index in the loop below.
for(i in 1:10)
{
df$eval(paste("St", as.character(i), sep = "" )) <- ObJeCt[i]
}
An error message comes out :
"Error: attempt to apply non-function"
How can I get around this?
I could do something like :
df$St2 <- NA
df$St3 <- NA
dft$St4 < -NA
..
and afterwards assign the results of the loop above
to the columns df$St2,df$St3,,,,,,,,,,,
The problem is that my object "ObJeCt[i]" may change in size
and definition and therefore a way to systematize the task would
be desirable.
Thanks in advance
> version
_
platform i386-pc-mingw32
arch i386
os mingw32
system i386, mingw32
status
major 2
minor 4.1
year 2006
month 12
day 18
svn rev 40228
language R
version.string R version 2.4.1 (2006-12-18)
More information about the R-help
mailing list