【发布时间】:2015-11-26 03:56:35
【问题描述】:
我很难从列表中选择满足某个功能的元素。因此,用解决方案记录相同的内容。
check.digits <- function(x){ grepl('^(\\d+)$' , x) }
x = "741 abc pqr street 71 15 41 510741"
lx = strsplit(x, split = " ", fixed = TRUE)
lapply(lx, check.digits)
这不起作用 -
lx[[1]][c(lapply(lx, check.digits))]
使用-
lx[[1]][sapply(lx, check.digits)]
谢谢!!!
【问题讨论】: