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
, 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
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)
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,
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
] 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
6 matches
Mail list logo