one way is the following:

df <- data.frame(month = as.character(rep(1:3, each = 30)), fac = factor(rep(1:2, each = 15)), data1 = round(runif(90), 2), data2 = round(runif(90), 2))

lapply(split(df, df$month), function(x) split(x, x$fac))


I hope it helps.

Best,
Dimitris


Lauri Nikkinen wrote:
R users,

I would like to split this df by month and fac and produce list of sublists

df <- 
data.frame(month=as.character(rep(1:3,each=30)),fac=factor(rep(1:2,each=15)),
            data1=round(runif(90),2),
            data2=round(runif(90),2))

This

split(df, paste(df$month, df$fac))

produces just a single list. Any ideas?

Many thanks,
Lauri

______________________________________________
R-help@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.


--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014

______________________________________________
R-help@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.

Reply via email to