R/ngram.R

Defines functions ngrams

Documented in ngrams

ngrams <-
function(x, n)
{
    N <- length(x)
    n <- n[(n >= 1L) & (n <= N)]
    lapply(unlist(lapply(n,
                         function(k) {
                             pos <- seq_len(k)
                             lapply(seq.int(0, N - k),
                                    `+`, pos)
                         }),
                  recursive = FALSE),
           function(e) x[e])
}

Try the NLP package in your browser

Any scripts or data that you put into this service are public.

NLP documentation built on Oct. 18, 2018, 5:04 p.m.