Artwork by @allison_horst
Challenge 1
- Click the “File” menu button, then “New Project”.
- Click “New Directory”.
- Click “New Project”.
- Type in the name of your project, e.g. “Learning_R”.
- Click the “Create Project” button
The simplest way to open an RStudio project once it has been created
is to click through your file system to get to the directory where it
was saved and double click on the .Rproj
file. This will
open RStudio and start your R session in the same directory as the
.Rproj
file. Any data, plots or scripts can be saved and
retrieved from this directory.
RStudio projects have the added benefit of allowing you to open multiple projects at the same time each open to its own project directory. This allows you to keep multiple projects open without them interfering with each other.
In the bottom right pane in RStudio, click the “Files” tab. To
organise your project, create folders called data
,
scripts
, results
, docs
by
clicking the folder icon with the green plus sign.
The most effective way to work with R is to write the code you want to run in an .R script. You then run the selected lines (by either using a keyboard shortcut or clicking the “Run” button) in the R console.
Open a script (click the white square with the cross in green below
File at the top left). Save the script in your R project folder (click
“File”, then “Save as” and browse to the script
folder in
your project). You could call it Lesson 1.
Artwork by @allison_horst
Challenge 2 View the palmer penguins data here.
- From the window showing the data, save the data as a file (CTRL + S or right mouse click > “Save as”)
- Make sure it’s saved under the name
penguins.csv
- Save the file in the
data
folder within your project.We will load and inspect these data shortly.
Every package author writes help files for their functions. Either of these will load up a help page in RStudio:
?function_name
help(function_name)
Each help page is broken down into sections (Description, Usage, Arguments etc). The last section Examples is very useful.
The command below will bring up the help for the function
log
.
?log
Tip: Help files
One of the most daunting aspects of R is the large number of functions available. It would be prohibitive, if not impossible to remember the correct usage for every function you use. Luckily, the help files mean you don’t have to!
If you’re having trouble using a function, 9 times out of 10, the answers you are seeking have already been answered on Stack Overflow.
We have already saved a .csv data file in our data folder (do the same when you work with your own datasets).
We can load this into R via the following:
penguins <- read.csv(file = "data/penguins.csv")
Here we used the function read.csv
but there are lots of
different functions for reading in different types of files. For example
read_excel
in the readxl package.
Tip: Problems reading in data
If your spreadsheet won’t read in check:
1. You are using the correct function for the type of file, for example
read.csv
for csv files
2. You have included the suffix after the name of the file
3. The name of the file is spelled correctly
4. The file exists in the folder you are directing R to. For example, in
our case we would click on the folder named data under the files tab at
the bottom right of RStudio to check.
5. Look at an example on the internet to ensure you have included all
the necessary arguments. read.csv
only needs
file =
but other functions may need other
arguments.
Once data is in R, you can view it by clicking on it’s name under the Environment window.
In R, datasets are called data frames (df) or sometimes tibbles.
We can begin exploring our data frame right away, pulling out columns
by specifying them using the $
operator:
penguins$species
## [1] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [7] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [13] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [19] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [25] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [31] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [37] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [43] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [49] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [55] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [61] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [67] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [73] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [79] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [85] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [91] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [97] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [103] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [109] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [115] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [121] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [127] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [133] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [139] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [145] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [151] "Adelie" "Adelie" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [157] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [163] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [169] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [175] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [181] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [187] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [193] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [199] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [205] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [211] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [217] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [223] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [229] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [235] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [241] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [247] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [253] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [259] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [265] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [271] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [277] "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap"
## [283] "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap"
## [289] "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap"
## [295] "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap"
## [301] "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap"
## [307] "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap"
## [313] "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap"
## [319] "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap"
## [325] "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap"
## [331] "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap"
## [337] "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap"
## [343] "Chinstrap" "Chinstrap"
penguins$bill_length_mm
## [1] 39.1 39.5 40.3 NA 36.7 39.3 38.9 39.2 34.1 42.0 37.8 37.8 41.1 38.6 34.6
## [16] 36.6 38.7 42.5 34.4 46.0 37.8 37.7 35.9 38.2 38.8 35.3 40.6 40.5 37.9 40.5
## [31] 39.5 37.2 39.5 40.9 36.4 39.2 38.8 42.2 37.6 39.8 36.5 40.8 36.0 44.1 37.0
## [46] 39.6 41.1 37.5 36.0 42.3 39.6 40.1 35.0 42.0 34.5 41.4 39.0 40.6 36.5 37.6
## [61] 35.7 41.3 37.6 41.1 36.4 41.6 35.5 41.1 35.9 41.8 33.5 39.7 39.6 45.8 35.5
## [76] 42.8 40.9 37.2 36.2 42.1 34.6 42.9 36.7 35.1 37.3 41.3 36.3 36.9 38.3 38.9
## [91] 35.7 41.1 34.0 39.6 36.2 40.8 38.1 40.3 33.1 43.2 35.0 41.0 37.7 37.8 37.9
## [106] 39.7 38.6 38.2 38.1 43.2 38.1 45.6 39.7 42.2 39.6 42.7 38.6 37.3 35.7 41.1
## [121] 36.2 37.7 40.2 41.4 35.2 40.6 38.8 41.5 39.0 44.1 38.5 43.1 36.8 37.5 38.1
## [136] 41.1 35.6 40.2 37.0 39.7 40.2 40.6 32.1 40.7 37.3 39.0 39.2 36.6 36.0 37.8
## [151] 36.0 41.5 46.1 50.0 48.7 50.0 47.6 46.5 45.4 46.7 43.3 46.8 40.9 49.0 45.5
## [166] 48.4 45.8 49.3 42.0 49.2 46.2 48.7 50.2 45.1 46.5 46.3 42.9 46.1 44.5 47.8
## [181] 48.2 50.0 47.3 42.8 45.1 59.6 49.1 48.4 42.6 44.4 44.0 48.7 42.7 49.6 45.3
## [196] 49.6 50.5 43.6 45.5 50.5 44.9 45.2 46.6 48.5 45.1 50.1 46.5 45.0 43.8 45.5
## [211] 43.2 50.4 45.3 46.2 45.7 54.3 45.8 49.8 46.2 49.5 43.5 50.7 47.7 46.4 48.2
## [226] 46.5 46.4 48.6 47.5 51.1 45.2 45.2 49.1 52.5 47.4 50.0 44.9 50.8 43.4 51.3
## [241] 47.5 52.1 47.5 52.2 45.5 49.5 44.5 50.8 49.4 46.9 48.4 51.1 48.5 55.9 47.2
## [256] 49.1 47.3 46.8 41.7 53.4 43.3 48.1 50.5 49.8 43.5 51.5 46.2 55.1 44.5 48.8
## [271] 47.2 NA 46.8 50.4 45.2 49.9 46.5 50.0 51.3 45.4 52.7 45.2 46.1 51.3 46.0
## [286] 51.3 46.6 51.7 47.0 52.0 45.9 50.5 50.3 58.0 46.4 49.2 42.4 48.5 43.2 50.6
## [301] 46.7 52.0 50.5 49.5 46.4 52.8 40.9 54.2 42.5 51.0 49.7 47.5 47.6 52.0 46.9
## [316] 53.5 49.0 46.2 50.9 45.5 50.9 50.8 50.1 49.0 51.5 49.8 48.1 51.4 45.7 50.7
## [331] 42.5 52.2 45.2 49.3 50.2 45.6 51.9 46.8 45.7 55.8 43.5 49.6 50.8 50.2
Passing the penguins
data frame through the structure
function str
will show you the type of data for each
variable.
str(penguins)
## 'data.frame': 344 obs. of 8 variables:
## $ species : chr "Adelie" "Adelie" "Adelie" "Adelie" ...
## $ island : chr "Torgersen" "Torgersen" "Torgersen" "Torgersen" ...
## $ bill_length_mm : num 39.1 39.5 40.3 NA 36.7 39.3 38.9 39.2 34.1 42 ...
## $ bill_depth_mm : num 18.7 17.4 18 NA 19.3 20.6 17.8 19.6 18.1 20.2 ...
## $ flipper_length_mm: int 181 186 195 NA 193 190 181 195 193 190 ...
## $ body_mass_g : int 3750 3800 3250 NA 3450 3650 3625 4675 3475 4250 ...
## $ sex : chr "male" "female" "female" NA ...
## $ year : int 2007 2007 2007 2007 2007 2007 2007 2007 2007 2007 ...
‘str’ shows us that species is chr
which is short for
character. This means R will treat species as a factor (in other words,
discrete data). Bill_length_mm is num
which stands for
numeric. int
means integer. Both num
and
int
variables are treated as continuous (scale) data by
R.
We can calculate the mean of bill length.
mean(penguins$bill_length_mm, na.rm = TRUE)
## [1] 43.92193
But we can’t use the mean function on a factor.
mean(penguins$species, na.rm = TRUE)
## Warning in mean.default(penguins$species, na.rm = TRUE): argument is not numeric
## or logical: returning NA
## [1] NA
Tip: When functions won’t work
Sometimes R errors are caused by R treating a variable as a factor
when you know it’s a number. Checking what R is “thinking” with
str
can help.
The $
operator will specify a variable in a data frame.
You can also use indexing.
Challenge 3
There are several subtly different ways to call variables, observations and elements from data.frames using indexing:
Try out these examples and after a # in your script describe what data is returned by each one.
penguins[1]
penguins[1, 1]
penguins[, 1]
penguins[1, ]
penguins[1]
## species
## 1 Adelie
## 2 Adelie
## 3 Adelie
## 4 Adelie
## 5 Adelie
## 6 Adelie
## 7 Adelie
## 8 Adelie
## 9 Adelie
## 10 Adelie
## 11 Adelie
## 12 Adelie
## 13 Adelie
## 14 Adelie
## 15 Adelie
## 16 Adelie
## 17 Adelie
## 18 Adelie
## 19 Adelie
## 20 Adelie
## 21 Adelie
## 22 Adelie
## 23 Adelie
## 24 Adelie
## 25 Adelie
## 26 Adelie
## 27 Adelie
## 28 Adelie
## 29 Adelie
## 30 Adelie
## 31 Adelie
## 32 Adelie
## 33 Adelie
## 34 Adelie
## 35 Adelie
## 36 Adelie
## 37 Adelie
## 38 Adelie
## 39 Adelie
## 40 Adelie
## 41 Adelie
## 42 Adelie
## 43 Adelie
## 44 Adelie
## 45 Adelie
## 46 Adelie
## 47 Adelie
## 48 Adelie
## 49 Adelie
## 50 Adelie
## 51 Adelie
## 52 Adelie
## 53 Adelie
## 54 Adelie
## 55 Adelie
## 56 Adelie
## 57 Adelie
## 58 Adelie
## 59 Adelie
## 60 Adelie
## 61 Adelie
## 62 Adelie
## 63 Adelie
## 64 Adelie
## 65 Adelie
## 66 Adelie
## 67 Adelie
## 68 Adelie
## 69 Adelie
## 70 Adelie
## 71 Adelie
## 72 Adelie
## 73 Adelie
## 74 Adelie
## 75 Adelie
## 76 Adelie
## 77 Adelie
## 78 Adelie
## 79 Adelie
## 80 Adelie
## 81 Adelie
## 82 Adelie
## 83 Adelie
## 84 Adelie
## 85 Adelie
## 86 Adelie
## 87 Adelie
## 88 Adelie
## 89 Adelie
## 90 Adelie
## 91 Adelie
## 92 Adelie
## 93 Adelie
## 94 Adelie
## 95 Adelie
## 96 Adelie
## 97 Adelie
## 98 Adelie
## 99 Adelie
## 100 Adelie
## 101 Adelie
## 102 Adelie
## 103 Adelie
## 104 Adelie
## 105 Adelie
## 106 Adelie
## 107 Adelie
## 108 Adelie
## 109 Adelie
## 110 Adelie
## 111 Adelie
## 112 Adelie
## 113 Adelie
## 114 Adelie
## 115 Adelie
## 116 Adelie
## 117 Adelie
## 118 Adelie
## 119 Adelie
## 120 Adelie
## 121 Adelie
## 122 Adelie
## 123 Adelie
## 124 Adelie
## 125 Adelie
## 126 Adelie
## 127 Adelie
## 128 Adelie
## 129 Adelie
## 130 Adelie
## 131 Adelie
## 132 Adelie
## 133 Adelie
## 134 Adelie
## 135 Adelie
## 136 Adelie
## 137 Adelie
## 138 Adelie
## 139 Adelie
## 140 Adelie
## 141 Adelie
## 142 Adelie
## 143 Adelie
## 144 Adelie
## 145 Adelie
## 146 Adelie
## 147 Adelie
## 148 Adelie
## 149 Adelie
## 150 Adelie
## 151 Adelie
## 152 Adelie
## 153 Gentoo
## 154 Gentoo
## 155 Gentoo
## 156 Gentoo
## 157 Gentoo
## 158 Gentoo
## 159 Gentoo
## 160 Gentoo
## 161 Gentoo
## 162 Gentoo
## 163 Gentoo
## 164 Gentoo
## 165 Gentoo
## 166 Gentoo
## 167 Gentoo
## 168 Gentoo
## 169 Gentoo
## 170 Gentoo
## 171 Gentoo
## 172 Gentoo
## 173 Gentoo
## 174 Gentoo
## 175 Gentoo
## 176 Gentoo
## 177 Gentoo
## 178 Gentoo
## 179 Gentoo
## 180 Gentoo
## 181 Gentoo
## 182 Gentoo
## 183 Gentoo
## 184 Gentoo
## 185 Gentoo
## 186 Gentoo
## 187 Gentoo
## 188 Gentoo
## 189 Gentoo
## 190 Gentoo
## 191 Gentoo
## 192 Gentoo
## 193 Gentoo
## 194 Gentoo
## 195 Gentoo
## 196 Gentoo
## 197 Gentoo
## 198 Gentoo
## 199 Gentoo
## 200 Gentoo
## 201 Gentoo
## 202 Gentoo
## 203 Gentoo
## 204 Gentoo
## 205 Gentoo
## 206 Gentoo
## 207 Gentoo
## 208 Gentoo
## 209 Gentoo
## 210 Gentoo
## 211 Gentoo
## 212 Gentoo
## 213 Gentoo
## 214 Gentoo
## 215 Gentoo
## 216 Gentoo
## 217 Gentoo
## 218 Gentoo
## 219 Gentoo
## 220 Gentoo
## 221 Gentoo
## 222 Gentoo
## 223 Gentoo
## 224 Gentoo
## 225 Gentoo
## 226 Gentoo
## 227 Gentoo
## 228 Gentoo
## 229 Gentoo
## 230 Gentoo
## 231 Gentoo
## 232 Gentoo
## 233 Gentoo
## 234 Gentoo
## 235 Gentoo
## 236 Gentoo
## 237 Gentoo
## 238 Gentoo
## 239 Gentoo
## 240 Gentoo
## 241 Gentoo
## 242 Gentoo
## 243 Gentoo
## 244 Gentoo
## 245 Gentoo
## 246 Gentoo
## 247 Gentoo
## 248 Gentoo
## 249 Gentoo
## 250 Gentoo
## 251 Gentoo
## 252 Gentoo
## 253 Gentoo
## 254 Gentoo
## 255 Gentoo
## 256 Gentoo
## 257 Gentoo
## 258 Gentoo
## 259 Gentoo
## 260 Gentoo
## 261 Gentoo
## 262 Gentoo
## 263 Gentoo
## 264 Gentoo
## 265 Gentoo
## 266 Gentoo
## 267 Gentoo
## 268 Gentoo
## 269 Gentoo
## 270 Gentoo
## 271 Gentoo
## 272 Gentoo
## 273 Gentoo
## 274 Gentoo
## 275 Gentoo
## 276 Gentoo
## 277 Chinstrap
## 278 Chinstrap
## 279 Chinstrap
## 280 Chinstrap
## 281 Chinstrap
## 282 Chinstrap
## 283 Chinstrap
## 284 Chinstrap
## 285 Chinstrap
## 286 Chinstrap
## 287 Chinstrap
## 288 Chinstrap
## 289 Chinstrap
## 290 Chinstrap
## 291 Chinstrap
## 292 Chinstrap
## 293 Chinstrap
## 294 Chinstrap
## 295 Chinstrap
## 296 Chinstrap
## 297 Chinstrap
## 298 Chinstrap
## 299 Chinstrap
## 300 Chinstrap
## 301 Chinstrap
## 302 Chinstrap
## 303 Chinstrap
## 304 Chinstrap
## 305 Chinstrap
## 306 Chinstrap
## 307 Chinstrap
## 308 Chinstrap
## 309 Chinstrap
## 310 Chinstrap
## 311 Chinstrap
## 312 Chinstrap
## 313 Chinstrap
## 314 Chinstrap
## 315 Chinstrap
## 316 Chinstrap
## 317 Chinstrap
## 318 Chinstrap
## 319 Chinstrap
## 320 Chinstrap
## 321 Chinstrap
## 322 Chinstrap
## 323 Chinstrap
## 324 Chinstrap
## 325 Chinstrap
## 326 Chinstrap
## 327 Chinstrap
## 328 Chinstrap
## 329 Chinstrap
## 330 Chinstrap
## 331 Chinstrap
## 332 Chinstrap
## 333 Chinstrap
## 334 Chinstrap
## 335 Chinstrap
## 336 Chinstrap
## 337 Chinstrap
## 338 Chinstrap
## 339 Chinstrap
## 340 Chinstrap
## 341 Chinstrap
## 342 Chinstrap
## 343 Chinstrap
## 344 Chinstrap
Calls the data in column 1.
penguins[1, 1]
## [1] "Adelie"
Calls the information that is in the first row, first column.
penguins[, 1]
## [1] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [7] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [13] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [19] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [25] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [31] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [37] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [43] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [49] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [55] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [61] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [67] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [73] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [79] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [85] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [91] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [97] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [103] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [109] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [115] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [121] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [127] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [133] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [139] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [145] "Adelie" "Adelie" "Adelie" "Adelie" "Adelie" "Adelie"
## [151] "Adelie" "Adelie" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [157] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [163] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [169] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [175] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [181] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [187] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [193] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [199] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [205] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [211] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [217] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [223] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [229] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [235] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [241] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [247] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [253] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [259] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [265] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [271] "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo" "Gentoo"
## [277] "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap"
## [283] "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap"
## [289] "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap"
## [295] "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap"
## [301] "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap"
## [307] "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap"
## [313] "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap"
## [319] "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap"
## [325] "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap"
## [331] "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap"
## [337] "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap" "Chinstrap"
## [343] "Chinstrap" "Chinstrap"
Also, calls the first column.
penguins[1, ]
## species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g
## 1 Adelie Torgersen 39.1 18.7 181 3750
## sex year
## 1 male 2007
Calls the first row.
Adapted from R for Reproducible Scientific Analysis licensed CC_BY 4.0 by The Carpentries