上下文:我想将累积总和列添加到名为 words_uni 的 tibble 中。我使用库(dplyr),函数变异。我使用 R 版本 3.4.1 64 位 - Windows 10 和 RStudio 版本 1.0.143
> head(words_uni)
# A tibble: 6 x 3
# Groups: Type [6]
Type Freq per
<chr> <int> <dbl>
1 the 937839 0.010725848
2 i 918552 0.010505267
3 to 788892 0.009022376
4 a 615082 0.007034551
然后我做了以下事情:
> words_uni1 = words_uni %>%
mutate( acum= cumsum(per))
> head(words_uni1)
# A tibble: 6 x 4
# Groups: Type [6]
Type Freq per acum
<chr> <int> <dbl> <dbl>
1 the 937839 0.010725848 0.010725848
2 i 918552 0.010505267 0.010505267
3 to 788892 0.009022376 0.009022376
4 a 615082 0.007034551 0.007034551
问题:它没有达到我的预期,我不明白为什么。
我会很感激你的意见。提前致谢。