如何在R中创建表?

如何在R中创建表?,r,rstudio,prettytable,R,Rstudio,Prettytable,我想为在for循环中重复运行的sqlite命令的输出创建一个表 是我的代码和预期输出的图片 我用Python编写代码时使用PrettyTable。R中是否有类似的选项 为什么不在for循环的每次迭代中预先分配一个数据帧并[over]写入值 循环之前: output <- data.frame('region' = regions) output$good_traffic <- 0 output$bad_traffic <- 0 output[output$region ==

我想为在for循环中重复运行的sqlite命令的输出创建一个表

是我的代码和预期输出的图片


我用Python编写代码时使用PrettyTable。R中是否有类似的选项

为什么不在for循环的每次迭代中预先分配一个数据帧并[over]写入值

循环之前:

output <- data.frame('region' = regions)
output$good_traffic <- 0
output$bad_traffic <- 0
output[output$region == region, 'good_traffic'] <- good_percent
output[output$region == region, 'bad_traffic'] <- bad_percent
print(output)

如果我理解你的意思,你应该试试knitr包中的kable()

library(knitr)
t <- table(mtcars$cyl,
       mtcars$am)
kable(t)

summary(lm(hp ~ cyl, data = mtcars))
coef.lmfit <- coef(summary(lm(hp ~ cyl, data = mtcars)))
kable(coef.lmfit)
库(knitr)

t在控制台或编织文档中输出?@paoloeusebi,我回滚了您对问题的编辑,删除了我们对该问题和已接受答案的唯一上下文。诚然,强烈反对使用图像(),但没有它,答案就毫无意义。SampyKIshan,在未来的问题中,请提供可复制的数据/代码,而不是其图像;有关更多详细信息,请参阅我的链接,但请简要介绍:复制能力;搜索引擎跳过它;屏幕阅读器不能。