Question
I need the R code for the following problem both part a and b. I have already loaded in the EX3.ABALONE Load in the `EX3.ABALONE`
I need the R code for the following problem both part a and b. I have already loaded in the EX3.ABALONE
Load in the `EX3.ABALONE` dataframe from `regclass`. This keeps track of physical characteristics of abalone (a shelled sea creature often eaten as a delicacy), one of which is `Rings` (which turns out to be a good proxy for age much like tree rings tell us the age of a tree).
Create a dataframe called `ABSUM` that has two columns: one named `Rings` and one named `AvgWeight`. When defining the dataframe with `data.frame` (you might have to refer back to the Unit 1 notes to see how this is done):
* let the elements of the `Rings` column of `ABSUM` be the unique values contained in the `Rings` column in `EX3.ABALONE` sorted from smallest (3) to largest (27) * use the `rep()` command to define the elements of the `AvgWeight` column of `ABSUM` with all 0s (the number of 0s needs to be the number of unique values in the `Rings` column of `EX3.ABALONE`).
a. Confirm that `head(ABSUM,3)` and `tail(ABSUM,3)` are as follows (i.e. print those the screen).
b. Use a `for` loop to define the elements of the `AvgWeight` column of `ABSUM` one by one. Specifically, let the value in the `i`-th element of this column equal to the average value of `Whole.Weight` in the `EX3.ABALONE` dataframe among rows with the corresponding value for `Rings`.
For example, the first value in the `AvgWeight` column will be the average weight of all abalone with 3 rings (0.02566667), since 3 is the value of `Rings` in the first row. The second value in the `AvgWeight` column will be the average weight of all abalone with 4 rings (0.05758333), since 4 is the value of `Rings` in the second row. The last value in the `AvgWeight` column will be the average weight of all abalone with 27 rings (2.183500), since 27 is the value of `Rings` in the last row.
Print to the screen `head(ABSUM)`, `tail(ABSUM)`, and `summary(ABSUM)` as well as a scatterplot showing the relationship between `AvgWeight` (vertical axis) and `Rings` (horizontal axis). Remember BAS 320! The syntax is something like `plot(y~x,data=DATA)`. The first 3 and last 3 rows of `ABSUM` are provided as a sanity check.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started