@@ -417,28 +417,28 @@ the name of the vector followed by square brackets. In those square brackets
417
417
we place the index (e.g. a number) in that bracket as follows:
418
418
419
419
``` {r, purl = FALSE}
420
- # get the 3rd value in the snp_genes vector
421
- snp_genes [3]
420
+ # get the 3rd value in the snp vector
421
+ snp [3]
422
422
```
423
423
424
424
In R, every item your vector is indexed, starting from the first item (1)
425
425
through to the final number of items in your vector. You can also retrieve a
426
426
range of numbers:
427
427
428
428
``` {r, purl = FALSE}
429
- # get the 1st through 3rd value in the snp_genes vector
429
+ # get the 1st through 3rd value in the snp vector
430
430
431
- snp_genes [1:3]
431
+ snp [1:3]
432
432
```
433
433
434
434
If you want to retrieve several (but not necessarily sequential) items from
435
435
a vector, you pass a ** vector of indices** ; a vector that has the numbered
436
436
positions you wish to retrieve.
437
437
438
438
``` {r, purl = FALSE}
439
- # get the 1st, 3rd, and 4th value in the snp_genes vector
439
+ # get the 1st, 3rd, and 4th value in the snp vector
440
440
441
- snp_genes [c(1, 3, 4)]
441
+ snp [c(1, 3, 4)]
442
442
```
443
443
444
444
There are additional (and perhaps less commonly used) ways of subsetting a
@@ -447,9 +447,9 @@ examples](https://thomasleeper.com/Rcourse/Tutorials/vectorindexing.html)).
447
447
Also, several of these subsetting expressions can be combined:
448
448
449
449
``` {r, purl = FALSE}
450
- # get the 1st through the 3rd value, and 4th value in the snp_genes vector
450
+ # get the 1st through the 3rd value, and 4th value in the snp vector
451
451
# yes, this is a little silly in a vector of only 4 values.
452
- snp_genes [c(1:3,4)]
452
+ snp [c(1:3,4)]
453
453
```
454
454
455
455
## Adding to, removing, or replacing values in existing vectors
@@ -458,7 +458,7 @@ Once you have an existing vector, you may want to add a new item to it. To do
458
458
so, you can use the ` c() ` function again to add your new value:
459
459
460
460
``` {r, purl = FALSE}
461
- # add the gene ' CYP1A1' and ' APOA5' to our list of snp genes
461
+ # add the gene " CYP1A1" and " APOA5" to our list of snp genes
462
462
# this overwrites our existing vector
463
463
snp_genes <- c(snp_genes, "CYP1A1", "APOA5")
464
464
```
0 commit comments