Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help with my Statatstic. It is using R-Studio. I can\'t figure any of it

ID: 3351627 • Letter: P

Question

Please help with my Statatstic. It is using R-Studio. I can't figure any of it out, please post the code you would use any an explaination so I can attempt my other homework.

(3) The famous data set iris which gives the measurements in centimeters of the variables sepal length and width and petal length and width, respectively, for 50 flowers from each of 3 species of iris is available in R. Type iris directly to see what it looks like.

(a) Selecting the observations (rows) whose Species are versicolor.

(b) Selecting the observations whose Speices are either versicolor or virginica.

(c) Selecting the observations whose Sepal.Width are greater than 2.9 but less than 3.5.

(d) Combine the data frames you got in part (a) and part (c) to one data frame.
(e) You may have some duplicated observations in the data frame you obtained in part (d). Use the command ?unique to learn the usage of the function unique and then

utilize it to remove duplicated rows from the data frame you obtained in part (d).

Explanation / Answer

Please note that all the explanation/comments are written following #sign.

library(datasets)
data(iris)

#Make a copy of the dataset iris. We will be working on this copy
iris1 = iris

#Top 6 rows of the dataset
head(iris1)
#Variable names
names(iris1)
#summary statistics of the dataset
summary(iris1)


#(a) Selecting the observations (rows) whose Species are versicolor.
#We will be using the package to filter out rows from our data frame
library(dplyr)
versicolor <- filter(iris, Species == "versicolor")
head(versicolor)

#(b) Selecting the observations whose Speices are either versicolor or virginica.
#Observations whose Species is versicolor or virginica is stored in the dataframe two
two <- filter(iris, Species == c("versicolor","virginica"))
summary(two)

#(c) Selecting the observations whose Sepal.Width are greater than 2.9 but less than 3.5.
#Observation whose Sepal Widhth lies in rage [3,3,4] are stored in the data frame three
three = filter(iris, Sepal.Width > 2.9,Sepal.Width < 3.5)
head(three)

#(d) Combine the data frames you got in part (a) and part (c) to one data frame.
#Data frames versicolour and three anre merged and stored in the dataframe four.
#Vericolour has 50 rows, while three has 68 rows. Our final dataframe 'four' has 118 rows
four=rbind(versicolor,three)
head(four)

#(e) You may have some duplicated observations in the data frame you obtained in part (d).
#Duplicate rows are removed from our dataframe using the unique command. Uni dataframe has 102 unique rows
Uni = unique(four)
head(Uni)