[R] struggling with "split" function

Dimitri Liakhovitski ld7631 at gmail.com
Sun Sep 6 11:02:49 CEST 2009


I am very sorry for such a simple question, but I am struggling with "split".
I have the following data frame:
x<-data.frame(A=c(NA,NA,NA,NA,"split",NA,NA,NA,NA,"split",NA,NA,NA,NA,"split",NA,NA,NA,NA),
B=c("Name1","text1","text2","text3",NA,"Name2","text1","text2","text3",NA,"Name3","text1","text2","text3",NA,"Name4","text1","text2","text3"),
C=c(NA,1,NA,3,NA,NA,4,5,6,NA,NA,7,8,9,NA,NA,3,3,3),D=c(NA,1,1,2,NA,NA,5,6,NA,NA,NA,9,8,7,NA,NA,2,2,2),
E=c(NA,3,2,1,NA,NA,6,5,4,NA,NA,7,7,8,NA,NA,1,NA,1))
print(x)

All I want to do is to split x, i.e., to create a list of data frames
that are currently separated by the word "split" in column A. In this
example, it would be 4 data frames, the first of them being:
A B C D E
NA Name1 NA NA NA
NA text1 1 1 3
NA text 2 NA 1 2
NA text3 3 2 1

etc.

I tried:
split(x, x$A)
split(x,x$A == 'split')
split(x,!is.na(x$A))

But nothing produces what I need.
Tanks a lot for any hint!

-- 
Dimitri Liakhovitski
Ninah.com
Dimitri.Liakhovitski at ninah.com




More information about the R-help mailing list