-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtidyr.R
More file actions
34 lines (26 loc) · 737 Bytes
/
tidyr.R
File metadata and controls
34 lines (26 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
############################
### tidyr ###
############################
## Update packages
old.packages()
update.packages(ask = FALSE)
## Install packages
install.packages("devtools")
library(devtools)
install_github("rstudio/EDAWR")
library(EDAWR)
# gather()
new_df<- tidyr::gather(cases, "Year", "n", 2:4)
new_df
# spread()
head(pollution)
new_df<- tidyr::spread(pollution, size, amount)
new_df
# "gather()" -- reverse of "spread()"
new_df<- tidyr::gather(new_df, "size", "amount", 2:3)
## "separate()" vs "unite()"
head(storms)
storms2<- tidyr::separate(storms, date, c("year", "month", "day"), sep="-")
storms2
storms2<-tidyr::unite(storms2, "date", year, month, day, sep="-")
storms2