Skip to content

Commit

Permalink
Merge pull request #13 from fhdsl/lesson1
Browse files Browse the repository at this point in the history
Lesson1
  • Loading branch information
caalo committed Oct 6, 2023
2 parents 002a0fb + c6a3fa4 commit a75673c
Show file tree
Hide file tree
Showing 77 changed files with 6,703 additions and 37 deletions.
6 changes: 3 additions & 3 deletions 01-lesson1.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ Common errors:

- Syntax error.

- Changing a variable without realizing you did so.
- It did something else than I expected!

- The function or operation does not accept the input data type.
- The function or operation does not accept the input data type.

- It did something else than I expected!
- Changing a variable without realizing you did so.

Solutions:

Expand Down
12 changes: 4 additions & 8 deletions 02-lesson2.Rmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# W2: Working with data structures
# Working with data structures

## Vectors

Expand Down Expand Up @@ -59,11 +59,7 @@ When we work with operations and functions, we must be mindful what inputs the o

In the exercise this past week, you looked at a new operation to subset elements of a vector using brackets.

**Execution rule for vector brackets**:

*Evaluate the expression in the bracket first. The return value of the expression in the bracket, which must be a numeric or a numeric vector, dictates which elements of the vector to return.*

Inside the bracket is either a single numeric value or an a **numerical indexing vector** containing numerical values.
Inside the bracket is either a single numeric value or an a **numerical indexing vector** containing numerical values. They dictate which elements of the vector to return.

```{r}
staff[2]
Expand All @@ -73,7 +69,7 @@ small_staff = staff[c(1, 2)]

In the last line, we created a new vector `small_staff` that is a subset of the staff given the indexing vector `c(1, 2)`. We have three vectors referenced in one line of code. This is tricky and we need to always refer to our rules step-by-step: evaluate the expression right of the `=`, which contains a vector bracket. Follow the rule of the vector bracket. Then store the returning value to the variable left of `=`.

Alternatively, instead of using numerical indexing vectors, we can use a **logical indexing vector**. The logical indexing vector must be the *same length* as the vector to be subsetted, with TRUE indicating an element to keep, and FALSE indicating an element to drop. The following block of code gives the same value as before:
Alternatively, instead of using numerical indexing vectors, we can use a **logical indexing vector**. The logical indexing vector must be the *same length* as the vector to be subsetted, with `TRUE` indicating an element to keep, and `FALSE` indicating an element to drop. The following block of code gives the same value as before:

```{r}
staff[c(TRUE, FALSE, FALSE)]
Expand Down Expand Up @@ -159,7 +155,7 @@ Here is the data structure you have been waiting for: the **dataframe**. A dataf
For the most part, we load in dataframes from a file path (although they are sometimes created by combining several vectors of the same length, but we won't be covering that here):

```{r}
metadata = read.csv("classroom_data/CCLE_metadata.csv")
load(url("https://github.com/fhdsl/S1_Intro_to_R/raw/main/classroom_data/CCLE.RData"))
```

### Using functions and operations on dataframes
Expand Down
16 changes: 4 additions & 12 deletions slides/lesson1_slides.html
Original file line number Diff line number Diff line change
Expand Up @@ -797,22 +797,14 @@ <h2>Tips on Exercises / Debugging</h2>
<div class="fragment">
<p>Common errors:</p>
<ul>
<li>Syntax error.</li>
<li>Syntax error</li>
</ul>
</div>
<div class="fragment">
<ul>
<li>The function or operation does not accept the input data type.</li>
</ul>
</div>
<div class="fragment">
<ul>
<li>Changing a variable without realizing you did so.</li>
</ul>
</div>
<div class="fragment">
<ul>
<li>It did something else than I expected!</li>
<li><p>It did something else than I expected!</p></li>
<li><p>The function or operation does not accept the input data type.</p></li>
<li><p>Changing a variable without realizing you did so.</p></li>
</ul>
</div>
</section>
Expand Down
19 changes: 5 additions & 14 deletions slides/lesson1_slides.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,13 @@ More importantly: **How we organize ideas \<-\> Instructing a computer to do som

## Setting up Posit Cloud and trying out your first analysis!


## Break

Let's find times for office hours, as well as time for people to work together!

https://www.when2meet.com/?21640707-kwIMj

A pre-course survey:
A pre-course survey:

https://forms.gle/Qz3X9jqpgwowp9Qb8

Expand Down Expand Up @@ -184,7 +183,6 @@ nchar("ATCG")
If an expression is made out of multiple, nested operations, what is the proper way of the R Console interpreting it? Being able to read nested operations and nested functions as a programmer is very important.
:::


## Function machine from algebra class

. . .
Expand Down Expand Up @@ -217,7 +215,6 @@ Lastly, a note on the use of functions: a programmer should not need to know how

- **Logical**: TRUE, FALSE


## Grammar Structure 2: Storing data types in the global environment

. . .
Expand Down Expand Up @@ -295,21 +292,15 @@ sqrt(nchar("hello"))

Common errors:

- Syntax error.

. . .

- The function or operation does not accept the input data type.

. . .

- Changing a variable without realizing you did so.
- Syntax error

. . .

- It did something else than I expected!

. . .
- The function or operation does not accept the input data type.

- Changing a variable without realizing you did so.

## Solutions:

Expand Down
Loading

0 comments on commit a75673c

Please sign in to comment.