Skip to content

Commit

Permalink
Merge pull request #216 from JasonJWilliamsNY/18-Get-rid-of-lists-mat…
Browse files Browse the repository at this point in the history
…erial
  • Loading branch information
naupaka authored Jun 14, 2023
2 parents 9b4a85b + a4d2bd8 commit ec0db09
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions episodes/01-r-basics.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ source: Rmd
- Be able to use arithmetic operators on R objects
- Be able to retrieve (subset), name, or replace, values from a vector
- Be able to use logical operators in a subsetting operation
- Understand that lists can hold data of more than one mode and can be indexed

::::::::::::::::::::::::::::::::::::::::::::::::::

Expand Down Expand Up @@ -53,7 +52,7 @@ below.

**Here are some R skills we will *not* cover in these lessons**

- How to create and work with R matrices and R lists
- How to create and work with R matrices
- How to create and work with loops and conditional statements, and the "apply"
family of functions (which are super useful, read more [here](https://www.r-bloggers.com/r-tutorial-on-the-apply-family-of-functions/))
- How to do basic string manipulations (e.g. finding patterns in text using grep, replacing text)
Expand Down Expand Up @@ -82,7 +81,7 @@ need this technical knowledge.
and applications for R
- [Programming in R Software Carpentry lesson](https://software-carpentry.org/lessons/):
There are several Software Carpentry lessons in R to choose from


::::::::::::::::::::::::::::::::::::::::::::::::::

Expand Down Expand Up @@ -140,9 +139,9 @@ status/warning/error messages (usually in red).

In the 'Environment' window you will also get a table:

| Values | |
| Values | |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| a | 1 |
| a | 1 |

The 'Environment' window allows you to keep track of the objects you have
created in R.
Expand Down Expand Up @@ -262,11 +261,11 @@ We will get to the "length" property later in the lesson. The **"mode" property*
**corresponds to the type of data an object represents**. The most common modes
you will encounter in R are:

| Mode (abbreviation) | Type of data |
| Mode (abbreviation) | Type of data |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Numeric (num) | Numbers such floating point/decimals (1.0, 0.5, 3.14), there are also more specific numeric types (dbl - Double, int - Integer). These differences are not relevant for most beginners and pertain to how these values are stored in memory |
| Character (chr) | A sequence of letters/numbers in single '' or double " " quotes |
| Logical | Boolean values - TRUE or FALSE |
| Numeric (num) | Numbers such floating point/decimals (1.0, 0.5, 3.14), there are also more specific numeric types (dbl - Double, int - Integer). These differences are not relevant for most beginners and pertain to how these values are stored in memory |
| Character (chr) | A sequence of letters/numbers in single '' or double " " quotes |
| Logical | Boolean values - TRUE or FALSE |

There are a few other modes (i.e. "complex", "raw" etc.) but these
are the three we will work with in this lesson.
Expand Down Expand Up @@ -342,15 +341,15 @@ appropriately manipulate that object. For example, objects of the numeric modes
can be added, multiplied, divided, etc. R provides several mathematical
(arithmetic) operators including:

| Operator | Description |
| Operator | Description |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| \+ | addition |
| \- | subtraction |
| \* | multiplication |
| / | division |
| ^ or \*\* | exponentiation |
| a%/%b | integer division (division where the remainder is discarded) |
| a%%b | modulus (returns the remainder after division) |
| \+ | addition |
| \- | subtraction |
| \* | multiplication |
| / | division |
| ^ or \*\* | exponentiation |
| a%/%b | integer division (division where the remainder is discarded) |
| a%%b | modulus (returns the remainder after division) |

These can be used with literal numbers:

Expand Down Expand Up @@ -563,17 +562,17 @@ snp_positions[snp_positions > 100000000]

In the square brackets you place the name of the vector followed by the comparison operator and (in this case) a numeric value. Some of the most common logical operators you will use in R are:

| Operator | Description |
| Operator | Description |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| \< | less than |
| \<= | less than or equal to |
| \> | greater than |
| \>= | greater than or equal to |
| \== | exactly equal to |
| != | not equal to |
| !x | not x |
| a | b | a or b |
| a \& b | a and b |
| \< | less than |
| \<= | less than or equal to |
| \> | greater than |
| \>= | greater than or equal to |
| \== | exactly equal to |
| != | not equal to |
| !x | not x |
| a | b | a or b |
| a \& b | a and b |

::::::::::::::::::::::::::::::::::::::::: callout

Expand Down Expand Up @@ -639,7 +638,7 @@ but the `is.NA()` function will return a logical vector, with TRUE for any NA
value:

```{r, purl=FALSE}
# current value of 'snp_genes':
# current value of 'snp_genes':
# chr [1:7] "OXTR" "ACTN3" "AR" "OPRM1" "CYP1A1" NA "APOA5"
is.na(snp_genes)
Expand Down Expand Up @@ -779,7 +778,9 @@ typeof(combined)

::::::::::::::::::::::::::::::::::::::::::::::::::

## Bonus material: Lists
::::::::::::::::::::::::::::::::::::::::: callout

## Lists

Lists are quite useful in R, but we won't be using them in the genomics lessons.
That said, you may come across lists in the way that some bioinformatics
Expand Down Expand Up @@ -820,6 +821,7 @@ To get the first value in the `position` object, use the `[]` notation to index:
snp_data$position[1]
```
:::::::::::::::::::::::::::::::::::::::::

:::::::::::::::::::::::::::::::::::::::: keypoints

Expand All @@ -828,5 +830,3 @@ snp_data$position[1]
- Working with vectors effectively prepares you for understanding how data are organized in R.

::::::::::::::::::::::::::::::::::::::::::::::::::


0 comments on commit ec0db09

Please sign in to comment.