Skip to content

Commit

Permalink
Merge branch '415-june-2019-lesson-release' (close #418)
Browse files Browse the repository at this point in the history
  • Loading branch information
katrinleinweber authored and Katrin Leinweber committed May 24, 2019
2 parents ca1590b + 8fe49a9 commit 8cdd15a
Show file tree
Hide file tree
Showing 57 changed files with 535 additions and 549 deletions.
79 changes: 76 additions & 3 deletions _episodes_rmd/01-starting-with-data.Rmd
Expand Up @@ -85,19 +85,49 @@ The filename needs to be a character string (or [string]({{ page.root }}/referen

> ## Loading Data with Headers
>
> What happens if you forget to put `header = FALSE`? The default value is `header = TRUE`, which you can check with `?read.csv` or `help(read.csv)`. What do you expect will happen if you leave the default value? Before you run any code, think about what will happen to the first few rows of your data frame, and its overall size. Then run the following code and see if your expectations agree:
> What happens if you forget to put `header = FALSE`? The default value is
> `header = TRUE`, which you can check with `?read.csv` or `help(read.csv)`.
> What do you expect will happen if you leave the default value?
> Before you run any code, think about what will happen to the first few rows
> of your data frame, and its overall size. Then run the following code and
> see if your expectations agree:
>
> ~~~
> read.csv(file = "data/inflammation-01.csv")
> ~~~
> {: .language-r}
>
> > ## Solution
> >
> > R will construct column headers from values in your first row of data,
> > resulting in `X0 X0.1 X1 X3 X1.1 X2 ...`.
> >
> > Note that the `X` is prepended just a number would not be a valid variable
> > name. Because that's what column headers are, the same rules apply.
> > Appending `.1`, `.2` etc. is necessary to avoid duplicate column headers.
> {: .solution}
{: .challenge}

> ## Reading Different Decimal Point Formats
>
> Depending on the country you live in, your standard can use the dot or the comma as decimal mark.
> Also, different devices or software can generate data with different decimal points.
> Take a look at `?read.csv` and write the code to load a file called `commadec.txt` that has numeric values with commas as decimal mark, separated by semicolons.
>
> > ## Solution
> >
> > ~~~
> > read.csv(file = "data/commadec.txt", sep = ";", dec = ",")
> > ~~~
> > {: .language-r}
> >
> > or the built-in shortcut:
> >
> > ~~~
> > read.csv2(file = "data/commadec.txt")
> > ~~~
> > {: .language-r}
> {: .solution}
{: .challenge}

A function will perform its given action on whatever value is passed to the argument(s).
Expand Down Expand Up @@ -196,7 +226,8 @@ This is different from the way spreadsheets work.

> ## Printing with Parentheses
>
> An alternative way to print the value of a variable is to use () around the assignment statement.
> An alternative way to print the value of a variable is to use
> `(` parentheses `)` around the assignment statement.
> As an example: `(total_weight <- weight_kg + weight_lb)` adds the values of `weight_kg` and `weight_lb`,
> assigns the result to the `total_weight`,
> and finally prints the assigned value of the variable `total_weight`.
Expand Down Expand Up @@ -227,6 +258,26 @@ head(dat)
> age <- age - 20
> ~~~
> {: .language-r}
>
> > ## Solution
> >
> > ~~~
> > mass <- 47.5
> > age <- 122
> > ~~~
> > {: .language-r}
> >
> > <img src="../fig/mass-age-assign-1.svg" alt="Assigning Variables" />
> >
> > ~~~
> > mass <- mass * 2.0
> > age <- age - 20
> > ~~~
> > {: .language-r}
> >
> > <img src="../fig/mass-age-assign-2.svg" alt="Assigning Variables" />
> >
> {: .solution}
{: .challenge}

### Manipulating Data
Expand Down Expand Up @@ -376,7 +427,8 @@ sd(dat[, 7])
> Note that R may return an error when you attempt to perform similar calculations on
> sliced *rows* of data frames. This is because some functions in R automatically convert
> the object type to a numeric vector, while others do not (e.g. `max(dat[1, ])` works as
> expected, while `mean(dat[1, ])` returns an error). You can fix this by including an
> expected, while `mean(dat[1, ])` returns `NA` and a warning). You get the
> expected output by including an
> explicit call to `as.numeric()`, e.g. `mean(as.numeric(dat[1, ]))`. By contrast,
> calculations on sliced *columns* always work as expected, since columns of data frames
> are already defined as vectors.
Expand Down Expand Up @@ -449,6 +501,18 @@ We'll learn why this is so in the next lesson.
> explain what `animal[-1:-4]` does.
>
> 1. Use a slice of `animal` to create a new character vector that spells the word "eon", i.e. `c("e", "o", "n")`.
> > ## Solutions
> >
> > 1. `animal[4:1]`
> >
> > 1. `"o" "n" "k" "e" "y"` and `"m" "o" "n" "e" "y"`, which means that a
> > single `-` removes the element at the given index position.
> > `animal[-1:-4]` remove the slice, returning `"e" "y"`, which is
> > equivalent to `animal[5:6]`.
> >
> > 1. `animal[c(5,2,3)]` combines indexing with the `c`ombine function.
> >
> {: .solution}
{: .challenge}

> ## Subsetting More Data
Expand Down Expand Up @@ -558,6 +622,15 @@ The maximum value rises and falls perfectly smoothly, while the minimum seems to
> ## Plotting Data
>
> Create a plot showing the standard deviation of the inflammation data for each day across all patients.
>
> > ## Solution
> >
> > ~~~
> > sd_day_inflammation <- apply(dat, 2, sd)
> > plot(sd_day_inflammation)
> > ~~~
> > {: .language-r}
> {: .solution}
{: .challenge}

{% include links.md %}
9 changes: 9 additions & 0 deletions _episodes_rmd/02-func-R.Rmd
Expand Up @@ -204,6 +204,15 @@ Real-life functions will usually be larger than the ones shown here--typically h
> 3. 23
> 4. 30
> 2. If `mySum(3)` returns 13, why does `mySum(input_2 = 3)` return an error?
>
> > ## Solution
> >
> > Read the error message: `argument "input_1" is missing, with no default`
> > means that no value for `input_1` is provided in the function call,
> > and neither in the function's defintion. Thus, the addition in the
> > function body can not be completed.
> >
> {: .solution}
{: .challenge}

### Testing and Documenting
Expand Down
2 changes: 1 addition & 1 deletion _includes/all_figures.html
Expand Up @@ -60,7 +60,7 @@
<hr/>
<p><img alt="plot of chunk inflammation-01" src="../fig/rmd-04-cond-inflammation-01-3.png" /></p>
<hr/>
<p><img alt="plot of chunk logical_vectors_indexing2" src="../fig/rmd-logical_vectors_indexing2-1.png" /></p>
<p><img alt="plot of chunk logical_vectors_indexing2" src="../fig/rmd-10-supp-addressing-data-logical_vectors_indexing2" /></p>
<hr/>
<p><img alt="csv written without row.names argument" src="../fig/01-supp-csv-with-row-nums.png" /></p>
<hr/>
Expand Down
23 changes: 0 additions & 23 deletions bin/boilerplate/.travis.yml

This file was deleted.

1 change: 0 additions & 1 deletion bin/boilerplate/AUTHORS

This file was deleted.

1 change: 0 additions & 1 deletion bin/boilerplate/CITATION

This file was deleted.

151 changes: 0 additions & 151 deletions bin/boilerplate/CONTRIBUTING.md

This file was deleted.

40 changes: 0 additions & 40 deletions bin/boilerplate/README.md

This file was deleted.

0 comments on commit 8cdd15a

Please sign in to comment.