@@ -518,10 +518,13 @@ human_chr_number * 2
518
518
519
519
## Exercise: Compute the golden ratio
520
520
521
+ The [ golden ratio] ( https://en.wikipedia.org/wiki/Golden_ratio ) is a famous
522
+ mathematical constant associated with beauty, architecture, and [ art] ( https://www.mos.org/leonardo/activities/golden-ratio.html ) .
523
+
521
524
One approximation of the golden ratio (φ) can be found by taking the sum of 1
522
- and the square root of 5, and dividing by 2 as in the example above. Compute
525
+ and the square root of 5, and dividing that sum by 2, as in the example above. Compute
523
526
the golden ratio to 3 digits of precision using the ` sqrt() ` and ` round() `
524
- functions. Hint: remember the ` round() ` function can take 2 arguments.
527
+ functions. Hint: the ` round() ` function can take 2 arguments.
525
528
526
529
::::::::::::::: solution
527
530
@@ -536,7 +539,8 @@ round((1 + sqrt(5)) / 2, digits = 3)
536
539
[1] 1.618
537
540
```
538
541
539
- Notice that you can place one function inside of another.
542
+ Notice that you can place one function inside of another, and that you can use
543
+ the 'digits' argument to return the desired precision.
540
544
541
545
542
546
@@ -605,6 +609,7 @@ Let's create a few more vectors to play around with:
605
609
``` r
606
610
# Some interesting human SNPs
607
611
# while accuracy is important, typos in the data won't hurt you here
612
+ # feel free to copy and paste
608
613
609
614
snps <- c(" rs53576" , " rs1815739" , " rs6152" , " rs1799971" )
610
615
snp_chromosomes <- c(" 3" , " 11" , " X" , " 6" )
@@ -910,8 +915,8 @@ c("ACTN3","APOA5") %in% snp_genes
910
915
## Tip: What's the difference between the ` %in% and the ` ==` operators?
911
916
912
917
The ` %in% ` operator is used to test if the elements of a vector are
913
- present in another vector. In the example above, if both "ACTN3" and "APOA5" are in
914
- the vector ` snp_genes ` , then R will return ` TRUE TRUE ` since they are both present.
918
+ present in another vector. In the example above, if both "ACTN3" and "APOA5" are in
919
+ the vector ` snp_genes ` , then R will return ` TRUE TRUE ` since they are both present.
915
920
If "ACTN3" is but "APOA5" is not in ` snp_genes ` , then R will return ` TRUE FALSE ` . The ` == ` operator
916
921
is used to test if two vectors are exactly equal. For example, if you wanted to know if the vector ` c(1, 2, 3) `
917
922
was equal to the vector ` c(1, 2, 3) ` , you could use the ` == ` operator. One trick people sometimes
0 commit comments