@@ -113,49 +113,28 @@ See https://cran.r-project.org/web/packages/OCSdata/vignettes/instructions.html
113
113
114
114
See https://www.opencasestudies.org/ocs-bp-opioid-rural-urban/ about this data.
115
115
116
- ## EXTRA PRACTICE - Get the data into your project directory
117
-
118
- ``` {r, results='hide', eval = FALSE}
119
- OCSdata::simpler_import_data("ocs-bp-opioid-rural-urban",
120
- outpath = tempdir())
121
- ```
122
-
123
- Where is the data?
124
-
125
- Simulates creating subdirectories to organize your data.
126
-
127
- ``` {r, fig.alt="dplyr", out.width = "55%", echo = FALSE, fig.align='center'}
128
- knitr::include_graphics("images/path.gif")
129
- ```
130
116
131
117
## Import the data
132
- ` here ` function of the ` here ` package helps R start looking where your .Rproj file is.
133
118
134
- ``` {r, echo = FALSE, message=FALSE, comment= FALSE, results='hide'}
135
- install.packages("here", repos='http://cran.us.r-project.org')
136
- ```
137
-
138
- ``` {r, eval = FALSE}
139
- #install.packages(here)
140
- library(here)
141
- annualDosage <- read_csv(file =
142
- here("OCS_data/data/simpler_import/county_annual.csv"))
143
-
144
- ```
145
-
146
-
147
- ## Or do this!
119
+ Now we will get the data from the ` OCSdata ` package using the ` load_imported_data() ` function.
148
120
149
121
``` {r}
150
- OCSdata:: load_imported_data("ocs-bp-opioid-rural-urban")
122
+ load_imported_data("ocs-bp-opioid-rural-urban")
151
123
```
152
124
153
125
You will see a few new objects in your environment called:
154
126
155
- - ` annualDosage ` (number of shipments (count) of either oxycodone or hydrocodone pills (DOSAGE_UNIT))
127
+ - ` annualDosage ` (number of shipments (count) of either oxycodone or hydrocodone pills (DOSAGE_UNIT)) - * we will work with this one for now *
156
128
- ` county_pop ` (population per county)
157
129
- ` land ` (land area per county)
158
130
131
+ ## Import the data - method 2
132
+
133
+ ``` {r}
134
+ annualDosage <- read_csv("https://jhudatascience.org/intro_to_r/data/annualDosage.csv")
135
+
136
+ ```
137
+
159
138
## Checking the data ` dim() `
160
139
161
140
The ` dim() ` , ` nrow() ` , and ` ncol() ` functions are good options to check the dimensions of your data before moving forward.
@@ -190,11 +169,11 @@ slice_sample(annualDosage, n = 2)
190
169
191
170
## Data frames
192
171
193
- An older version of data in tables is called a data frame. The iris dataset is an example of this.
172
+ An older version of data in tables is called a data frame. The mtcars dataset is an example of this.
194
173
195
174
``` {r}
196
- class(iris )
197
- head(iris )
175
+ class(mtcars )
176
+ head(mtcars )
198
177
```
199
178
## tibble
200
179
@@ -215,8 +194,8 @@ annualDosage
215
194
If we wanted to create a ` tibble ` ("fancy" data frame), we can using the ` tibble() ` function on a data frame.
216
195
217
196
``` {r}
218
- tbl_iris <- tibble(iris )
219
- tbl_iris
197
+ tbl_mtcars <- tibble(mtcars )
198
+ tbl_mtcars
220
199
```
221
200
222
201
Note don't necessarily need to use ` head() ` with tibbles, as they conveniently print a portion of the data.
0 commit comments