[R] help with text patterns in strings

Crombie, Burnette N bcrombie at utk.edu
Thu Jun 20 15:38:17 CEST 2013


Thanks, Arun.  I will study this as soon as possible.  I really appreciate your time and R mentoring.
________________________________________

Try this:
res1<-sapply(vec3,function(x) length(vec2New[grep(x,vec2New)]) )
dat1<-data.frame(res1,Name=names(vec3))

 dat1$Name<-factor(dat1$Name,levels=c("early","mid","late","wknd"))
 with(dat1,tapply(res1,list(Name),FUN=sum))
#early   mid  late  wknd
 #   0     1     4     6

#or
 sapply(split(res1,names(vec3)),sum)
#early  late   mid  wknd
 #   0     4     1     6
A.K.


More information about the R-help mailing list