Skip to content

Instantly share code, notes, and snippets.

@syu-id
Created December 2, 2015 15:34
Show Gist options
  • Save syu-id/c26c3a970655a805b82f to your computer and use it in GitHub Desktop.
Save syu-id/c26c3a970655a805b82f to your computer and use it in GitHub Desktop.
library(dplyr)
tokens <- read.csv('data/tokens.csv')
result <- tokens %>%
group_by(native, id) %>%
summarise(
n_token = length(token),
n_type = length(unique(token)),
ttr = n_type / n_token,
gi = n_type / sqrt(n_token)
)
# save the result to csv
write.csv(result, file = 'out/2015.11.27-ttr_gi.csv', row.names = FALSE)
# print out the result
result %>%
mutate_each(
funs(round(., 3)),
ttr:gi
) %>%
as.data.frame() %>%
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment