HI, I am not sure about what you expect as output. dat1<- read.table(text=" Offense Play Y A N B Y A Y C N B N C ",sep="",header=TRUE,stringsAsFactors=FALSE)
with(dat1,tapply(Play,list(Offense),table)) #$N # #B C #2 1 # #$Y # #A C #2 1 #or with(dat1,tapply(factor(Play),list(Offense),table)) #$N # #A B C #0 2 1 # #$Y # #A B C #2 0 1 A.K. >I have lines of data that look like this: > >Offense Play >Y A >N B >Y A >Y C >N B >N C > >with a bunch of other variables. > >I just want to get a table like >table(Play[Offense=="Y"]) >but one that would return, for the data above: >A 2 >C 1 > >Instead of what I get now, from >table(Play[Offense=="Y"]): > >A 2 >B 2 >C 2 ______________________________________________ R-help@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.