I store many objects (e.g. htest or lm) in a list. I would like to access the attributes (like p-values) of each object stored in this list.
I can access one attribute using l[[1]]$p.value
. Is there a solution and access all attributes of one kind and store them in a vector using sapply or something similar?
data <- data.frame(x1 = runif(n = 100),
x2 = runif(n = 100),
x3 = sample(x = c(0,1), size = 100, replace = T))
l <- list()
for(i in 1:2){
l[[i]] <- t.test(data[,i] ~ data[,3])
}
l[[1]]$p.value