library(ngram)
str = "A B A C A B B"
ngram(str, n=2)
str = "A,B,A,C A B B"
### Split at a space
print(ngram(str), output="full")
### Split at a comma
print(ngram(str, sep=","), output="full")
### Split at a space or a comma
print(ngram(str, sep=", "), output="full")
Run the code above in your browser using DataLab