Мы можем выполнить очистку строк / столбцов перед выполнением split
foo <- function(...){
r <- list(...)
lapply(r, function(dat) {
m1 <- is.na(dat)|dat == ""
i1 <- rowSums(m1) < ncol(m1)
j1 <- colSums(m1) < nrow(m1)
dat1 <- dat[i1, j1]
facColumns <- sapply(dat1, is.factor)
dat1[facColumns] <- lapply(dat1[facColumns], as.character)
dat1$study.name <- factor(dat1$study.name, levels = unique(dat1$study.name))
l1 <- split(dat1, dat1$study.name)
do.call(rbind, c(l1, make.row.names = FALSE))
}
)
}
lapply(foo(B1, B2), head, 2)
#[[1]]
# study.name group.name outcome ESL prof scope type
#1 Shin.Ellis ME.short 1 1 2 1 1
#2 Shin.Ellis ME.long 1 1 2 1 1
#[[2]]
# study.name group.name outcome ESL prof scope type
#1 Shin.Ellis ME.short 1 1 2 1 1
#2 Shin.Ellis ME.long 1 1 2 1 1
или использованием одного объекта в качестве аргумента
lapply(foo(A), head, 2)
#[[1]]
# study.name group.name outcome ESL prof scope type ESL.1 prof.1 scope.1 type.1
#1 Shin.Ellis ME.short 1 1 2 1 1 1 2 1 1
#2 Shin.Ellis ME.long 1 1 2 1 1 1 2 1 1