Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
v4 answer keys
  • Loading branch information
cxli233 authored Oct 11, 2022
1 parent d9e7a61 commit eb35771
Show file tree
Hide file tree
Showing 13 changed files with 1,814 additions and 1,790 deletions.
171 changes: 91 additions & 80 deletions answer_key/00_Very_basics_of_R_coding_key.Rmd
Original file line number Diff line number Diff line change
@@ -1,80 +1,91 @@
---
title: "Very basics of R coding"
author: "Chenxin Li"
date: "9/12/2020"
output:
html_document:
toc: yes
html_notebook:
number_sections: yes
toc: yes
toc_float: yes
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r}
library(dplyr)
```

# Exercise

Today you have learned some basic syntax of R. Now it's time for you to practice.

## Q1:

1) Insert a new code chunk
2) make this matrix

| \| 1 \| 1 \| 2 \| 2 \|
| \| 2 \| 2 \| 1 \| 2 \|
| \| 2 \| 3 \| 3 \| 4 \|
| \| 1 \| 2 \| 3 \| 4 \|

and save it as an item called my_mat2

\
3. select the 1st and 3rd rows and the 1st, 2nd and 4th columns, and save it as an item.

\
4. take the square root for each member of my_mat2, then take log2(), and lastly find the maximum value. Use the pipe syntax.\
The command for maximum is `max()`.

```{r}
my_mat2 <- rbind(
c(1, 1, 2, 2),
c(2, 2, 1, 2),
c(2, 3, 3, 4),
c(1, 2, 3, 4)
)
my_mat3 <- my_mat2[c(1,3), -3]
my_mat3
my_mat2 %>%
sqrt() %>%
log2() %>%
max()
```

## Q2:

1) Insert a code chunk
2) Use the following info to make a data frame and save it as an item called grades.\
Adel got 85 on the exam, Bren got 83 and Cecil got 93. Their letter grades are B, B, and A, respectively.\
3) Pull out the column with the scores. Use the `$` syntax.

```{r}
grades <- data.frame(
name = c("Adel", "Bren", "Cecil"),
score = c(85, 83, 93),
grade = c("B", "B", "A")
)
grades
grades$score
```
---
title: "Very basics of R coding"
author: "Chenxin Li"
date: "9/12/2020"
output:
html_document:
toc: yes
html_notebook:
number_sections: yes
toc: yes
toc_float: yes
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r}
library(dplyr)
```

# Exercise

Today you have learned some basic syntax of R. Now it's time for you to practice.

## Q1:

# Excerice

Today you have learned some basic syntax of R.
Now it's time for you to practice.

## Q1:

1. Insert a new code chunk
2. Make this matrix

| 1 | 1 | 2 | 2 |
| 2 | 2 | 1 | 2 |
| 2 | 3 | 3 | 4 |
| 1 | 2 | 3 | 4 |

and save it as an item called `my_mat2`.

3. Select the 1st and 3rd rows and the 1st, 2nd and 4th columns, and save it as an item.

4. Take the square root for each member of my_mat2, then take log2(), and lastly find the maximum value.
Use the pipe syntax. The command for maximum is `max()`.



```{r}
my_mat2 <- rbind(
c(1, 1, 2, 2),
c(2, 2, 1, 2),
c(2, 3, 3, 4),
c(1, 2, 3, 4)
)
my_mat3 <- my_mat2[c(1,3), -3]
my_mat3
my_mat2 %>%
sqrt() %>%
log2() %>%
max()
```

## Q2:

1. Use the following info to make a data frame and save it as an item called "grade".
Adel got 85 on the exam, Bren got 83, and Cecil got 93.
Their letter grades are B, B, and A, respectively.
(Hint: How many columns do you have to have?)

2. Pull out the column with the scores.
Use the `$` syntax.


```{r}
grades <- data.frame(
name = c("Adel", "Bren", "Cecil"),
score = c(85, 83, 93),
grade = c("B", "B", "A")
)
grades
grades$score
```
Loading

0 comments on commit eb35771

Please sign in to comment.