将数据帧列表中的值视为 r 中的一个 object

Treating values in a list of data frames as one object in r

我正在尝试将各种分析函数(lm、plot 等)应用于一长串数据框。所有数据框都有相同的列标题,我想为数据框中每个列标题下的所有数据计算 1 个结果。我不知道如何使用 'unlist' 函数来执行此操作。

对于下面的例子,我想要一个 n = 15 的图,以及一个所有 $a ~ 所有 $b 的线性模型。

d1 <- data.frame(a=rnorm(5), b=1:5, c=rnorm(5))
d2 <- data.frame(a=1:5, b=rnorm(5), c =rnorm(5))
d3 <- data.frame(a=1:5, b=rnorm(5), c= rnorm(1:5))

my_test_data <- list()

my_test_data <- list(d1, d2, d3)

我什么都试过了,包括:

plot(unlist(my_test_data), my_test_data$a)

lm(my_test_data$a ~ my_test_data$b, unlist(my_test_data))

让我知道我错过了什么 - 非常感谢所有帮助。

您可以使用 rbind 来组合 data.frames?

d1 <- data.frame(a=rnorm(5), b=1:5, c=rnorm(5))
d2 <- data.frame(a=1:5, b=rnorm(5), c =rnorm(5))
d3 <- data.frame(a=1:5, b=rnorm(5), c= rnorm(1:5))

my_test_data <- rbind(d1, d2, d3)

m <- lm(a ~ b, data = my_test_data)
plot(a ~ b, data = my_test_data)
abline(m)