Skip to content

Instantly share code, notes, and snippets.

@tkawachi
Created December 19, 2011 05:42
Show Gist options
  • Save tkawachi/1495580 to your computer and use it in GitHub Desktop.
Save tkawachi/1495580 to your computer and use it in GitHub Desktop.
printf <- function(fmt, ...) {
cat(sprintf(fmt, ...))
}
VNTTRK <- function(csv_file) {
abet <- read.csv(csv_file, header=T, row.names=1)
abe <- data.frame(rank=1:nrow(abet), freq=abet)
par(mfrow=c(1,2))
plot(abe, type="l")
plot(log(abe), type="l")
abeD <- data.frame(table(abet)) # クロス表作成
V = sum(abeD[,2]) # 異なり語数 V
N = sum(as.integer(levels(abeD[,1])) * abeD[,2]) # 延べ語数 N
TTR = V / N # TTR
K = 10^4 * ((sum(as.integer(levels(abeD[,1]))^2 * abeD[,2]) - N) / N^2) # K特性値
printf("%s V=%f, N=%f, TTR=%f, K=%f\n", csv_file, V, N, TTR, K)
}
VNTTRK("~/Desktop/ABE.csv")
readLines(n=1)
VNTTRK("~/Desktop/FUKUDA.csv")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment