> token_list <- unique(unlist(parse)) > lapply(parse,function(s)sapply(s, function(w) (1:length(token_list))[token_list %in% w] )) [[1]] T h e c a t s a t o n t h e m a t . 1 2 3 4 5 6 7 4 8 6 7 4 9 10 4 7 2 3 4 11 6 7 12
[[2]] T h e d o g a t e m y h o m e w o r k . 1 2 3 4 13 9 14 4 6 7 3 4 11 15 4 2 9 11 3 16 9 17 18 12
Comments 1
> parse <- strsplit(samples, "")
> parse
[[1]]
[1] "T" "h" "e" " " "c" "a" "t" " " "s" "a" "t" " " "o" "n" " " "t" "h" "e" " "
[20] "m" "a" "t" "."
[[2]]
[1] "T" "h" "e" " " "d" "o" "g" " " "a" "t" "e" " " "m" "y" " " "h" "o" "m" "e"
[20] "w" "o" "r" "k" "."
> token_list <- unique(unlist(parse))
> lapply(parse,function(s)sapply(s, function(w) (1:length(token_list))[token_list %in% w] ))
[[1]]
T h e c a t s a t o n t h e m a t .
1 2 3 4 5 6 7 4 8 6 7 4 9 10 4 7 2 3 4 11 6 7 12
[[2]]
T h e d o g a t e m y h o m e w o r k .
1 2 3 4 13 9 14 4 6 7 3 4 11 15 4 2 9 11 3 16 9 17 18 12
Reply
Leave a comment