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
## 1  1   male  28    173     70      yes   JSSFP       9       0       0    Jack Sparrow    cutlass        1       0.58
## 2  2   male  31    209    106      yes   JSSFP       9      11       0    Jack Sparrow    cutlass        0       1.11
## 3  3   male  26    170     77      yes    CCCC      10      10       1    Jack Sparrow    cutlass        1       1.44
## 4  4 female  31    144     58       no   JSSFP       2       0       2    Jack Sparrow   scimitar        1      36.11
## 5  5 female  41    158     58      yes   JSSFP       9       6       4            Hook    cutlass        1       0.11
## 6  6   male  26    190     85      yes    CCCC       7      19       0    Jack Sparrow    cutlass        1       0.59
##   beard.length           fav.pixar grogg
## 1           16      Monsters, Inc.    11
## 2           21              WALL-E     9
## 3           19          Inside Out     7
## 4            2          Inside Out     9
## 5            0          Inside Out    14
## 6           17 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)