Skip to content

Commit

Permalink
hw update
Browse files Browse the repository at this point in the history
  • Loading branch information
jmledford3115 committed Mar 3, 2024
1 parent 8e4a556 commit ebde5f5
Show file tree
Hide file tree
Showing 25 changed files with 2,965 additions and 65 deletions.
4 changes: 2 additions & 2 deletions homework/hw1.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<meta name="author" content="Joel Ledford" />

<meta name="date" content="2024-02-03" />
<meta name="date" content="2024-03-03" />

<title>Homework 1</title>

Expand Down Expand Up @@ -376,7 +376,7 @@

<h1 class="title toc-ignore">Homework 1</h1>
<h4 class="author">Joel Ledford</h4>
<h4 class="date">2024-02-03</h4>
<h4 class="date">2024-03-03</h4>

</div>

Expand Down
113 changes: 113 additions & 0 deletions homework/hw1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
---
title: "Homework 1"
author: "Joel Ledford"
date: "2024-03-03"
output:
html_document:
theme: spacelab
keep_md: yes
---

## Instructions
Answer the following questions and complete the exercises in RMarkdown. Please embed all of your code and push your final work to your repository. Your final lab report should be organized, clean, and run free from errors. Remember, you must remove the `#` for the included code chunks to run. Be sure to add your name to the author header above.

Make sure to use the formatting conventions of RMarkdown to make your report neat and clean!

**1. Please complete the [class survey](https://forms.gle/AHHXd3aobaAdkkFg9) if you have not already done so.**

**2. What is the difference between R and RStudio? What is GitHub and why is it useful to programmers?**
R is an open-source [programming language](https://www.r-project.org/about.html) that is focused on statistics and graphics. RStudio is a GUI that makes interacting with R easier.

Github is a website where programmers store and share code in repositories. It is also a place where scientists upload code such that the calculations they make are open and repeatable.

**3. Navigate to my [BIS15L](https://github.com/jmledford3115/BIS15LW2021_jledford) repository on GitHub. Notice that near the bottom there is a nice, clean description of the repository. You want this on your repository! It is built by making edits to the `README.md` file using the RMarkdown conventions. Edit your repository's `README.md` file so that you have a clean informative description, including your email address. Be creative! You don't need to just copy mine. There are lots of examples online.**

**4. Calculate the following expressions. Be sure to include each one in a separate code chunk.**

```r
5 - 3 * 2
```

```
## [1] -1
```


```r
8 / 2 ** 2
```

```
## [1] 2
```

**5. Did any of the results in #4 surprise you? Write two programs that calculate each expression such that the result for the first example is 4 and the second example is 16.**
I notice that order of operations for mathematical expression applies.

```r
(5 - 3) * 2
```

```
## [1] 4
```


```r
(8 / 2) * 2
```

```
## [1] 8
```

**6. `Objects` in R are a way in which we can store data or operations. We will talk more about objects next week. For now, make a new object `pi` as 3.14159265359 by running the following code chunk. You should now see the object `pi` in the environment window in the top right.**

```r
pi <- 3.14159265359
```

**7. Let's say we want to multiply `pi` by 2. Using the same arithmetic principles that we just learned, write a code chunk that performs this operation using the object we created.**


```r
pi*2
```

```
## [1] 6.283185
```

**8. In order to get help with any command in R, just type a `?` in front the command of interest. Practice this by running the following code chunk.**

```r
?mean
```

**9. Let's calculate the mean for the numbers 2, 8, 6, 4, 9, 10. I have built an object `x` for you below so all you need to do is run the first code chunk and then create a second code chunk that shows the calculation. Give it a try!**

```r
x <- c(2, 8, 6, 6, 7, 4, 9, 9, 9, 10)
```


```r
mean(x)
```

```
## [1] 7
```

**10. Repeat the procedure above, but this time calculate the median.**

```r
median(x)
```

```
## [1] 7.5
```

## Push your final code to GitHub!
Please be sure that you check the `keep md` file in the knit preferences.
2 changes: 1 addition & 1 deletion homework/hw10.Rmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Homework 10"
author: "Please Add Your Name Here"
author: "Joel Ledford"
date: "`r Sys.Date()`"
output:
html_document:
Expand Down
18 changes: 9 additions & 9 deletions homework/hw10.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion homework/hw11.Rmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Lab 11 Homework"
author: "Please Add Your Name Here"
author: "Joel Ledford"
date: "`r Sys.Date()`"
output:
html_document:
Expand Down
16 changes: 8 additions & 8 deletions homework/hw11.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions homework/hw12.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<meta name="author" content="Please Add Your Name Here" />

<meta name="date" content="2024-02-28" />
<meta name="date" content="2024-03-03" />

<title>Homework 12</title>

Expand Down Expand Up @@ -376,7 +376,7 @@

<h1 class="title toc-ignore">Homework 12</h1>
<h4 class="author">Please Add Your Name Here</h4>
<h4 class="date">2024-02-28</h4>
<h4 class="date">2024-03-03</h4>

</div>

Expand Down
4 changes: 2 additions & 2 deletions homework/hw2.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<meta name="author" content="Joel Ledford" />

<meta name="date" content="2024-02-03" />
<meta name="date" content="2024-03-03" />

<title>Homework 2</title>

Expand Down Expand Up @@ -376,7 +376,7 @@

<h1 class="title toc-ignore">Homework 2</h1>
<h4 class="author">Joel Ledford</h4>
<h4 class="date">2024-02-03</h4>
<h4 class="date">2024-03-03</h4>

</div>

Expand Down
152 changes: 152 additions & 0 deletions homework/hw2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
---
title: "Homework 2"
author: "Joel Ledford"
date: "2024-03-03"
output:
html_document:
theme: spacelab
keep_md: yes
---

## Instructions
Answer the following questions and complete the exercises in RMarkdown. Please embed all of your code and push your final work to your repository. Your final lab report should be organized, clean, and run free from errors. Remember, you must remove the `#` for the included code chunks to run. Be sure to add your name to the author header above.

Make sure to use the formatting conventions of RMarkdown to make your report neat and clean!

1. What is a vector in R?
_A vector in R is a type of data structure that is ordered and consists of elements, usually of the same class._

2. What is a data matrix in R?
_A data matrix is a series of stacked vectors arranged like a data table._

3. Below are data collected by three scientists (Jill, Steve, Susan in order) measuring temperatures of eight hot springs. Run this code chunk to create the vectors.

```r
spring_1 <- c(36.25, 35.40, 35.30)
spring_2 <- c(35.15, 35.35, 33.35)
spring_3 <- c(30.70, 29.65, 29.20)
spring_4 <- c(39.70, 40.05, 38.65)
spring_5 <- c(31.85, 31.40, 29.30)
spring_6 <- c(30.20, 30.65, 29.75)
spring_7 <- c(32.90, 32.50, 32.80)
spring_8 <- c(36.80, 36.45, 33.15)
```

4. Build a data matrix that has the springs as rows and the columns as scientists.

```r
springs <- c(spring_1, spring_2, spring_3, spring_4, spring_5, spring_6, spring_7, spring_8)
springs
```

```
## [1] 36.25 35.40 35.30 35.15 35.35 33.35 30.70 29.65 29.20 39.70 40.05 38.65
## [13] 31.85 31.40 29.30 30.20 30.65 29.75 32.90 32.50 32.80 36.80 36.45 33.15
```


```r
springs_matrix <- matrix(springs, nrow=8, byrow = T)
springs_matrix
```

```
## [,1] [,2] [,3]
## [1,] 36.25 35.40 35.30
## [2,] 35.15 35.35 33.35
## [3,] 30.70 29.65 29.20
## [4,] 39.70 40.05 38.65
## [5,] 31.85 31.40 29.30
## [6,] 30.20 30.65 29.75
## [7,] 32.90 32.50 32.80
## [8,] 36.80 36.45 33.15
```

5. The names of the springs are 1.Bluebell Spring, 2.Opal Spring, 3.Riverside Spring, 4.Too Hot Spring, 5.Mystery Spring, 6.Emerald Spring, 7.Black Spring, 8.Pearl Spring. Name the rows and columns in the data matrix. Start by making two new vectors with the names, then use `colnames()` and `rownames()` to name the columns and rows.

```r
scientists <- c("Jill", "Steve", "Susan")
```


```r
springs <- c("Bluebell Spring", "Opal Spring", "Riverside Spring", "Too Hot Spring", "Mystery Spring", "Emerald Spring", "Black Spring", "Pearl Spring")
```


```r
colnames(springs_matrix) <- scientists
rownames(springs_matrix) <- springs
springs_matrix
```

```
## Jill Steve Susan
## Bluebell Spring 36.25 35.40 35.30
## Opal Spring 35.15 35.35 33.35
## Riverside Spring 30.70 29.65 29.20
## Too Hot Spring 39.70 40.05 38.65
## Mystery Spring 31.85 31.40 29.30
## Emerald Spring 30.20 30.65 29.75
## Black Spring 32.90 32.50 32.80
## Pearl Spring 36.80 36.45 33.15
```

6. Calculate the mean temperature of all eight springs.

```r
mean_vector <- rowMeans(springs_matrix)
mean_vector
```

```
## Bluebell Spring Opal Spring Riverside Spring Too Hot Spring
## 35.65000 34.61667 29.85000 39.46667
## Mystery Spring Emerald Spring Black Spring Pearl Spring
## 30.85000 30.20000 32.73333 35.46667
```

7. Add this as a new column in the data matrix.

```r
springs_matrix2 <- cbind(springs_matrix, mean_vector)
springs_matrix2
```

```
## Jill Steve Susan mean_vector
## Bluebell Spring 36.25 35.40 35.30 35.65000
## Opal Spring 35.15 35.35 33.35 34.61667
## Riverside Spring 30.70 29.65 29.20 29.85000
## Too Hot Spring 39.70 40.05 38.65 39.46667
## Mystery Spring 31.85 31.40 29.30 30.85000
## Emerald Spring 30.20 30.65 29.75 30.20000
## Black Spring 32.90 32.50 32.80 32.73333
## Pearl Spring 36.80 36.45 33.15 35.46667
```

8. Show Susan's value for Opal Spring only.

```r
springs_matrix2[2,3]
```

```
## [1] 33.35
```

9. Calculate the mean for Jill's column only.

```r
Jill <- springs_matrix2[ ,1]
mean(Jill)
```

```
## [1] 34.19375
```

10. Use the data matrix to perform one calculation or operation of your interest.

## Push your final code to GitHub!
Please be sure that you check the `keep md` file in the knit preferences.
4 changes: 2 additions & 2 deletions homework/hw3.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<meta name="author" content="Joel Ledford" />

<meta name="date" content="2024-02-03" />
<meta name="date" content="2024-03-03" />

<title>Homework 3</title>

Expand Down Expand Up @@ -376,7 +376,7 @@

<h1 class="title toc-ignore">Homework 3</h1>
<h4 class="author">Joel Ledford</h4>
<h4 class="date">2024-02-03</h4>
<h4 class="date">2024-03-03</h4>

</div>

Expand Down
Loading

0 comments on commit ebde5f5

Please sign in to comment.