[R] any equivalent SUM IF statement in R

Duncan Murdoch murdoch at stats.uwo.ca
Sun Nov 22 22:21:12 CET 2009


On 22/11/2009 3:44 PM, ychu066 wrote:
> for example, i want to sum all the row entries if column 1 takes the value
> "boy". anyone knows ?

Subset then sum:

sum(M[M[,1] == "boy", ])

Duncan Murdoch




More information about the R-help mailing list