[R] Something Very Easy
John Kane
jrkrideau at inbox.com
Wed May 22 16:02:51 CEST 2013
Using arun, data set, dat1
Is this type of thing what you want?
dat2 <- subset(dat1, dat1$Play != "B" & dat1$Offense == "Y")
with(dat2,table(Play, Offense))
John Kane
Kingston ON Canada
> -----Original Message-----
> From: smartpink111 at yahoo.com
> Sent: Tue, 21 May 2013 18:57:56 -0700 (PDT)
> To: r-help at r-project.org
> Subject: Re: [R] Something Very Easy
>
> 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 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.
____________________________________________________________
FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!
More information about the R-help
mailing list