Skip to content

Instantly share code, notes, and snippets.

@hepplerj
Created December 11, 2019 18:11
Show Gist options
  • Select an option

  • Save hepplerj/1c1000e25b297a429b8e612aeda908fe to your computer and use it in GitHub Desktop.

Select an option

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