Skip to content

Instantly share code, notes, and snippets.

@hepplerj
Created December 11, 2019 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hepplerj/1c1000e25b297a429b8e612aeda908fe to your computer and use it in GitHub Desktop.
Save hepplerj/1c1000e25b297a429b8e612aeda908fe to your computer and use it in GitHub Desktop.
Turn a frequency table into a list of individual items
library(tidyverse)
library(readxl)
data <- readxl::read_xlsx("data.xlsx")
reshaped <- data %>% gather(word, freq, 2:21)
reshaped <- reshaped %>% drop_na()
cleaned <- reshaped %>%
uncount(freq)
names(cleaned) <- c("noun","color")
write_csv(cleaned, "tidy.csv")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment