@@ -446,10 +446,13 @@ human_chr_number * 2
446
446
447
447
## Exercise: Compute the golden ratio
448
448
449
+ The [ golden ratio] ( https://en.wikipedia.org/wiki/Golden_ratio ) is a famous
450
+ mathematical constant associated with beauty, architecture, and [ art] ( https://www.mos.org/leonardo/activities/golden-ratio.html ) .
451
+
449
452
One approximation of the golden ratio (φ) can be found by taking the sum of 1
450
- and the square root of 5, and dividing by 2 as in the example above. Compute
453
+ and the square root of 5, and dividing that sum by 2, as in the example above. Compute
451
454
the golden ratio to 3 digits of precision using the ` sqrt() ` and ` round() `
452
- functions. Hint: remember the ` round() ` function can take 2 arguments.
455
+ functions. Hint: the ` round() ` function can take 2 arguments.
453
456
454
457
::::::::::::::: solution
455
458
@@ -459,7 +462,8 @@ functions. Hint: remember the `round()` function can take 2 arguments.
459
462
round((1 + sqrt(5)) / 2, digits = 3)
460
463
```
461
464
462
- Notice that you can place one function inside of another.
465
+ Notice that you can place one function inside of another, and that you can use
466
+ the 'digits' argument to return the desired precision.
463
467
464
468
465
469
@@ -507,6 +511,7 @@ Let's create a few more vectors to play around with:
507
511
``` {r, purl=FALSE}
508
512
# Some interesting human SNPs
509
513
# while accuracy is important, typos in the data won't hurt you here
514
+ # feel free to copy and paste
510
515
511
516
snps <- c("rs53576", "rs1815739", "rs6152", "rs1799971")
512
517
snp_chromosomes <- c("3", "11", "X", "6")
@@ -736,8 +741,8 @@ c("ACTN3","APOA5") %in% snp_genes
736
741
## Tip: What's the difference between the ` %in% and the ` ==` operators?
737
742
738
743
The ` %in% ` operator is used to test if the elements of a vector are
739
- present in another vector. In the example above, if both "ACTN3" and "APOA5" are in
740
- the vector ` snp_genes ` , then R will return ` TRUE TRUE ` since they are both present.
744
+ present in another vector. In the example above, if both "ACTN3" and "APOA5" are in
745
+ the vector ` snp_genes ` , then R will return ` TRUE TRUE ` since they are both present.
741
746
If "ACTN3" is but "APOA5" is not in ` snp_genes ` , then R will return ` TRUE FALSE ` . The ` == ` operator
742
747
is used to test if two vectors are exactly equal. For example, if you wanted to know if the vector ` c(1, 2, 3) `
743
748
was equal to the vector ` c(1, 2, 3) ` , you could use the ` == ` operator. One trick people sometimes
0 commit comments