我有一个元素列表(示例中的字母)
(l <- list(letters[1:2], letters[2:3]))
# [[1]]
# [1] "a" "b"
# [[2]]
# [1] "b" "c"
And another elements
(r <- letters[2])
# [1] "b"
R函数必须在“b”和“b”之前删除evrything。
所以结果将是这样的:
# [[1]]
# [1] "c"
请问好吗?
提前谢谢
答案 0 :(得分:3)
尝试
out = lapply(l, function(x) x[-c(1,which(x == "b"))])
Filter(length, out)
#[[1]]
#[1] "c"
或@akrun建议
Filter(length,lapply(l, function(x) x[-seq(match("b",x))]))