-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v4 answer keys
- Loading branch information
Showing
13 changed files
with
1,814 additions
and
1,790 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
Oops, something went wrong.