How to average score from different elements

This question already has an answer here:

  • Mean per group in a data.frame [duplicate] 8 answers
  • Aggregate / summarize multiple variables per group (eg sum, mean) 4 answers
  • How to make a great R reproducible example? 23 answers

  • 我们可以尝试

    library(data.table)
    setDT(data)[, list(avg = mean(Score)), by = AD]
    

    library(data.table)
    dt <-  data.table(ur_data)
    dt[, lapply(.SD, mean), by = "AD"]
    

    I'd recommend the dplyr package.

    require(dplyr)
    data %>% 
     group_by(AD) %>% 
     summarize(avg = mean(Score))
    

    Is that what you're looking for?

    链接地址: http://www.djcxy.com/p/24882.html

    上一篇: 如何用R数据框中的零代替NA值?

    下一篇: 如何平均来自不同元素的分数