Skip to content

Instantly share code, notes, and snippets.

@fauxneticien
Created November 30, 2017 23:36
Show Gist options
  • Save fauxneticien/9d59ce04bd10d374c7f71194b5a71d6e to your computer and use it in GitHub Desktop.
Save fauxneticien/9d59ce04bd10d374c7f71194b5a71d6e to your computer and use it in GitHub Desktop.
Gather names from wide table to long table (and drop column name)
# Use install.packages() on dplyr and tidyr
library(dplyr)
library(tidyr)
# mock up data frame (or use read_xlsx function from readxl package to read in an excel sheet)
wrl_wide <-
data.frame(
Warlpiri = c("wumparlpa", "wartarurru"),
`scientificName 1` = c("ecucalyptus leucophloia", "acacia validinervia"),
`scientificName 2` = c("eucalyptus pruinosa", "acacia jennerae")
)
wrl_wide %>%
gather(key = column, value = scientific_name, -Warlpiri) %>% # make old column names in wide form into
# a column called 'column' and place its value into sci_name column
# but don't touch Warlpiri column in the gather routine
select(-column) # drop column 'column'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment