oildata <- read.csv(url("https://raw.githubusercontent.com/chrisgmartin/DATA607/master/untidy_oil_consumption.csv"), sep = ",", stringsAsFactors=FALSE)
oildata
## Month Category Caltex Gulf Mobil
## 1 Open Engine Oil 140 : 000 199 : 000 141 : 000
## 2 GearBox Oil 198 : 000 132 : 000 121 : 000
## 3 Jan Engine Oil 170 : 103 194 : 132 109 : 127
## 4 GearBox Oil 132 : 106 125 : 105 191 : 100
## 5 Feb Engine Oil 112 : 133 138 : 113 171 : 101
## 6 GearBox Oil 193 : 148 199 : 119 134 : 127
## 7 Mar Engine Oil 184 : 100 141 : 141 114 : 108
## 8 GearBox Oil 138 : 121 172 : 133 193 : 115
## 9 Apr Engine Oil 149 : 150 117 : 118 117 : 118
## 10 GearBox Oil 185 : 125 191 : 133 119 : 121
## 11 May Engine Oil 170 : 139 104 : 119 200 : 117
## 12 GearBox Oil 168 : 117 138 : 102 121 : 146
## 13 Jun Engine Oil 159 : 129 170 : 138 169 : 105
## 14 GearBox Oil 107 : 129 195 : 141 141 : 112
oildata %>%
pivot_longer(cols=c(Caltex, Gulf, Mobil),
names_to = "Type",
values_to = "Range")
## # A tibble: 42 x 4
## Month Category Type Range
## <chr> <chr> <chr> <chr>
## 1 "Open" Engine Oil Caltex 140 : 000
## 2 "Open" Engine Oil Gulf 199 : 000
## 3 "Open" Engine Oil Mobil 141 : 000
## 4 "" GearBox Oil Caltex 198 : 000
## 5 "" GearBox Oil Gulf 132 : 000
## 6 "" GearBox Oil Mobil 121 : 000
## 7 "Jan" Engine Oil Caltex 170 : 103
## 8 "Jan" Engine Oil Gulf 194 : 132
## 9 "Jan" Engine Oil Mobil 109 : 127
## 10 "" GearBox Oil Caltex 132 : 106
## # … with 32 more rows
setwd("~/Desktop/DATA110")
diseases <- read.csv("us_contagious_diseases.csv")
unique(diseases$year)
## [1] 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980
## [16] 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995
## [31] 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010
## [46] 2011 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941
## [61] 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956
## [76] 1957 1958 1959 1960 1961 1962 1963 1964 1965
diseases_wide <- diseases %>%
pivot_wider(
names_from = year,
values_from = c(weeks_reporting, count, population)
) %>%
select(
disease, state, ends_with("68"), ends_with("73"),
ends_with("78"), ends_with("83"), ends_with("88"),
ends_with("93"), ends_with("98"), ends_with("03"),
ends_with("08")
)
diseases_wide
## # A tibble: 357 x 29
## disease state weeks_reporting… count_1968 population_1968 weeks_reporting…
## <chr> <chr> <int> <int> <int> <int>
## 1 Hepati… Alab… 52 314 3386068 45
## 2 Hepati… Alas… 31 84 284068 32
## 3 Hepati… Ariz… 50 425 1661517 22
## 4 Hepati… Arka… 38 166 1867112 44
## 5 Hepati… Cali… 52 10821 19219725 49
## 6 Hepati… Colo… 43 715 2100603 48
## 7 Hepati… Conn… 52 502 2964628 51
## 8 Hepati… Dela… 43 146 533755 39
## 9 Hepati… Dist… 36 67 765853 32
## 10 Hepati… Flor… 51 1116 6411565 49
## # … with 347 more rows, and 23 more variables: count_1973 <int>,
## # population_1973 <int>, weeks_reporting_1978 <int>, count_1978 <int>,
## # population_1978 <int>, weeks_reporting_1983 <int>, count_1983 <int>,
## # population_1983 <int>, weeks_reporting_1988 <int>, count_1988 <int>,
## # population_1988 <int>, weeks_reporting_1993 <int>, count_1993 <int>,
## # population_1993 <int>, weeks_reporting_1998 <int>, count_1998 <int>,
## # population_1998 <int>, weeks_reporting_2003 <int>, count_2003 <int>,
## # population_2003 <int>, weeks_reporting_2008 <int>, count_2008 <int>,
## # population_2008 <int>