Julie Joe
Measurement 1 Measurement 2 Measurement 1 Measurement 2
Part Number 1 33 32 33 31
Part Number 2 34 31 33 32
Part Number 3 33 31 30 31
How do I get this messy Excel table into a tidy format for use in R? I can utilize readr functions like spread()
and gather()
but this seems to need a higher level of sophistication. Here's my best reconstruction of the Excel data frame for you to mess with. Please modify it at will to better make any point.
library(tidyverse)
messy <- data.frame(
" " = c(" ", "Part Number 1", "Part Number 2", "Part Number 3"),
Julie = c("Measurement 1", 33, 34, 33),
Julie = c("Measurement 2", 32, 31, 31),
Joe = c("Measurement 1", 33, 33, 30),
Joe = c("Measurement 2", 31, 32, 31))
I'm open to trying the dev versions of readr or tidyr. The new pack()
, unpack()
etc. functions seem to be useful. Also, it appears other SO attempts/solutions aren't quite what I'm looking for 1, 2, 3, 4.