使用循环应用 epidisplay 中的 tab1 函数

发布于 2025-01-12 19:06:06 字数 276 浏览 1 评论 0原文

我有一个包含 172 个变量的数据集,我正在尝试为所有变量生成频率表(它们都是分类/字符变量)。我正在使用 epiDisplay 包中的 tab1 函数。我知道如何对单个变量执行此操作,就像我在下面的代码中所做的那样,但是有没有办法一次完成所有操作?我将如何使用循环或 lapply 来做到这一点?

library(epiDisplay)
tab1(data$Race1, sort.group = "decreasing", cum.percent = TRUE)

谢谢!

I have a dataset with 172 variables and I'm trying to generate frequency tables for all of the variables(they're all categorical/character variables). I'm using the tab1 function from the epiDisplay package. I know how to do it for individual variables like I've done in my code below, but is there a way to do it all at once? How would I do this using a loop or lapply?

library(epiDisplay)
tab1(data$Race1, sort.group = "decreasing", cum.percent = TRUE)

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挖鼻大婶 2025-01-19 19:06:06

可能有几种方法可以做到这一点。这可能想尝试这样的事情:

library(epiDisplay)
data <- mtcars # as an example data
f_1 <- function(x){tab1(x, sort.group = "decreasing", cum.percent = TRUE)}
lapply(data, f_1)

如果你不需要图表:

f_1 <- function(x){tab1(x, sort.group = "decreasing", cum.percent = TRUE, graph = FALSE)}
lapply(data, f_1)

There might be several ways to do it. This may want to try something like this:

library(epiDisplay)
data <- mtcars # as an example data
f_1 <- function(x){tab1(x, sort.group = "decreasing", cum.percent = TRUE)}
lapply(data, f_1)

If you do not need graph:

f_1 <- function(x){tab1(x, sort.group = "decreasing", cum.percent = TRUE, graph = FALSE)}
lapply(data, f_1)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文