![](/img/trans.png)
[英]Extracting the same column from multiple data frames and cbind them into a new data frame in R
[英]extracting particular column from a list of multiple data frames and combine them into a new data frame in r
如何提取列表中多個數據幀的特定列,例如所有dfs的第8列,並將提取的列合並為一個新的數據幀。
我使用的是for循環,無法提供所需的輸出。 我更喜歡使用lapply()函數而不是for循環。 你知道我該怎么做嗎?
new_df <- data.frame()
for(i in 1:length(list_of_dfs)){
col_8 <- list_of_dfs[[i]][8]
new.df[i] <- col_8
}
View(df)
您可以使用lapply
和do.call
來實現:
library(magrittr)
lapply(list_of_dfs,function(i) i[,8]) %>% do.call(cbind,.) %>% data.frame
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.