Hadley Wickham's journal of statistical software paper:
https://vita.had.co.nz/papers/tidy-data.pdf
Tools that work together to transform, analyze and visualize tidy data
https://www.tidyverse.org
Reshaping data using tidyr package
The tidyr package, provides 4 functions to help you change the layout of your data set:
separate()
: separate one column into multiple
unite()
: unite multiple columns into one
gather()
: gather (collapse) columns into rows
spread()
: spread rows into columns
data <- read.csv("data//players.csv")
Warning message in file(file, "rt"): "cannot open file 'data//players.csv': No such file or directory"
Error in file(file, "rt"): cannot open the connection Traceback: 1. read.csv("data//players.csv") 2. read.table(file = file, header = header, sep = sep, quote = quote, . dec = dec, fill = fill, comment.char = comment.char, ...) 3. file(file, "rt")
library(tidyr)
head(data)
separate(data, Home_Town, c("city", "state"), sep=",")
unite(data, "Name", c(First_Name, Last_Name), sep=" ")
data1 <- read.csv("data//homeruns.csv")
head(data1)
data3 <- gather(data1, year, home_runs, x2015:x2013)
data3
spread(data3, year, home_runs)