R_頻度区間調整 のバックアップ(No.1) - アールメカブ

アールメカブ


R_頻度区間調整 のバックアップ(No.1)


Rの備忘録

例えば

writers <- read.csv(file = "corpusWork2007/test.csv")
# 上の中身は
  Writer,Text,Length
  akutagawa,rashom,151
# の2行だけだとして
 text0 <- as.character(writers$Text[1])
 buntyo <- read.csv(file = 
    paste("CAB/",text0,".csv",sep = ""), header = F)
 # 文を先頭から句数で数えたファイルを読み込む
 # そのファイルから句数の頻度表を作成する
bun.orig.df <- data.frame(table(buntyo))

###

### 高頻度では、データ区間が飛び飛びになっているので、これを補正する

# y <- min(buntyo):max(buntyo) y <- 0:max(buntyo) bun.df <- data.frame(cate = y, freq = c(rep(0, length(y)))) z <- 0 bun.df[1,] = c(0,0) for(i in 1:nrow(bun.df)){

 if(bun.orig.df[i - z,]$buntyo == bun.df[i,]$cate){
   bun.df[i,]$freq <- bun.orig.df[bun.orig.df$buntyo == bun.df[i,]$cate, ]$Freq}
 else{
   z <- z + 1;
   next;
 }

}

次のような結果が得られる.

ModifiedOriginal
10
211
344
433
588
666
71515
81212
91919
101717
1177
121212
1355
1499
1588
1688
1722
1844
1944
200
2111
2211
230
240
2522
2611
270
2822