[R] splitting data frame into fixed rows depending on column rep

Ragia Ibrahim ragia11 at hotmail.com
Sun Dec 6 10:55:44 CET 2015


Dear group,

I have the following data frame

            v1 v2  v3 v4 v5
1           1  3 1   3.5    1
2           1  4 3   3.5    1
3           1  8 3   3.5    1
4           2  9 8   2.5    1
5           2 10 9   2.5    1
6           2  6 3   1.5    1
7           3  4 3   2.0    1
8           3  5 3   1.0    1
9           3  8 3   1.0    1
10          4  9 8   2.0    1
11          4  6 5   1.0    1
12          4  8 4   1.0    1
13          5  4 3   2.0    1
14          5  5 3   2.0    1
15          5  6 5   2.0    1

I'm trying to split it into data frames where each equal v1 so all v1==1 in data frame and all v1==2 in separate data frame and so on.
so it would be

        v1 v2  v3 v4 v5
1           1  3 1   3.5    1
2           1  4 3   3.5    1
3           1  8 3   3.5    1
then
            v1 v2  v3 v4 v5
4           2  9 8   2.5    1
5           2 10 9   2.5    1
6           2  6 3   1.5    1
.......
...
and so on

I tried 
a<- split(df, df$v1==1) 
but the resulting class is a list and when I try to access for example a$v2 it gave me NULL ??

how can I split it an get each vector of v2 for each group, 
lots of thanks
Ragia 		 	   		  


More information about the R-help mailing list