Hi,
the following code should produce a dfm with characters as features, but does contain words as tokens:
library(quanteda)
txt <- c(d1 = "Chinese Beijing Chinese",
d2 = "Chinese Chinese Shanghai",
d3 = "Chinese Macao",
d4 = "Tokyo Japan Chinese",
d5 = "Chinese Chinese Chinese Tokyo Japan")
q_corp <- corpus(txt)
q_dfm <- dfm(q_corp, what = 'character')
head(q_dfm)
Document-feature matrix of: 5 documents, 6 features (60% sparse).
5 x 6 sparse Matrix of class "dfm"
features
docs chinese beijing shanghai macao tokyo japan
d1 2 1 0 0 0 0
d2 2 0 1 0 0 0
d3 1 0 0 1 0 0
d4 1 0 0 0 1 1
d5 3 0 0 0 1 1
It works when using tokens() in a prestep:
q_tokens <- tokens(q_corp, what = 'character')
q_dfm <- dfm(q_tokens)
head(q_dfm)
Document-feature matrix of: 5 documents, 6 features (0% sparse).
5 x 6 sparse Matrix of class "dfm"
features
docs c h i n e s
d1 2 2 4 3 5 2
d2 2 4 3 3 4 3
d3 2 1 1 1 2 1
d4 1 1 1 2 2 1
d5 3 3 3 4 6 3
Hi,
the following code should produce a dfm with characters as features, but does contain words as tokens:
It works when using
tokens()in a prestep: