Supporting Statistical Analysis for Research

## 2.2 Reading csv files and other delimited data

1. Import the “mtcars.csv” data set

``library(tidyverse)``
``````mtcars_path <- file.path("..", "datasets", "mtcars.csv")
mtcars <- read_csv(mtcars_path, col_types = cols())``````
``Warning: Missing column names filled in: 'X1' [1]``
2. What is the type of each variable of the mtcars data set?

``glimpse(mtcars)``
``````Observations: 32
Variables: 12
\$ X1   <chr> "Mazda RX4", "Mazda RX4 Wag", "Datsun 710", "Hornet 4 Dri...
\$ mpg  <dbl> 21.0, 21.0, 22.8, 21.4, 18.7, 18.1, 14.3, 24.4, 22.8, 19....
\$ cyl  <dbl> 6, 6, 4, 6, 8, 6, 8, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 4, 4, ...
\$ disp <dbl> 160.0, 160.0, 108.0, 258.0, 360.0, 225.0, 360.0, 146.7, 1...
\$ hp   <dbl> 110, 110, 93, 110, 175, 105, 245, 62, 95, 123, 123, 180, ...
\$ drat <dbl> 3.90, 3.90, 3.85, 3.08, 3.15, 2.76, 3.21, 3.69, 3.92, 3.9...
\$ wt   <dbl> 2.620, 2.875, 2.320, 3.215, 3.440, 3.460, 3.570, 3.190, 3...
\$ qsec <dbl> 16.46, 17.02, 18.61, 19.44, 17.02, 20.22, 15.84, 20.00, 2...
\$ vs   <dbl> 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, ...
\$ am   <dbl> 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, ...
\$ gear <dbl> 4, 4, 4, 3, 3, 3, 3, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 4, 4, ...
\$ carb <dbl> 4, 4, 1, 1, 2, 1, 4, 2, 2, 4, 4, 3, 3, 3, 4, 4, 4, 1, 2, ...``````
3. Import the “cane.csv” data set.

``````cane_path <- file.path("..", "datasets", "cane.csv")
cane <- read_csv(cane_path, col_types = cols())``````
``Warning: Missing column names filled in: 'X1' [1]``
4. What is the type of each variable of the cane data set?

``glimpse(cane)``
``````Observations: 180
Variables: 6
\$ X1    <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1...
\$ n     <dbl> 87, 119, 94, 95, 134, 92, 118, 70, 128, 85, 77, 29, 109,...
\$ r     <dbl> 76, 8, 74, 11, 0, 0, 11, 32, 33, 14, 3, 3, 28, 63, 3, 16...
\$ x     <dbl> 19, 14, 9, 12, 12, 3, 17, 3, 3, 21, 8, 3, 7, 10, 7, 14, ...
\$ var   <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1...
\$ block <chr> "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "...``````