How to use Aggregate function in R

后端 未结 2 1874
滥情空心
滥情空心 2020-12-06 03:17

can you help me please how to properly use aggregate function in R? I have data like this:

SPORT   FLOWS
[1,] \"Other\" \"1\"  
[2,] \"Other\" \"1\"  
[3,] \         


        
相关标签:
2条回答
  • 2020-12-06 03:44

    Assuming your dataframe is named "sport_data", I think you just want:

    aggregate(sport_data, sport_data$SPORT, sum)
    

    If you just have individual counts (that are all equal to 1), then "tabulate" may be a simpler option.

    Please let us know what kind of errors you are getting. (if this doesn't work, or in the future, in your question)

    0 讨论(0)
  • 2020-12-06 03:58
    aggregate(FLOWS ~ SPORT, dat, function(x) sum(as.numeric(x)))
    

    where dat is the name of your matrix.

    Here, the function is.numeric is necessary to transform the second column into numbers.

    0 讨论(0)
提交回复
热议问题