Re: [R] Getting number of students with zeroes in long format

From: Jorge Ivan Velez <jorgeivanvelez_at_gmail.com>
Date: Wed, 06 Apr 2011 16:58:07 -0400

Hi Chris,

Is this what you have in mind?

> sum(with(yourdata, tapply(sus, id_r, function(x) any(x==0))))
[1] 13

HTH,
Jorge

On Wed, Apr 6, 2011 at 4:44 PM, Christopher Desjardins <> wrote:

> Hi,
> I have longitudinal school suspension data on students. I would like to
> figure out how many students (id_r) have no suspensions (sus), i.e. have a
> code of '0'. My data is in long format and the first 20 records look like
> the following:
>
> > suslm[1:20,c(1,7)]
> id_r sus
> 11 0
> 15 10
> 16 0
> 18 0
> 19 0
> 19 0
> 20 0
> 21 0
> 21 0
> 22 0
> 24 0
> 24 0
> 25 3
> 26 0
> 26 0
> 30 0
> 30 0
> 31 0
> 32 0
> 33 0
>
> Each id_r is unique and I'd like to know the number of id_r that have a 0
> for sus not the total number of 0. Does that make sense?
> Thanks!
> Chris
>
> [[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.
>

        [[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. Received on Wed 06 Apr 2011 - 21:03:56 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 06 Apr 2011 - 21:10:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive