Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 将子集函数应用于数据帧列表_R_List_Dataframe_Lapply - Fatal编程技术网

R 将子集函数应用于数据帧列表

R 将子集函数应用于数据帧列表,r,list,dataframe,lapply,R,List,Dataframe,Lapply,我有一个SpatialPolygonDataFrame列表,我可以将其同化为dataframe,如下所示: df.1 <- data.frame(A = c(1:10), B = c(1, 2, 2, 2, 5:10)) df.2 <- data.frame(A = c(1:10), B = c(1, 2, 2, 2, 2, 2, 7:10)) df.3 <- data.frame(A = c(1:10), B = c(1, 2, 2, 4:10)) list.df <

我有一个
SpatialPolygonDataFrame
列表,我可以将其同化为
dataframe
,如下所示:

df.1 <- data.frame(A = c(1:10), B = c(1, 2, 2, 2, 5:10))
df.2 <- data.frame(A = c(1:10), B = c(1, 2, 2, 2, 2, 2, 7:10))
df.3 <- data.frame(A = c(1:10), B = c(1, 2, 2, 4:10))

list.df <- list(df.1, df.2, df.3)
我想直接在
list.df
上应用我的子集。我知道我必须使用
lappy
功能,但不知道如何使用?

这应该可以:

lapply(list.df, function(x)x[x$B!=2,])
或使用
子集

lapply(list.df, subset, B!=2)

如果您只想子集一列,还可以使用“[[”函数

示例列表
lapply(list.df, subset, B!=2)
example_list <- list(iris, iris, iris)
lapply(example_list, "[[", "Species")