0

tm パッケージを使用して用語ドキュメント マトリックスを作成し、以下のコードを使用してキーワードの相関関係を特定しました。

tdm2 - 私の用語 doc マトリックスです

text    Var1    Var2    Var3    Var4
Music   0       0       0       0
ableton 0       0       1       0
bass    1       0       0       0
blues   1       0       0       0
drums   0       0       0       0
fun     0       0       0       0
history 0       0       0       0

a - 相関する単語を見つける必要がある単語のリストです

以下のコードは動作します

aa <- as.data.frame(findAssocs(tdm2,a[1], 0.15),stringsAsFactors = FALSE)
  aa$text <- rownames(aa)
  aa$word <- a[1]
  names(aa) <- c("Corr","text","word")

を使用して同じことを自動化しようとすると

for (i in 1:n){

    a1 <- findAssocs(tdm2,a[i], 0.15)
    a2 <- as.data.frame(a1,stringsAsFactors = FALSE)
    a2$text <- rownames(a2)
    a2$word <- a[i]
    names(a2) <- c("Corr","text","word")
    aa <- rbind(aa,a1)
  }

以下のエラーが表示されます

Error in `$<-.data.frame`(`*tmp*`, "word", value = "100") : 
  replacement has 1 rows, data has 0

誰でも理由を教えてもらえますか?

4

0 に答える 0