Grouping data based on a field in R -
i using r complete following task. have dataset looks this:
item category price aaa 1 10.00 bbb 2 5.00 ccc 3 20.00 ddd 1 25.00 eee 3 5.00 fff 2 15.00
is possible group items categories , calculate summary statistics (ex. average or total sum of price)?
so essentially, i'm trying create this:
cateogry averageprice 1 17.50 2 10.00 3 12.50
thanks help!
assuming that's data.table
(which give best performance , syntax):
library(data.table) dt <- data.table(mydf) # mydf original data.frame dt[, list(averageprice = mean(price), sumofprices = sum(price)), = category]
Comments
Post a Comment