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

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -