Skip to content

Commit

Permalink
Merge pull request #303 from JasonJWilliamsNY/patch-for-299
Browse files Browse the repository at this point in the history
Patch for #299
  • Loading branch information
naupaka authored Nov 9, 2024
2 parents 5d7055b + b456d85 commit 76b12f0
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions episodes/01-r-basics.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -446,10 +446,13 @@ human_chr_number * 2

## Exercise: Compute the golden ratio

The [golden ratio](https://en.wikipedia.org/wiki/Golden_ratio) is a famous
mathematical constant associated with beauty, architecture, and [art](https://www.mos.org/leonardo/activities/golden-ratio.html).

One approximation of the golden ratio (φ) can be found by taking the sum of 1
and the square root of 5, and dividing by 2 as in the example above. Compute
and the square root of 5, and dividing that sum by 2, as in the example above. Compute
the golden ratio to 3 digits of precision using the `sqrt()` and `round()`
functions. Hint: remember the `round()` function can take 2 arguments.
functions. Hint: the `round()` function can take 2 arguments.

::::::::::::::: solution

Expand All @@ -459,7 +462,8 @@ functions. Hint: remember the `round()` function can take 2 arguments.
round((1 + sqrt(5)) / 2, digits = 3)
```

Notice that you can place one function inside of another.
Notice that you can place one function inside of another, and that you can use
the 'digits' argument to return the desired precision.



Expand Down Expand Up @@ -507,6 +511,7 @@ Let's create a few more vectors to play around with:
```{r, purl=FALSE}
# Some interesting human SNPs
# while accuracy is important, typos in the data won't hurt you here
# feel free to copy and paste
snps <- c("rs53576", "rs1815739", "rs6152", "rs1799971")
snp_chromosomes <- c("3", "11", "X", "6")
Expand Down Expand Up @@ -736,8 +741,8 @@ c("ACTN3","APOA5") %in% snp_genes
## Tip: What's the difference between the `%in% and the `==` operators?

The `%in%` operator is used to test if the elements of a vector are
present in another vector. In the example above, if both "ACTN3" and "APOA5" are in
the vector `snp_genes`, then R will return `TRUE TRUE` since they are both present.
present in another vector. In the example above, if both "ACTN3" and "APOA5" are in
the vector `snp_genes`, then R will return `TRUE TRUE` since they are both present.
If "ACTN3" is but "APOA5" is not in `snp_genes`, then R will return `TRUE FALSE`. The `==` operator
is used to test if two vectors are exactly equal. For example, if you wanted to know if the vector `c(1, 2, 3)`
was equal to the vector `c(1, 2, 3)`, you could use the `==` operator. One trick people sometimes
Expand Down

0 comments on commit 76b12f0

Please sign in to comment.