[R] Create a unique group id

2014-01-02 Thread Norbi Gurracho
I have a following sample data frame. How can I create a group id of column and b and to obtain column c? a b c 1 1 1 1 1 1 1 1 1 1 2 2 1 2 2 1 2 2 1 3 3 1 3 3 1 3 3 2 1 4 2 1

Re: [R] Create a unique group id

2014-01-02 Thread PIKAL Petr
, January 02, 2014 12:33 PM To: r-help@r-project.org Subject: [R] Create a unique group id I have a following sample data frame. How can I create a group id of column and b and to obtain column c? ab c 1 1 1 1 1 1 1 1 1 1 2 2 1 2

Re: [R] Create a unique group id

2014-01-02 Thread arun
Hi, Try: dat - read.table(text=a    b    c  1    1    1  1    1    1  1    1    1  1    2    2  1    2    2  1    2    2  1    3    3  1    3    3  1    3    3  2    1    4  2    1    4  2    1    4  2    2    5  2    2    5  2    2    5  2    2    5,sep=,header=TRUE)   

Re: [R] Create a unique group id

2014-01-02 Thread arun
Hi, Also, to make it general: vec1 - with(dat,paste(a,b))  within(dat,d - as.numeric(factor(vec1,labels=seq(length(unique(vec1)) #or  within(dat,d - match(vec1,unique(vec1))) #or within(dat,d- as.numeric(interaction(a,b))) #ids are unique, not in the same order A.K. On Thursday,

Re: [R] Create a unique group id

2014-01-02 Thread Norbi Gurracho
Subject: Re: [R] Create a unique group id To: r-help@r-project.org CC: kum...@hotmail.com Hi, Also, to make it general: vec1 - with(dat,paste(a,b)) аwithin(dat,d - as.numeric(factor(vec1,labels=seq(length(unique(vec1)) #or аwithin(dat,d - match(vec1,unique(vec1))) #or within(dat,d

Re: [R] Create a unique group id

2014-01-02 Thread arun
] Create a unique group id To: r-help@r-project.org CC: kum...@hotmail.com Hi, Also, to make it general: vec1 - with(dat,paste(a,b)) аwithin(dat,d - as.numeric(factor(vec1,labels=seq(length(unique(vec1)) #or аwithin(dat,d - match(vec1,unique(vec1))) #or within(dat,d- as.numeric