[R] rowsum- is there a countsum
Gabor Grothendieck
ggrothendieck at gmail.com
Sat Jan 26 16:47:43 CET 2008
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.
>
More information about the R-help
mailing list