50,176 ツイートのデータセットがあります (tweets_data: 1 変数の 50176 個の観測値)。今、私は自作のレキシコン (formal_lexicon) を作成しました。これは約 100 万語で構成され、すべて形式言語スタイルです。ここで、ツイートごとに、そのレキシコンに含まれる単語の数 (存在する場合) をカウントする小さなコードを作成したいと考えています。
ツイート_データ:
Content
1 "Blablabla"
2 "Hi my name is"
3 "Yes I need"
.
.
.
50176 "TEXT50176"
フォーマル辞書:
X
1 "admittedly"
2 "Consequently"
3 "Furthermore"
.
.
.
1000000 "meanwhile"
したがって、出力は次のようになります。
Content Lexicon
1 "TEXT1" 1
2 "TEXT2" 3
3 "TEXT3" 0
.
.
.
50176 "TEXT50176" 2
次のような単純な for ループにする必要があります。
for(sentence in tweets_data$Content){
for(word in sentence){
if(word %in% formal_lexicon){
...
}
}
}
「単語」は機能しないと思います。単語がレキシコンにある場合、特定の列でカウントする方法がわかりません。誰でも助けることができますか?
structure(list(X = c("admittedly", "consequently", "conversely", "considerably", "essentially", "furthermore")), row.names = c(NA, 6L), class = "data.frame")
c("@barackobama Thank you for your incredible grace in leadership and for being an exceptional… ", "happy 96th gma #fourmoreyears! \U0001f388 @ LACMA Los Angeles County Museum of Art", "2017 resolution: to embody authenticity!", "Happy Holidays! Sending love and light to every corner of the earth \U0001f381", "Damn, it's hard to wrap presents when you're drunk. cc @santa", "When my whole fam tryna have a peaceful holiday " )