Peter Dalgaard BSA writes:
Robert Gentleman <rgentlem@stat.auckland.ac.nz> writes:
Peter,
They don't work on purpose. Basically this is the same problem as indexing
beyond the end of an array. In almost all cases it is an error.
To add a variable with a specific name to a data frame how about
x (the dataframe)
var1 the variable
name1 the name
x<-cbind(x,var1)
names(x)[ncol(x)]<-name1
Hm. Not sure about that argument. After all we don't protect against
typing
x$mumble<-17
instead of
x$grumble<-17
Once you're into indexing lists through character variables, shouldn't
you be assumed to know what you're doing? Beginners can do much more
mischief with e.g. dfr$new<-0 which will turn dfr into a list.
However, apropos your construct, watch this:
x<-list()
x[[1]]<-23
names(x)[1]<-"a"
x
names(x)[1]<-"a"
names(x)