[R] adding columns to dataframes contained in a list

From: E Hofstadler <e.hofstadler_at_gmail.com>
Date: Wed, 04 May 2011 10:25:06 +0300

hi there,

I have a list of 5 identical dataframes:

mydf <- data.frame(x=c(1:5), y=c(21:25)) mylist <- rep(list(mydf),5)

and a factor variable with 5 levels:

foo <- c(letters[1:5])
foo <- as.factor(foo)

I'd like to add a new variable to each dataframe in the list, each containing only one level of the factor variable. So mylist[[1]] should have a new variable z containing only "a", in mylist[[2]] the new variable z should contain only "b", etc.

(How) can this be done without looping?

All help is greatly appreciated.


R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 05 May 2011 - 06:25:12 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 05 May 2011 - 07:00:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive