Skip to content

Instantly share code, notes, and snippets.

@syu-id
Created December 5, 2015 06:33
Show Gist options
  • Save syu-id/0e1c4341800c008b4649 to your computer and use it in GitHub Desktop.
Save syu-id/0e1c4341800c008b4649 to your computer and use it in GitHub Desktop.
学習者コーパス論 2015.12.04 AWL と ASL の計算
library(dplyr)
tokens <- read.csv('data/tokens.csv', as.is = TRUE)
result <- tokens %>%
group_by(native, id) %>%
summarise(
n_token = n(),
n_type = n_distinct(token),
n_sent = n_distinct(sen_no),
ttr = n_type / n_token,
gi = n_type / sqrt(n_token),
awl = mean(nchar(token)),
asl = n_token / n_sent
)
write.csv(result, file = 'out/2015.12.04-awl_asl.csv', row.names = FALSE)
result %>%
mutate_each(
funs(round(., 2)),
ttr:asl
) %>%
as.data.frame() %>%
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment