【发布时间】:2020-02-17 00:18:04
【问题描述】:
函数foo1 可以通过一个或多个请求的变量(例如by = ESL == 1 或by == ESL == 1 & type == 4)子集(使用subset())data.frames 列表。
但是,我知道 R 中的 danger of using subset()。因此,我想知道在下面的 foo1 中,我可以使用什么来代替 subset() 来获得相同的输出?
foo1 <- function(data, by){
s <- substitute(by)
L <- split(data, data$study.name) ; L[[1]] <- NULL
lapply(L, function(x) do.call("subset", list(x, s))) ## What to use instead of `subset`
## to get the same output?
}
# EXAMPLE OF USE:
D <- read.csv("https://raw.githubusercontent.com/izeh/i/master/k.csv", header=TRUE) # DATA
foo1(D, ESL == 1)
【问题讨论】:
标签: r list function dataframe subset