Skip to content

Commit

Permalink
differences for PR #620
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Apr 19, 2024
1 parent f85a887 commit e7d9bc2
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 213 deletions.
22 changes: 0 additions & 22 deletions 01-starting-with-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,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 @@ -146,8 +142,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 @@ -366,8 +360,6 @@ age <- age - 20

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

## Solution

```r
mass <- 47.5
age <- 122
Expand Down Expand Up @@ -827,8 +819,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 @@ -857,8 +847,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 @@ -880,8 +868,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 @@ -916,8 +902,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 @@ -987,8 +971,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 @@ -998,8 +980,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 @@ -1014,5 +994,3 @@ plot(sd_day_inflammation)
- Use `plot` to create simple visualizations.

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


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

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

## Solution

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

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

## Solution

```r
edges <- function(v) {
first <- v[1]
Expand Down Expand Up @@ -268,8 +264,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 @@ -535,8 +529,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 @@ -567,8 +559,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 @@ -775,8 +765,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 03-loops-R.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,6 @@ print_N(3)

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

## Solution

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

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

## Solution

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

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

## Solution

```r
expo <- function(base, power) {
result <- 1
Expand Down Expand Up @@ -525,8 +519,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 04-cond.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,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 @@ -385,8 +383,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 @@ -438,8 +434,6 @@ print(average_inf_max)

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

## Solution

```r
# Add your code here ...
if (patient_average_inf > average_inf_max) {
Expand Down Expand Up @@ -605,8 +599,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 05-cmdline.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,6 @@ Rscript arith.R 3 - 4

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

## Solution


```bash
cat arith.R
Expand Down Expand Up @@ -387,8 +385,6 @@ main()

::::::::::::::: 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 @@ -412,8 +408,6 @@ print-args.R

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

## Solution


```bash
cat find-pattern.R
Expand Down Expand Up @@ -531,8 +525,6 @@ What is the best way to test your program?

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

## Solution


```bash
cat check.R
Expand Down Expand Up @@ -674,8 +666,6 @@ Separately, modify the program so that if no action is specified (or an incorrec

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

## Solution


```bash
cat readings-short.R
Expand Down Expand Up @@ -867,8 +857,6 @@ Write a program called `line-count.R` that works like the Unix `wc` command:

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

## Solution


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

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

## Solution


```bash
cat inflammation.R
Expand Down
12 changes: 0 additions & 12 deletions 10-supp-addressing-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ Think about the number of rows and columns you would expect as the result.

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

## Solution


```r
dat[1, 1]
Expand All @@ -141,8 +139,6 @@ What will be returned by `dat[, 2]`?

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

## Solution


```r
dat[, 2]
Expand Down Expand Up @@ -184,8 +180,6 @@ Use the colon operator to index just the aneurism count data (columns 6 to 9).

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

## Solution


```r
dat[, 6:9]
Expand Down Expand Up @@ -591,8 +585,6 @@ plot(dat[dat$Group == 'Control', ]$BloodPressure)

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

## Solution

1. The code for such a plot:

```r
Expand All @@ -603,8 +595,6 @@ plot(dat[dat$Group == 'Control', ]$BloodPressure)
2. In addition to
`dat$Group != 'Control'`, one could use
`dat$Group %in% c("Treatment1", "Treatment2")`.



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

Expand Down Expand Up @@ -634,8 +624,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 11-supp-read-write-csv.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,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 @@ -335,8 +333,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
Loading

0 comments on commit e7d9bc2

Please sign in to comment.