Skip to content
Prev 321661 / 398500 Next

group data

Hi,
You could do this:
dat1<- read.table(text="
ID? Value
AL1? 1
AL2? 2
CA1? 3
CA4? 4
",sep="",header=TRUE,stringsAsFactors=FALSE)
?lst1<-split(dat1,gsub("\\d+","",dat1$ID))
res<-do.call(rbind,lapply(seq_along(lst1),function(i) {x1<-lst1[[i]]; x1$group<- paste0("Key",i);x1}))
?res
#?? ID Value group
#1 AL1???? 1? Key1
#2 AL2???? 2? Key1
#3 CA1???? 3? Key2
#4 CA4???? 4? Key2
A.K.



----- Original Message -----
From: Ye Lin <yelin at lbl.gov>
To: Rui Barradas <ruipbarradas at sapo.pt>
Cc: R help <r-help at r-project.org>
Sent: Monday, April 15, 2013 11:50 AM
Subject: Re: [R] group data

What if more generally that the group name doest have anything to do with
the ID, eg. for ID=AL1 and AL2, I want to name the group as "Key1", how can
I approach that?

Thanks,
On Thu, Apr 11, 2013 at 11:54 AM, Rui Barradas <ruipbarradas at sapo.pt> wrote:

            
??? [[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.