#> a b c d
#> 1 5.5 a TRUE 1.1
#> 2 4.5 a FALSE 1.2
#> 3 3.5 b TRUE 1.3
#> 4 2.5 b FALSE 1.4
#> 5 1.5 b TRUE 1.5
Quiz 7 Instructions
Please complete the following questions and submit a file named Quiz7.R to Gradescope for autograding.
Remember:
- Do not use global paths in you script. Instead, use setwd() interactively in the console, but do not forget to remove or comment out this part of the code before you submit. The directory structure of your machine is not the same as the one on Gradescope’s virtual machines.
- Do not destroy or overwrite any variables in your program. I check them only after I have run your entire program from start to finish.
- Check to make sure you do not have any syntax errors. Code that doesn’t run will get a very bad grade.
- Make sure to name your submission Quiz7.R
Tip: before submitting, it might help to clear all the objects from your workspace, and then source your file before you submit it. This will often uncover bugs.
Question 1
We will use iris
data frame, which is a data frame in the R package datasets
. Please use ?iris
to find more information.
[1pt] Please find the number of columns of
iris
and store the value to objectncol.iris
.[1pt] Please show the last three rows of iris and save it as
Last.3
.[1pt] Save the data where the species is “setosa” to the object named
Setosa
.[1pt] Find the column names of
iris
and save the result tocolnames.iris
.[3pts] Find the mean
Sepal.Length
of eachSpecies
. Save the results asmean.setosa
,mean.versicolor
, andmean.virginica
.
Question 2
- [1pt] Create a data frame named
df_abcd
as follows
- [1pt] Write a command that would give you the following data from
df_abcd
and save the result asdf_ac
.
#> a c
#> 1 5.5 TRUE
#> 2 4.5 FALSE
#> 3 3.5 TRUE
#> 4 2.5 FALSE
#> 5 1.5 TRUE
- [1pt] Add a new_column
e <- c(1, 1, 1, 1, 1)
todf_abcd
and save the new data frame asdf_new
. (Please note that, do not overwritedf_abcd
.)
#> a b c d e
#> 1 5.5 a TRUE 1.1 1
#> 2 4.5 a FALSE 1.2 1
#> 3 3.5 b TRUE 1.3 1
#> 4 2.5 b FALSE 1.4 1
#> 5 1.5 b TRUE 1.5 1