[R] To summary data

Berend Hasselman bhh at xs4all.nl
Mon May 14 10:42:20 CEST 2012


On 14-05-2012, at 07:14, mrzung wrote:

> hi all,
> 
> my data is here,
> --------------------------------------------------------------------------------------------------
> data
> 
>  clss number
> 1    A      1
> 2    B      2
> 3    C      3
> 4    A      4
> 5    B      5
> 6    C      6
> 7    A      7
> 8    B      8
> 9    C      9
> -----------------------------------------------------------------------------------------------------
> I want to this format
> 
> clss number
> A      12
> B      15
> C      18
> 
> is there a way to solve this problem?

?aggregate

mydata <- data.frame(clss=rep(c("A","B","C"),rep=3),number=1:9, stringsAsFactors=FALSE)
aggregate(number ~ .,data=mydata,sum)

Berend



More information about the R-help mailing list