Re: [R] rowsum- is there a countsum

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Sat, 26 Jan 2008 10:47:43 -0500

Try this (adding 0 converts the logicals to numeric):

rowsum((X > 0)+0, group)

On Jan 26, 2008 9:13 AM, Anders Bjørgesæter <abjrges_at_getmail.no> wrote:
> Hello
>
> Is there an analogous function to "rowsum" that count the numbers
> according to a given vector (preferably larger than a given value)
> instead of summing them?
>
> E.g. rowsum(x, group)
>
> X is the dataframe, A B C
> 5 0 0
> 1 3 3
> 0 1 12
> and group is the vector; 1,1,2
>
> rowsum gives: A B C
> 1 6 3 3
> 2 0 1 12
>
>
> I want: A B C
> 1 2 1 1
> 2 0 1 1
>
> for e.g. count all > 0.
>
> Best Regards
> Anders
>
> ______________________________________________
> 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.
>



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 Sat 26 Jan 2008 - 15:52:18 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 Sat 26 Jan 2008 - 17:30:09 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