##1) library(tidyverse) pew <- tbl_df(read.csv(‘pew.csv’, stringsAsFactors = FALSE, check.names = FALSE)) pew2 <- pew %>% gather(key = religion, value = frequency, ‘<$10k’:‘$10k-20’:‘$20k-30’:‘$30k-40’:$40k-50’:‘50k-75’) pew2
library(tidyverse) table1 ## # A tibble: 6 x 4 ## country year cases
population ##
table2 ## # A tibble: 12 x 4 ## country year type count ##
table3 ## # A tibble: 6 x 3 ## country year rate
## *
## 1 Afghanistan 1999 745/19987071
## 2 Afghanistan 2000 2666/20595360
## 3 Brazil 1999 37737/172006362
## 4 Brazil 2000 80488/174504898
## 5 China 1999 212258/1272915272 ## 6 China 2000 213766/1280428583
table4a ## # A tibble: 3 x 3 ## country 1999
2000 ## *
table4b ## # A tibble: 3 x 3 ## country 1999
2000 ## *
table5 ## # A tibble: 6 x 4 ## country century year rate
## *
## 1 Afghanistan 19 99 745/19987071
## 2 Afghanistan 20 00 2666/20595360
## 3 Brazil 19 99 37737/172006362
## 4 Brazil 20 00 80488/174504898
## 5 China 19 99 212258/1272915272 ## 6 China 20 00
213766/1280428583
##2) tidy4b <- table4b %>% gather(key = year, value =
population, 1999:2000) tidy4b
tidy4a <- table4a %>% gather(key = “year”, value = “cases”,
1999:2000) tidy4a
##3) full_join(tidy4a, tidy4b, by = “country”)
##4) stocks <- tibble( year = c(2015, 2015, 2016, 2016), half = c( 1, 2, 1, 2), return = c(1.88, 0.59, 0.92, 0.17) ) stocks
spread(stocks, key = year, value = half)
##5) pregnant <- tribble( ~pregnant, ~male, ~female, “yes”, NA, 10, “no”, 20, 12 ) pregnant
pregnant2 <- pregnant %>% gather(pregnant, key = pregnant, value = pregnant) pregnant2
##6) tidy5 <- table5 %>% unite(year, century, year, sep = ““)
tidy5 %>% separate(rate, into = c(“cases”, “population”), sep = “/”)