R:多个svytables到数据帧的列表
我在列表中有一个多个 svytable ,从该列表中,我想通过保存相同的数据结构来使它们单独。
例如:
library(survey)
data(api)
x <- apiclus1
dclus1 <- svydesign(id=~dnum, weights=~pw, data=x, fpc=~fpc)
n <- c("sch.wide", "cname")
for(k in seq_along(n)){
assign((paste0( n[[k]], "_1")),((svytable(as.formula(paste0("~", n[[k]], "+stype")), design = dclus1, na.action=na.pass))))
}
list<- list(sch.wide_1, cname_1)
result <- lapply(list, function(x) ((prop.table(x, margin =2)*100)))
如何从 result 列表表中制作单独的数据帧?
I have a multiple svytable in list and from that list I want to make them separate dataframes by saving the same data structure.
For example:
library(survey)
data(api)
x <- apiclus1
dclus1 <- svydesign(id=~dnum, weights=~pw, data=x, fpc=~fpc)
n <- c("sch.wide", "cname")
for(k in seq_along(n)){
assign((paste0( n[[k]], "_1")),((svytable(as.formula(paste0("~", n[[k]], "+stype")), design = dclus1, na.action=na.pass))))
}
list<- list(sch.wide_1, cname_1)
result <- lapply(list, function(x) ((prop.table(x, margin =2)*100)))
How to make the separate data frames from result list tables?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:简化的方法修改您的循环,并使用
Janitor
包装程序,现在您得到了:
您可以探索
Janitor
软件包并修改PCT格式化,总计,...您所需的输出。不确定您是否要逐一做它,或者您需要一个循环:这是单独获取它们的一种方法:
想为此做一个循环吗?
现在,您有DF_1和DF_2
可能有一个快捷方式,但这就是我到目前为止的工作方式。祝你好运
Edit: simplified approach modifying your for loop and with the use of
janitor
packagenow you got:
you can explore
janitor
package and modify pct formatting, total,... to get your desired output.not sure if you're going to do it 1 by one or you need a loop for it: here's one way for getting them separately:
want to make a loop for it?
now you have df_1 and df_2
there might be a shortcut for it but this is how I'm doing so far. good luck