[R] problem with conditional column sums
Chel Hee Lee
chl948 at mail.usask.ca
Thu Jan 29 16:42:46 CET 2015
Or, you can also do the same job using 'colSums()' as shown in the below:
> colSums(status=="I")
2010 2011 2012
3 4 4
>
I hope this helps.
Chel Hee Lee
On 1/28/2015 7:31 PM, JSHuang wrote:
> Hi,
>
> I think you need quotation around I like the following:
>> status
> 2010 2011 2012
> 1 A A A
> 2 A I I
> 3 A A A
> 4 U U U
> 5 A A A
> 6 I I I
> 7 U I I
> 8 A U A
> 9 I A U
> 10 I I I
>> apply(start,2,function(x) {sum(x=="I",na.rm=TRUE)})
> X2010 X2011 X2012
> 3 4 4
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/problem-with-conditional-column-sums-tp4702426p4702434.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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