I have an object like this:
d1 <- data.frame(y1=c(1,2,3),y2=c(4,5,6))
d2 <- data.frame(y1=c(3,2,1),y2=c(6,5,4))
d3 <- data.frame(y1=c(7,8,9),y2=c(5,2,6))
my.list <- list(d1, d2, d3)
names(my.list) <- c("d1","d2","d3")
Is there a way to access the column y2
of all data frames inside the list once?
Something like this:
my.list[["d1"]]$y2
But this only works for one data frame at a time
Try
lapply(my.list, '[[', 'y2')
Or use sapply
to get the output as a matrix
sapply(my.list, `[[`, 'y2')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With