[英](R) Loop objects on Environment into a function and export results
我想從幾個數據框中導出圖。
我嘗試使用 1)for 循環並將 ls() 傳遞給 2) 函數,但無論如何,我使用的函數 (regplot) 只能到達字符向量:數據錯誤 [,1] :不正確的維數
cbind.data.frame(x = 0:6, y = c(1, 2, 3, 6.1, 5.9, 6, 6.1)) -> data1
cbind.data.frame(x = 0:6, y = c(2, 4, 6, 12.2, 11.8, 12, 12.2)) -> data2
require(easyreg)
for (i in base::ls()) { i |> easyreg::regplot(model = 3) }
test_fun <- function(x) { x |> regplot(model=3) }
test_fun(ls())
for (i in base::ls()) {
svglite::svglite(filename = paste0(i,".svg"))
i |> easyreg::regplot(model = 3)
dev.off()
}
您可以跳過第 2 步和第 3 步。
# require(svglite)
for (i in ls(pattern = "data")) { # Assuming that all the dataframes'names contain the word "data"
svglite::svglite(filename = paste0(i,".svg"))
get(i) |> easyreg::regplot(model = 3)
dev.off()
}
受此評論啟發
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.