创建计数 tables 而不在 r 中的数据 table 中提及变量名

Create count tables without mentioning variable names in a data table within r

有没有办法在 R 中为数据 table 中的所有变量创建 count/frequency table 而无需明确提及 table 中的所有变量?

我的数据 table 如下所示:

我需要为 table 中的所有变量创建计数 tables 而无需提及数据 table 中的变量名称。

例如烟雾频率 table 可能如下所示:

有什么建议吗?

同意@markus。只是想添加以下内容 -

try <- data.frame(id= c(1,2,3,4,5),
                    smoke= c(1,0,1,1,0),
                    run= c(1,0,0,1,1),
                    eat= c(0,1,1,1,1),
                    sleep = c(1,0,0,1,1))
X <- lapply(try[,-1], table) #As suggested by markus


func1 <- function(x){
  y <- as.data.frame(x)
  colnames(y) <- c("Values", "Frequency")
  y
}
func1(X$sleep)

输出-

> func1(X$sleep)
  Values Frequency
1      0         2
2      1         3

谢谢!

try <- data.frame(id= c(1,2,3,4,5),
                smoke= c(1,0,1,1,0),
                run= c(1,0,0,1,1),
                eat= c(0,1,1,1,1),
                sleep = c(1,0,0,1,1)) #from Girish

X <- lapply(try[,-1], table) #As suggested by markus

View(X)