我有一个类似这样的列表
#Make dataframes
df1 = data.frame(x = c("a", "b", "c"), y = 1:3, stringsAsFactors = F)
df2 = df1 %>% mutate(y = y*2)
df3 = df1 %>% mutate(y = y*3)
#Make a name for each dataframe
myvar = "fname"
#Combine name and dataframe into a list
mylist = list(myvar, df1)
#Add the other dataframes and name to the list (done in a loop for my bigger dataset
list2 = list(myvar, df2)
mylist = rbind(mylist, list2)
list3 = list(myvar, df3)
mylist = rbind(mylist, list3)
我希望能够提取列表中与 "c" 相关的所有数据的子集。
x y
3 c 3
x y
3 c 6
x y
3 c 9
这是我尝试的方法,但它并没有起作用
#Find all instances of "c"
picksite = "c"
site_indices = which(mylist[,2] == picksite)
mylist[site_indices,]
有什么建议可以做到这一点,甚至可以提供更好地理解列表的链接吗?非常感谢。