[R] accessing names of lists in a list
tomtomme
langkamp at tomblog.de
Wed Jul 6 21:24:24 CEST 2011
After importing multiple files to data.frames in R, I want to rename all
their columns and do other operations with them. The data.frame names are
not continuous like 1, 3, 4, 6.
I could not find a way of creating a list of the data.frames and loop this
and ended up putting them into a list first:
# get all objects
all.obj = sapply(ls(), get)
# get data frames
dfrs = all.obj[sapply(all.obj, is.data.frame)]
but then I get lists within lists:
structure(list(`1` = structure(list(Datum = structure(c(...
my problem now is how to access the inner list, for example to rename the
"Datum" to "date". The following changes only the outer list:
names(dfrs) <- c("date", "time", "temp","")
with the result:
structure(list(date = structure(list(Datum = structure(c(...
Or isn´t there a way to avoid the list and just loop through the data.frames
of your workspace regardless of number and naming of the data.frames and
thus apply different operations on them like the renaming of the columns?
Many thanks!
--
View this message in context: http://r.789695.n4.nabble.com/accessing-names-of-lists-in-a-list-tp3649750p3649750.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list