You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Warnings are issued for checks that failed, but are optional. Within each row, output describes the result of the check. For example: Column names in Riverbank_Sediment_ADC.csv are well formed. No non-printable characters detected.
At the Arctic Data Center we can use these checks to gain insights about our data holdings. TODO: maybe insert figures here?
88
88
89
-
### Data Quality and You
89
+
### Checking Data Quality in R
90
90
91
91
Poll:
92
92
93
93
- What are the most common quality issues you see? (free text)
94
94
- What kind of data quality checks do you use on your own data? (free text)
95
95
- Do you have ideas for checks you think we should add to the ADC quality suite?
96
96
97
+
Although the Arctic Data Center has implemented data quality checks that are automated, the vast majority of data quality work still falls on researchers doing analysis. In this section we will discuss a few tools that researchers can use in R to do general data quality work.
98
+
99
+
#### Resolving mysteries with `file`
100
+
101
+
When a researcher receives a new file to incorporate into an analysis, the first step is to examine the file. One tool already used in the Arctic Data Center data quality suite is the `file` utility in linux/unix systems. This is a command run using the terminal that performs tests on the **content** of a file to determine its type. This is useful for files where the type is unknown, or for files that cannot be read into R for unknown reasons.
102
+
103
+
In the terminal, run the following:
104
+
105
+
```
106
+
file data/BGchem2008data.csv
107
+
```
108
+
109
+
You should see an output like: `data/BGchem2008data.csv: CSV text`. Which makes sense!
110
+
111
+
The file command is very helpful at catching things like this, where we have an excel file masquerading as a csv file. You might wind up using this if you try to read in the example file below using `read.csv`, and get output that looks completely garbled.
112
+
113
+
```
114
+
file example-data/my-data.csv
115
+
example-data/my-data.csv: Microsoft Excel 2007+
116
+
```
117
+
118
+
Another great use of the file command is for mystery extensions:
119
+
120
+
```
121
+
file example-data/JUSTIN_400__001.DZG
122
+
example-data/JUSTIN_400__001.DZG: ASCII text, with CRLF, LF line terminators
123
+
```
124
+
125
+
#### Quick Summaries with `skimr`.
126
+
127
+
First, we need to install the `skimr` package.
128
+
129
+
```{r, eval = FALSE}
130
+
install.packages("skimr")
131
+
```
132
+
133
+
And load it into our environment, along with `readr`
134
+
135
+
```{r, warning = FALSE, message = FALSE}
136
+
library(skimr)
137
+
library(readr)
138
+
library(dplyr)
139
+
library(lubridate)
140
+
```
141
+
142
+
Now we'll read in a familar file, the `BGChem2008data.csv` from [Craig Tweedie. (2009). North Pole Environmental Observatory Bottle Chemistry. Arctic Data Center. doi:10.18739/A25T3FZ8X.](https://doi.org/doi:10.18739/A25T3FZ8X)
143
+
144
+
```{r}
145
+
bg_chem <- read_csv("data/BGchem2008data.csv")
146
+
```
147
+
Notice that the `read_csv` call already gives us some information about the dataset here. It tells us what the columns are, and what the column types are. `skimr` can give us even more information that will be helpful.
148
+
149
+
```{r}
150
+
skim(bg_chem)
151
+
```
152
+
153
+
`skim` gives us information about the data frame including basic statistics on the numeric values, missing values, and number of unique values in the character variables.
154
+
155
+
Helpfully, `skim` can also handle grouped output, if we wanted to look more closely at summaries of oxygen concentaration by `station`, for example, we can run:
156
+
157
+
```{r}
158
+
bg_chem %>%
159
+
select(Station, O2) %>%
160
+
group_by(Station) %>%
161
+
skim()
162
+
```
163
+
164
+
Skim is a great way to get a big picture overview of your data to spot major issues. Does anything stand out here?
165
+
166
+
-99 (or some repetition of those digits) is a very common missing value code that isn't automatically recognized by R. Let's go back to the `read_csv` call to add it in as an argument.
167
+
168
+
```{r}
169
+
bg_chem <- read_csv("data/BGchem2008data.csv", na = "-99")
170
+
```
171
+
172
+
Another similar package is called `visdat`. It lets you visualize a data frame with its column types, variable names, and missing values.
0 commit comments