-2

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

这些

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

我在 Python 中编码时使用 PrettyTable。R中有类似的选项吗?

4

2 回答 2

-1

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

在循环之前:

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)
于 2018-11-02T21:17:47.143 回答
-1

如果我理解您的意思,您应该尝试使用 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)
于 2018-11-02T21:30:26.647 回答