[R] Something Very Easy
arun
smartpink111 at yahoo.com
Wed May 22 03:57:56 CEST 2013
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
More information about the R-help
mailing list