Try this. First we use outer to form a matrix such that i,j-th entry
is TRUE if i, j are in the same group and unequal and FALSE otherwise.
We apply which on the rows of that matrix to get the groups that are
associated with the row group. We then cbind the components together
using ts class to
try this:
> x <- read.table(textConnection(" id group
+ 1 1 1
+ 2 2 1
+ 3 3 1
+ 4 4 1
+ 5 5 2
+ 6 6 2
+ 7 7 3
+ 8 8 3
+ 9 9 3
+ 10 10 3
+ 11 11 3
+ 12 12 3"), header=TRUE)
> # split by group and process
>
Hi all,
I want to make extra columns in my datafile where the id of every
groupmember is mentioned in separate columns. To explain it better see the
example:
id<-c(1,2,3,4,5,6,7,8,9,10,11,12)
group<-c(1,1,1,1,2,2,3,3,3,3,3,3)
a<-as.data.frame(cbind(id,group))
3 matches
Mail list logo