如果你要考虑使用的数据帧的列表,这样的事情可能实现你以后
Depth <- c(40,60,70,80,85,90)
D2H <- c(-60,-65,-63,-67,-58,-66)
A1 <- data.frame(Depth, D2H)
set.seed(123) ## these would be your other 7 data frames in your case
A2 <- A1[sample(nrow(A1), nrow(A1), replace = TRUE),]
A3 <- A1[sample(nrow(A1), nrow(A1), replace = TRUE),]
A4 <- A1[sample(nrow(A1), nrow(A1), replace = TRUE),]
A5 <- A1[sample(nrow(A1), nrow(A1), replace = TRUE),]
A6 <- A1[sample(nrow(A1), nrow(A1), replace = TRUE),]
A7 <- A1[sample(nrow(A1), nrow(A1), replace = TRUE),]
A8 <- A1[sample(nrow(A1), nrow(A1), replace = TRUE),]
mydflist <- list(A1, A2, A3, A4, A5, A6, A7, A8)
newlist40 <- lapply(mydflist, function(x) subset(x$D2H, x$Depth == 40))
newlist60 <- lapply(mydflist, function(x) subset(x$D2H, x$Depth == 60))
编辑
newlist40.b <- lapply(newlist40, function(x) if(length(x)==0) x <- NA else x)
newlist40.final <- unlist(lapply(newlist40.b, unique)) ## if you want unique values from each array in list
# newlist40.final <- unlist(newlist40.b) # if you don't
newlist60.b <- lapply(newlist60, function(x) if(length(x)==0) x <- NA else x)
newlist60.final <- unlist(lapply(newlist60.b, unique)) ## if you want unique values from each array in list
# newlist60.final <- unlist(newlist60.b) # if you don't
那么你会得到这种方法的错误?您可以尝试使用'which()'来查找满足条件的行,然后使用'length()'检查令人满意的行数。只有当长度大于'零'时,才可以尝试'subset()'。 – TUSHAr