act3_tonyzhang
pdf
keyboard_arrow_up
School
Pennsylvania State University *
*We aren’t endorsed by this school
Course
184
Subject
Mathematics
Date
Apr 3, 2024
Type
Pages
6
Uploaded by MajorMaskMule13
Assignment Title
Tony Zhang
02/06/2024
Use Headers
Use headers to organize your document. The first level heading is denoted by a single pound sign/hash tag,
#
. Each new
problem/exercise should get a Level 1 Heading. For subparts, increase the heading level by increasing the number of hash
tags.
For example, if Problem 1 has Parts A (with parts i-ii) and B, your R Markdown file would have the following:
# Problem 1
[text]
## Part A
[text]
### Part i
[text]
### Part ii
[text]
## Part B
[text]
Code
There are two ways to include code in your document: inline and chunks.
Inline Code
To add inline code, you’ll need to type a grave mark ‘ (the key to the left of the numeral 1 key), followed by a lower case r,
a space, then the
R
commands you wish to r and a final grave. For example ‘
r nrow(dataFrame)
‘ would return the number
of rows in the data frame named “dataFrame”.
Inline code is good for calling values you have stored and doing quick calculations on those values. Inline code will not be
added to the Code Appendix.
Code Chunks
For more complicated code such as data manipulation and cleaning, creating graphs or tables, model building and testing,
you’ll want to use code chunks. You can do this in two ways:
•
You can click the Insert button found just above the RStudio’s editor page (has an icon of a white circle with a green
plus sign and a green square with a white C) and selecting R from the drop down list.
•
You can create your own code chunk by typing three graves in a row, returning twice and typing three more graves.
You should see the editor become shaded gray for those three lines. You will want to write your code starting in the
middle blank line. In the first line, right after the third grave, you’ll want to set options including coding language and
chunk name as well as other options (e.g., figure caption and dimensions).
1
Mathematics
To type mathematical formulas, you will need to use LaTeX commands. For inline mathematics you’ll need to enclose your
mathematical expression in \( and \). For display math (on it’s own line and centered), enclose the expression in \[ and \].
The following code will automatically create your Code Appendix by grabbing all of your code chunks and writing that code
here. Take a moment to look through the appendix and make sure that your code is fully readable. Use comments in your
code to help create markers for what code does what.
2
Code Appendix
# This template file is based off of a template created by Alex Hayes
# https://github.com/alexpghayes/rmarkdown_homework_template
# Setting Document Options
knitr
::
opts_chunk
$
set
(
echo =
TRUE
,
warning =
FALSE
,
message =
FALSE
,
fig.align =
"center"
)
library
(dplyr)
data
(
"ChickWeight"
)
unique_diets
<-
unique
(ChickWeight
$
Diet)
unique_diets
num_unique_chicks
<-
ChickWeight
%>%
summarise
(
num_unique_chicks =
n_distinct
(Chick))
max_min_weights
<-
ChickWeight
%>%
summarise
(
max_weight =
max
(weight),
min_weight =
min
(weight))
measurements_per_chick
<-
ChickWeight
%>%
group_by
(Chick)
%>%
summarise
(
num_measurements =
n
())
measurements_per_chick
avg_weight_per_chick
<-
ChickWeight
%>%
group_by
(Chick)
%>%
summarise
(
avg_weight =
mean
(weight))
avg_weight_per_chick
chicks_per_diet
<-
ChickWeight
%>%
group_by
(Diet)
%>%
summarise
(
num_chicks =
n_distinct
(Chick))
chicks_per_diet
measurements_per_diet
<-
ChickWeight
%>%
group_by
(Diet)
%>%
summarise
(
num_measurements =
n
())
measurements_per_diet
avg_range_weights_per_diet
<-
ChickWeight
%>%
group_by
(Diet)
%>%
summarise
(
avg_weight =
mean
(weight),
range_weight =
max
(weight)
-
min
(weight))
avg_range_weights_per_diet
mean_weight_per_diet_days
<-
ChickWeight
%>%
group_by
(Diet, Time)
%>%
summarise
(
mean_weight =
mean
(weight))
mean_weight_per_diet_days
Problem 1
Part a
The ChickWeight dataset contains data on the weight of chicks over time under different diets. There are 578 entries in the
table and 4 different columns (weight, Time, Chick, Diet). I used install.packages(), library(), and data() commands to load
3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
the ChickWeight dataset.
Part b
unique_diets
<-
unique
(ChickWeight
$
Diet)
unique_diets
## [1] 1 2 3 4
## Levels: 1 2 3 4
The unique values in the Diet variable are (1, 2, 3, 4).
Part c
num_unique_chicks
<-
ChickWeight
%>%
summarise
(
num_unique_chicks =
n_distinct
(Chick))
max_min_weights
<-
ChickWeight
%>%
summarise
(
max_weight =
max
(weight),
min_weight =
min
(weight))
Part d
measurements_per_chick
<-
ChickWeight
%>%
group_by
(Chick)
%>%
summarise
(
num_measurements =
n
())
measurements_per_chick
## # A tibble: 50 x 2
##
Chick num_measurements
##
<ord>
<int>
##
1 18
2
##
2 16
7
##
3 15
8
##
4 13
12
##
5 9
12
##
6 20
12
##
7 10
12
##
8 8
11
##
9 17
12
## 10 19
12
## # i 40 more rows
avg_weight_per_chick
<-
ChickWeight
%>%
group_by
(Chick)
%>%
summarise
(
avg_weight =
mean
(weight))
avg_weight_per_chick
## # A tibble: 50 x 2
##
Chick avg_weight
##
<ord>
<dbl>
##
1 18
37
##
2 16
49.7
##
3 15
60.1
##
4 13
67.8
4
##
5 9
81.2
##
6 20
78.4
##
7 10
83.1
##
8 8
92
##
9 17
92.5
## 10 19
86.8
## # i 40 more rows
chicks_per_diet
<-
ChickWeight
%>%
group_by
(Diet)
%>%
summarise
(
num_chicks =
n_distinct
(Chick))
chicks_per_diet
## # A tibble: 4 x 2
##
Diet
num_chicks
##
<fct>
<int>
## 1 1
20
## 2 2
10
## 3 3
10
## 4 4
10
measurements_per_diet
<-
ChickWeight
%>%
group_by
(Diet)
%>%
summarise
(
num_measurements =
n
())
measurements_per_diet
## # A tibble: 4 x 2
##
Diet
num_measurements
##
<fct>
<int>
## 1 1
220
## 2 2
120
## 3 3
120
## 4 4
118
avg_range_weights_per_diet
<-
ChickWeight
%>%
group_by
(Diet)
%>%
summarise
(
avg_weight =
mean
(weight),
range_weight =
max
(weight)
-
min
(weight))
avg_range_weights_per_diet
## # A tibble: 4 x 3
##
Diet
avg_weight range_weight
##
<fct>
<dbl>
<dbl>
## 1 1
103.
270
## 2 2
123.
292
## 3 3
143.
334
## 4 4
135.
283
mean_weight_per_diet_days
<-
ChickWeight
%>%
group_by
(Diet, Time)
%>%
summarise
(
mean_weight =
mean
(weight))
mean_weight_per_diet_days
## # A tibble: 48 x 3
## # Groups:
Diet [4]
##
Diet
Time mean_weight
##
<fct> <dbl>
<dbl>
##
1 1
0
41.4
5
##
2 1
2
47.2
##
3 1
4
56.5
##
4 1
6
66.8
##
5 1
8
79.7
##
6 1
10
93.1
##
7 1
12
109.
##
8 1
14
123.
##
9 1
16
145.
## 10 1
18
159.
## # i 38 more rows
6
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help