Skip to content

Commit e0499e5

Browse files
including more import data practice but not through ocs_data
1 parent d376163 commit e0499e5

File tree

2 files changed

+30
-37
lines changed

2 files changed

+30
-37
lines changed

modules/Subsetting_Data_in_R/Subsetting_Data_in_R.Rmd

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -113,49 +113,28 @@ See https://cran.r-project.org/web/packages/OCSdata/vignettes/instructions.html
113113

114114
See https://www.opencasestudies.org/ocs-bp-opioid-rural-urban/ about this data.
115115

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-
```
130116

131117
## Import the data
132-
`here` function of the `here` package helps R start looking where your .Rproj file is.
133118

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.
148120

149121
```{r}
150-
OCSdata::load_imported_data("ocs-bp-opioid-rural-urban")
122+
load_imported_data("ocs-bp-opioid-rural-urban")
151123
```
152124

153125
You will see a few new objects in your environment called:
154126

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*
156128
- `county_pop` (population per county)
157129
- `land` (land area per county)
158130

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+
159138
## Checking the data `dim()`
160139

161140
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)
190169

191170
## Data frames
192171

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.
194173

195174
```{r}
196-
class(iris)
197-
head(iris)
175+
class(mtcars)
176+
head(mtcars)
198177
```
199178
## tibble
200179

@@ -215,8 +194,8 @@ annualDosage
215194
If we wanted to create a `tibble` ("fancy" data frame), we can using the `tibble()` function on a data frame.
216195

217196
```{r}
218-
tbl_iris <- tibble(iris)
219-
tbl_iris
197+
tbl_mtcars <- tibble(mtcars)
198+
tbl_mtcars
220199
```
221200

222201
Note don't necessarily need to use `head()` with tibbles, as they conveniently print a portion of the data.

modules/Subsetting_Data_in_R/lab/Subsetting_Data_in_R_Lab_Key.Rmd

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ In this lab you can use the interactive console to explore but please record you
1313

1414
# Part 1
1515

16+
Now we will work with the `county_pop` data from the same case study.
17+
18+
19+
1620
First let's get the OCSdata package if we haven't already. We added an argument here so you don't have to select a mirror.
1721

1822
```{r}
@@ -26,8 +30,18 @@ library(tidyverse)
2630
library(OCSdata)
2731
```
2832

29-
Now let's load the opioid related datasets by running this chunk.
3033

34+
There are two ways to get the data- either one is fine. We give you two options in case you have challenges:
35+
1) importing the csv
36+
2) using the OCSdata package
37+
38+
```{r}
39+
40+
county_pop <- read_csv("https://jhudatascience.org/intro_to_r/data/county_pop.csv")
41+
42+
```
43+
44+
Or we can load the data from this package:
3145
```{r}
3246
OCSdata::load_imported_data("ocs-bp-opioid-rural-urban")
3347
```

0 commit comments

Comments
 (0)