简体   繁体   English

使用 for 循环从列表中的 R 对象中提取信息

[英]extract information from R objects in a list with a for loop

I have a list of objects, where each object is a dataframe.我有一个对象列表,其中每个对象都是一个数据框。

list_of_dfs<-(df1, df2, df3,....)

Suppose I want to extract information from the first column of each dataframe, say suppose extract all values of column 1 which is above 0.5, how do I use a for loop to do that?假设我想从每个数据帧的第一列中提取信息,假设提取第 1 列中高于 0.5 的所有值,我该如何使用 for 循环来做到这一点?

Complication: It might be that each dataframe is only a "name" in the list_of_dfs however running the name itself in the console eg '>df1' would generate dataframe information.复杂性:可能每个数据帧只是 list_of_dfs 中的一个“名称”,但是在控制台中运行名称本身,例如 '>df1' 会生成数据帧信息。

Thanks for your consideration and advice.感谢您的考虑和建议。

If you first columns have all the same name, eg col_1 you could use a map to apply filter to all of them at once如果您的第一列具有所有相同的名称,例如col_1您可以使用map一次将filter应用于所有列

library(tidyverse)
list_of_dfs <- (df1, df2, df3,....)
map(list_of_dfs, filter, col_1 > 0.5)
map(list_of_dfs, ~ filter(., col_1 > 0.5)) # equivalent

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM