push to list in R
OK, this really basic. How do I add an element to a (named) list in R?
EDIT when the key name is a varibale
for (name in names(list$filenames)) {
filename <- list$filenames[[name]]
x <- read.table(filename)
ret$name <- x # I wan开发者_开发技巧t name to be interpreted here, not use "name"
}
Perhaps ret<-lapply(list$filenames,read.table)
will be better?
Re:
ret$name <- x # I want name to be interpreted here, not use "name"
That's the same thing as this:
ret[["name"]]
Do this instead:
ret[name]
Or if you want a simple vector back rather than something as the same type as ret, do this:
ret[[name]]
精彩评论