使用base的另一种方法R
是使用mapply
和substr
:
nc <- nchar("detected") mapply(function(x, y){substr("detected", x, y)}, x=1:(nc-1), y=2:nc) # [1] "de" "et" "te" "ec" "ct" "te" "ed"
没有包你可以这样做:
test_domain <- c("detected") temp <- strsplit(test_domain ,'')[[1]] sapply(1:(length(temp)-1), function(x){paste(temp[x:(x+1)], collapse='')}) # [1] "de" "et" "te" "ec" "ct" "te" "ed"