12/06/04 19:49:05.43
>>551, 552
あぁ、そうだね。
わざわざ1:lenght(pattern)でやるより、簡潔にsapply(pattern, function(x) ...)でよかった。
ご指摘ありがとう。
> target <- apply(matrix(sample(letters[1:6], 4 * 10000, replace = TRUE), ncol = 4), 1, paste, collapse = '')
> pattern <- c("ab","ef")
> system.time(target[unique(unlist(sapply(1:length(pattern), function(i){grep(pattern[i], target)})))])
ユーザ システム 経過
0.004 0.000 0.005
> system.time(unique(c(sapply(pattern, function(x) grep(x, target, value=TRUE)))))
ユーザ システム 経過
0.004 0.000 0.007
速度的にはあまり変わらないみたいだが。