我有一个如下所示的 data.frame:
> dat <- data.frame(Operation = c("Login", "Posted", "Deleted"), `Total Count` = c(5, 25, 40), check.names = FALSE)
> dat
Operation Total Count
1 Login 5
2 Posted 25
3 Deleted 40
我想计算每个操作的百分比,例如,操作的百分比是多少Login
。我希望得到如下结果:
Operation Total Count Percentage
1 Login 5 0.07142857
2 Posted 25 0.35714286
3 Deleted 40 0.57142857
由于计数已经汇总,table()
因此不起作用:
> table(dat$`Total Count`)
5 25 40
1 1 1