Skip to content

Commit

Permalink
Remove hardcoded div titles
Browse files Browse the repository at this point in the history
  • Loading branch information
Bisaloo committed Apr 19, 2024
1 parent 9c2c1e2 commit f3c1419
Show file tree
Hide file tree
Showing 11 changed files with 0 additions and 107 deletions.
22 changes: 0 additions & 22 deletions episodes/01-starting-with-data.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,13 @@ read.csv(file = "data/inflammation-01.csv")

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

## 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 character `X` is prepended: a standalone number would not be a valid variable
name. Because column headers are variables, the same naming rules apply.
Appending `.1`, `.2` etc. is necessary to avoid duplicate column headers.



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

::::::::::::::::::::::::::::::::::::::::::::::::::
Expand All @@ -142,8 +138,6 @@ Take a look at `?read.csv` and write the code to load a file called `commadec.tx

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

## Solution

```r
read.csv(file = "data/commadec.txt", sep = ";", dec = ",")
```
Expand Down Expand Up @@ -303,8 +297,6 @@ age <- age - 20

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

## Solution

```r
mass <- 47.5
age <- 122
Expand Down Expand Up @@ -566,8 +558,6 @@ animal[4:6]

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

## Solutions

1. `animal[4:1]`

2. `"o" "n" "k" "e" "y"` and `"m" "o" "n" "e" "y"`, which means that a
Expand Down Expand Up @@ -596,8 +586,6 @@ Which of the following lines of R code gives the correct answer?

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

## Solution

Answer: 3

Explanation: You want to extract the part of the dataframe representing data for patient 5 from days three to seven. In this dataframe, patient data is organised in rows and the days are represented by the columns. Subscripting in R follows the `[i, j]` principle, where `i = rows` and `j = columns`. Thus, answer 3 is correct since the patient is represented by the value for i (5) and the days are represented by the values in j, which is a subset spanning day 3 to 7.
Expand All @@ -619,8 +607,6 @@ Let's pretend there was something wrong with the instrument on the first five da

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

## Solution

```r
whichPatients <- seq(2, 60, 2) # i.e., which rows
whichDays <- seq(1, 5) # i.e., which columns
Expand Down Expand Up @@ -655,8 +641,6 @@ apply call and check your intuition by applying the mean function.

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

## Solution

```r
# 1.
apply(dat[1:5, ], 1, mean)
Expand Down Expand Up @@ -708,8 +692,6 @@ Create a plot showing the standard deviation of the inflammation data for each d

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

## Solution

```r
sd_day_inflammation <- apply(dat, 2, sd)
plot(sd_day_inflammation)
Expand All @@ -719,8 +701,6 @@ plot(sd_day_inflammation)

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



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

- Use `variable <- value` to assign a value to a variable in order to record it in memory.
Expand All @@ -735,5 +715,3 @@ plot(sd_day_inflammation)
- Use `plot` to create simple visualizations.

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


12 changes: 0 additions & 12 deletions episodes/02-func-R.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ highlight(best_practice, asterisk)

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

## Solution

```r
highlight <- function(content, wrapper) {
answer <- c(wrapper, content, wrapper)
Expand All @@ -188,8 +186,6 @@ edges(dry_principle)

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

## Solution

```r
edges <- function(v) {
first <- v[1]
Expand Down Expand Up @@ -241,8 +237,6 @@ mySum <- function(input_1, input_2 = 10) {

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

## Solution

1. The solution is `a.`.

2. Read the error message: `argument "input_1" is missing, with no default`
Expand Down Expand Up @@ -428,8 +422,6 @@ Be sure to document your function with comments.

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

## Solution

```r
analyze <- function(filename) {
# Plots the average, min, and max inflammation over time.
Expand Down Expand Up @@ -460,8 +452,6 @@ Test that your `rescale` function is working properly using `min`, `max`, and `p

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

## Solution

```r
rescale <- function(v) {
# Rescales a vector, v, to lie in the range 0 to 1.
Expand Down Expand Up @@ -608,8 +598,6 @@ both are given the same input vector and parameters?

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

## Solution

```r
rescale <- function(v, lower = 0, upper = 1) {
# Rescales a vector, v, to lie in the range lower to upper.
Expand Down
8 changes: 0 additions & 8 deletions episodes/03-loops-R.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ print_N(3)

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

## Solution

```r
print_N <- function(N) {
nseq <- seq(N)
Expand Down Expand Up @@ -226,8 +224,6 @@ total(ex_vec)

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

## Solution

```r
total <- function(vec) {
# calculates the sum of the values in a vector
Expand Down Expand Up @@ -268,8 +264,6 @@ expo(2, 4)

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

## Solution

```r
expo <- function(base, power) {
result <- 1
Expand Down Expand Up @@ -374,8 +368,6 @@ and runs `analyze` for each file whose name matches the pattern.

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

## Solution

```r
analyze_all <- function(folder = "data", pattern) {
# Runs the function analyze for each file in the given folder
Expand Down
8 changes: 0 additions & 8 deletions episodes/04-cond.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,6 @@ plot_dist(dat[1:5, 10], threshold = 10) # samples (rows) 1-5 on day (column) 10

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

## Solution

```r
plot_dist <- function(x, threshold) {
if (length(x) > threshold) {
Expand Down Expand Up @@ -302,8 +300,6 @@ plot_dist(dat[1:5, 10], threshold = 10) # samples (rows) 1-5

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

## Solution

```r
plot_dist <- function(x, threshold, use_boxplot = TRUE) {
if (length(x) > threshold && use_boxplot) {
Expand Down Expand Up @@ -354,8 +350,6 @@ print(average_inf_max)

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

## Solution

```r
# Add your code here ...
if (patient_average_inf > average_inf_max) {
Expand Down Expand Up @@ -490,8 +484,6 @@ update `analyze`, and then recreate all the figures with `analyze_all`.

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

## Solution

```r
analyze <- function(filename, output = NULL) {
# Plots the average, min, and max inflammation over time.
Expand Down
12 changes: 0 additions & 12 deletions episodes/05-cmdline.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,6 @@ Rscript arith.R 3 - 4

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

## Solution

```{r, engine="bash"}
cat arith.R
```
Expand All @@ -198,8 +196,6 @@ cat arith.R

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

## Solution

An error message is returned due to "invalid input."
This is likely because '\*' has a special meaning in the shell, as a wildcard.

Expand All @@ -217,8 +213,6 @@ Rscript find-pattern.R print-args

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

## Solution

```{r, engine="bash"}
cat find-pattern.R
```
Expand Down Expand Up @@ -280,8 +274,6 @@ What is the best way to test your program?

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

## Solution

```{r, engine="bash"}
cat check.R
```
Expand Down Expand Up @@ -343,8 +335,6 @@ Separately, modify the program so that if no action is specified (or an incorrec

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

## Solution

```{r, engine="bash"}
cat readings-short.R
```
Expand Down Expand Up @@ -419,8 +409,6 @@ Write a program called `line-count.R` that works like the Unix `wc` command:

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

## Solution

```{r, engine="bash"}
cat line-count.R
```
Expand Down
2 changes: 0 additions & 2 deletions episodes/06-best-practices-R.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ rm(list = ls()) # If you want to delete all the objects in the workspace and sta

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

## Solution

```{r, engine="bash"}
cat inflammation.R
```
Expand Down
12 changes: 0 additions & 12 deletions episodes/10-supp-addressing-data.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ Think about the number of rows and columns you would expect as the result.

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

## Solution

```{r select-values}
dat[1, 1]
```
Expand All @@ -98,8 +96,6 @@ What will be returned by `dat[, 2]`?

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

## Solution

```{r select-values-2}
dat[, 2]
```
Expand All @@ -126,8 +122,6 @@ Use the colon operator to index just the aneurism count data (columns 6 to 9).

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

## Solution

```{r subset-sequence}
dat[, 6:9]
```
Expand Down Expand Up @@ -291,17 +285,13 @@ plot(dat[dat$Group == 'Control', ]$BloodPressure)

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

## Solution

1. The code for such a plot:
```{r plot-logical}
plot(dat[dat$Group != 'Control', ]$BloodPressure)
```
2. In addition to
`dat$Group != 'Control'`, one could use
`dat$Group %in% c("Treatment1", "Treatment2")`.



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

Expand All @@ -326,8 +316,6 @@ Combine the addressing and assignment operations to convert all values to lowerc

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

## Solution

```r
dat[dat$Gender == 'M', ]$Gender <- 'm'
dat[dat$Gender == 'F', ]$Gender <- 'f'
Expand Down
4 changes: 0 additions & 4 deletions episodes/11-supp-read-write-csv.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ without importing the data with `stringsAsFactors=FALSE`.

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

## Solution

```r
carSpeeds <- read.csv(file = 'data/car-speeds.csv')
# Replace 'Blue' with 'Green' in cars$Color without using the stringsAsFactors
Expand Down Expand Up @@ -220,8 +218,6 @@ Is there a way to specify more than one 'string', such as "Black" and "Blue", to

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

## Solution

```r
read.csv(file = "data/inflammation-01.csv", na.strings = "0")
```
Expand Down
10 changes: 0 additions & 10 deletions episodes/12-supp-factors.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ d. `exercise <- factor(c("L", "N", "N", "I", "L"), levels = c("N", "L", "I"), or

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

## Solution

Correct solution is **d.**

```r
Expand All @@ -108,8 +106,6 @@ exercise <- factor(c("L", "N", "N", "I", "L"), levels = c("N", "L", "I"), ordere
We only expect three categories ("N", "L", "I").
We can order these from least intense to most intense, so let's use `ordered`.



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

::::::::::::::::::::::::::::::::::::::::::::::::::
Expand Down Expand Up @@ -194,8 +190,6 @@ Use the `factor()` command to modify the column `dat$Group` so that the *control

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

## Solution

```{r reordering-factors-2, fig.alt="Bar chart showing control and treatment to emphasise how the function factor() moves the control group to the last coulumn."}
dat$Group <- factor(dat$Group, levels = c("Treatment1", "Treatment2", "Control"))
barplot(table(dat$Group))
Expand Down Expand Up @@ -234,12 +228,8 @@ Why does this plot show 4 levels?

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

## Solution

`dat$Gender` has 4 levels, so the plot shows 4 levels.



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

::::::::::::::::::::::::::::::::::::::::::::::::::
Expand Down
Loading

0 comments on commit f3c1419

Please sign in to comment.