I would like to extracts small word parts (quadgrams) from text. Example:
hello world
results in:
_hel, hell, ello, llo_, lo_w ...
This my basic attempt thus far:
text <- "hello world"
number_of_characters <- nchar(text)
quad_gram_list <- ""[-1]
for (i in 1:number_of_characters) {
end <- i + 3
if (end > number_of_characters) {
end <- number_of_characters
}
temp <- substring(text, i, end)
if (nchar(temp) == 4) {
quad_gram_list <- append(quad_gram_list, temp)
}
}
Any improvement suggestions would be very much appreciated.