[英]Create a table with for loop (R)
我是使用 R 軟件的新手,我需要你的幫助。
我在這個數據中有很多變量(列),我需要使用 for 循環將它們呈現在一個表中。 我使用了這段代碼,但表中只保存了一個變量。
有人可以修改代碼嗎?
library(tidyverse)
library(gapminder)
data(gapminder)
for (i in 4:6)
{table_one <- tableby(continent ~ gapminder[[i]],
data = gapminder)
summary(table_one, title = "Gapminder Data", text=TRUE)
write2word(table_one, "table 1.doc",
keep.md = TRUE,
quiet = TRUE,
title = "Maximum ROM of the main movements")
}
原因是文件名是相同的"table 1.doc"
,因此會覆蓋每次迭代中已經生成的表。 我們在運行循環后得到的 output 來自上一次迭代
for (i in 4:6){
table_one <- tableby(continent ~ gapminder[[i]],
data = gapminder)
print(summary(table_one, title = "Gapminder Data", text=TRUE))
filename <- paste0("table", i, ".doc")
write2word(table_one, filename,
keep.md = TRUE,
quiet = TRUE,
title = "Maximum ROM of the main movements")
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.