Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 按月计算NPS分数_R_Dataframe - Fatal编程技术网

R 按月计算NPS分数

R 按月计算NPS分数,r,dataframe,R,Dataframe,我在R中有一个数据帧,它有以下列: 年 月 NPS分数 例如: Year Month NPS 16 June 8 16 June 3 16 July 4 16 July 10 16 Aug 3 16 Aug 1 16 Sept 8 我想做的是创建一个新的数据框架,用于计算每个月的NPS分数。所以看起来是这样的: Year Month Monthly NPS 16 June 45 16 July 35 16

我在R中有一个数据帧,它有以下列:

  • NPS分数
例如:

Year Month NPS
16   June   8
16   June   3
16   July   4
16   July   10
16   Aug    3
16   Aug    1
16   Sept   8
我想做的是创建一个新的数据框架,用于计算每个月的NPS分数。所以看起来是这样的:

Year Month Monthly NPS
16   June     45
16   July     35
16   Aug      24.5
16   Sept     37.3

我不知道如何在R做这件事。任何帮助都将是伟大的

假设您在示例中包含的总计值不正确,您可以使用dplyr库计算每月值,如下所示:

library(dplyr)

df <- data.frame(year = rep(16, 7),
                 month = c("June", "June", "July", "July", "Aug", "Aug", "Sept"),
                 NPS = c(8, 3, 4, 10, 3, 1, 8))


summarise(group_by(df, year, month), sum(NPS))
库(dplyr)

df不清楚您是如何获得预期输出的。^同上,您到目前为止做了哪些尝试?