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
## 2     2 male  31    209    106      yes   JSSFP       9      11       0
## 793 793 male  25    209    104      yes    CCCC       8      27       9
## 430 430 male  26    201     99      yes    CCCC       4       7       1
## 292 292 male  29    201    102      yes    CCCC       9       2       3
## 895 895 male  27    201    103      yes    CCCC      12       1       1
## 409 409 male  28    201     97      yes    CCCC       7      10       0
##     favorite.pirate sword.type eyepatch sword.time beard.length
## 2      Jack Sparrow    cutlass        0        1.1           21
## 793        Anicetus    cutlass        1        1.1           16
## 430    Jack Sparrow    cutlass        1        0.9           14
## 292    Jack Sparrow      sabre        1        9.9           14
## 895            Hook    cutlass        1        2.3           25
## 409    Jack Sparrow    cutlass        1        1.2           15
##               fav.pixar grogg
## 2                WALL-E     9
## 793 Monsters University     8
## 430              WALL-E     9
## 292              WALL-E     6
## 895               Brave    14
## 409          Inside Out     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"            
##  [4] "height"          "weight"          "headband"       
##  [7] "college"         "tattoos"         "tchests"        
## [10] "parrots"         "favorite.pirate" "sword.type"     
## [13] "eyepatch"        "sword.time"      "beard.length"   
## [16] "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)