I have a dataset that is a bit too wide for the EDA plots I would like to make.
The data can be found here: https://www.massey.ac.nz/~kgovinda/data/Bill_Colour.RData
But looks something like this:
|CommonName||r_ChromaticityFemaleLowerMandible||r_ChromaticityFemaleUpperMandible||r_ChromaticityMaleLowerMandible||r_ChromaticityMaleUpperMandible||many more column ...|
I am pivoting it longer so that three columns are tacked on to the end while removing the four
r_* Chromaticity columns
My current method of doing this requires two pivot_longer for upper and lower and then they are bonded together.
library(tidyverse) load(url("https://www.massey.ac.nz/~kgovinda/data/Bill_Colour.RData")) lowerMandible <- Bill_Colour %>% pivot_longer(c(r_ChromaticityFemaleLowerMandible, r_ChromaticityMaleLowerMandible), values_to = "LowerMandible") %>% select(-name) upperMandible <- Bill_Colour %>% select(r_ChromaticityFemaleUpperMandible, r_ChromaticityMaleUpperMandible) %>% pivot_longer(c(r_ChromaticityFemaleUpperMandible, r_ChromaticityMaleUpperMandible), values_to = "UpperMandible") %>% mutate(Sex = as.factor(str_sub(name,15,-14))) %>% select(-name) upperAndLowerBySex <- cbind.data.frame(lowerMandible, upperMandible) %>% select(-r_ChromaticityFemaleUpperMandible, -r_ChromaticityMaleUpperMandible)
I feel like there should be a way to do this with one set of
pivot_longer rather than making multiple datasets.