tags:

views:

71

answers:

2

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 want name to be interpreted here, not use "name"
}
+1  A: 

check this answer here: http://stackoverflow.com/questions/1105659/r-how-to-add-variable-key-value-pair-to-list-object

Saher
Thanks, but what do I do if the key name is a variable by itself?
David B
+1  A: 

May be ret<-lapply(list$filenames,read.table) will be better?

Cekory
maybe in this case it will, but I would happy to know hot to generally do it.
David B
Generally, ret[[name]] <- x
Cekory
+1 Thanks, the `[[...]]` is what I was looking for!
David B