Joseph Kliegman / May 20 2019

How to tidy data with R

weather_data2.csv
library(tidyverse)
weather <- read_csv2(
weather_data2.csv
) str(weather)

The weather dataset suffers from one of the five most common symptoms of messy data: column names are values. In particular, the column names X1 and X2 represent days of the month, which should really be values of a new variable called day.

weather2 <- gather(weather, day, value, X1:X2, na.rm = TRUE)
# First remove column of row names
weather2 <- weather2[, -1]