Dear R-user,
 I have a simple question, I just can't figure out a easy way to handle it.
 My importing data x is like this:
  COL1 COL2 id
1 12 49 1
2 70 120 1
3 58 124 1
51 14 13 2
52 88 100 2
53 90 134 2
 I want to change the format of the data, i want to group data into 
differenct part according id,so that when i use x[1], which will refer me to 
the information about first id.I use the command:
 
list(list(N=2,n=c(100,150),matrix(c(x[x$id==1,][,1],x[x$id==1,][,2]),nr=2,nc=3)),list(N=2,n=c(100,150),matrix(c(x[x$id==2,][,1],x[x$id==2,][,2]),nr=2,nc=3)))

so the data becomes :

[[1]]
[[1]]$N
[1] 2

[[1]]$n
[1] 100 150

[[1]][[3]]
[,1] [,2] [,3]
[1,] 12 58 120
[2,] 70 49 124


[[2]]
[[2]]$N
[1] 2

[[2]]$n
[1] 100 150

[[2]][[3]]
[,1] [,2] [,3]
[1,] 14 90 100
[2,] 88 13 134

This is the format I want, but problem is that for my data, id is not only 1 
to 2,but 1 to 100, so my code is not efficient. Could you help me find a 
efficient way? Thanks.

 Qi Zhang

PhD student,

University of Cincinnati

        [[alternative HTML version deleted]]

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to