3.1 Exploring data

Next, we’ll look at the help menu for the pirates dataset using the question mark ?pirates. When you run this, you should see a small help window open up in RStudio that gives you some information about the dataset.

?pirates

First, let’s take a look at the first few rows of the dataset using the head() function. This will show you the first few rows of the data.

# Look at the first few rows of the data
head(pirates)
##   id    sex age height weight headband college tattoos tchests parrots favorite.pirate sword.type eyepatch sword.time beard.length
## 1  1   male  28 173.11   70.5      yes   JSSFP       9       0       0    Jack Sparrow    cutlass        1       0.58           16
## 2  2   male  31 209.25  105.6      yes   JSSFP       9      11       0    Jack Sparrow    cutlass        0       1.11           21
## 3  3   male  26 169.95   77.1      yes    CCCC      10      10       1    Jack Sparrow    cutlass        1       1.44           19
## 4  4 female  31 144.29   58.5       no   JSSFP       2       0       2    Jack Sparrow   scimitar        1      36.11            2
## 5  5 female  41 157.85   58.4      yes   JSSFP       9       6       4            Hook    cutlass        1       0.11            0
## 6  6   male  26 190.20   85.4      yes    CCCC       7      19       0    Jack Sparrow    cutlass        1       0.59           17
##             fav.pixar grogg
## 1      Monsters, Inc.    11
## 2              WALL-E     9
## 3          Inside Out     7
## 4          Inside Out     9
## 5          Inside Out    14
## 6 Monsters University     7

You can look at the names of the columns in the dataset with the names() function

# What are the names of the columns?
names(pirates)
##  [1] "id"              "sex"             "age"             "height"          "weight"          "headband"        "college"        
##  [8] "tattoos"         "tchests"         "parrots"         "favorite.pirate" "sword.type"      "eyepatch"        "sword.time"     
## [15] "beard.length"    "fav.pixar"       "grogg"

Finally, you can also view the entire dataset in a separate window using the View() function:

# View the entire dataset in a new window
View(pirates)