我有一个看起来像这样的数据集(实际上它有> 50列)
data <- read.csv("sample.csv")
subject gender age type satisfation agree
1 f 22 a yes yes
2 f 23 b no yes
3 f 21 b no
4 m 24 c yes yes
5 f 22 b no yes
6 m a yes yes
7 25 c yes no
8 m 21 b no yes
9 f 23 c yes yes
Run Code Online (Sandbox Code Playgroud)
我想计算每列中的元素(不计算NA)并将结果导出为下面的布局
subject gender age type satisfation agree
9 8 8 9 8 9
Run Code Online (Sandbox Code Playgroud)
我写了一个脚本来计算
counting <- function(x) { …Run Code Online (Sandbox Code Playgroud)