我正在尝试在R中的数据框中添加(特定向量中的所有计数)的总和。具体来说,我想保留所有计数,然后在结尾添加一个总和。在excel中,你会做= sum(A1:A5232)。另外,我不知道特定载体的长度。见下文:
#sumarize by colname
NewDepartment <- List %>%
group_by(NewDepartment) %>%
tally(sort=TRUE)
NewDepartment n
<chr> <int>
1 <NA> 709
2 Collections 454
3 Telesales 281
4 Operations Control Management 93
5 Underwriting 92
NewDepartment n
<chr> <int>
1 <NA> 709
2 Collections 454
3 Telesales 281
4 Operations Control Management 93
5 Underwriting 92
6 Total Sum 1721
如何获得上面的第6行?
答案 0 :(得分:1)
试试这个:
NewDepartment = rbind(NewDepartment,
data.frame(NewDepartment = "Total Sum", n = sum(NewDepartment$n)))