Bryson_BIOL3000_Quiz1_2

docx

School

Abraham Baldwin Agricultural College *

*We aren’t endorsed by this school

Course

3000

Subject

Biology

Date

Feb 20, 2024

Type

docx

Pages

4

Uploaded by SuperHumanProton12926

Report
BIOL3000 Quiz1 Hannah Bryson Mon Jan 29 10:18:25 2024 EST Instructions: Please do not print the whole data as it is long, jut print head(data) to see first few rows only. Please change the name of your file with your last name as lastname_Biostat_Quiz1.Rmd . Question 1 You need to use R to answer all questions Read the builtin dataset called ‘iris’ (name it as A) in R. The data set 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. The species are Iris setosa, versicolor, and virginica. A = iris head (A) ## Sepal.Length Sepal.Width Petal.Length Petal.Width Species ## 1 5.1 3.5 1.4 0.2 setosa ## 2 4.9 3.0 1.4 0.2 setosa ## 3 4.7 3.2 1.3 0.2 setosa ## 4 4.6 3.1 1.5 0.2 setosa ## 5 5.0 3.6 1.4 0.2 setosa ## 6 5.4 3.9 1.7 0.4 setosa If any columns have missing/blank values, first replace them by NA and then list the columns that have NA values. is.na (A) <- A == colnames (A)[ apply ( is.na (A), 2 , any)] head (A) ## Sepal.Length Sepal.Width Petal.Length Petal.Width Species ## 1 5.1 3.5 1.4 0.2 setosa ## 2 4.9 3.0 1.4 0.2 setosa ## 3 4.7 3.2 1.3 0.2 setosa ## 4 4.6 3.1 1.5 0.2 setosa ## 5 5.0 3.6 1.4 0.2 setosa ## 6 5.4 3.9 1.7 0.4 setosa Add a new column named Sepal_Size in A. This new column uses the column named Sepal.Length. If Sepal.Length< 5, then the Sepal_Size is ‘small’, if Sepal.Length > 5 but smaller than 6.4, then the Sepal_Size is ‘medium’, and if the Sepal.Length > 6.4, then the Sepal_Size is ‘big’. Hint: use cut and breaks function.
B = data.frame (A) B $ Sepal_Size = cut (A $ Sepal.Length, breaks = c ( 0 , 5 , 6.4 , 20 ), labels = c ( 'small' , 'medium' , 'big' ), include.lowest = TRUE ) head (B) ## Sepal.Length Sepal.Width Petal.Length Petal.Width Species Sepal_Size ## 1 5.1 3.5 1.4 0.2 setosa medium ## 2 4.9 3.0 1.4 0.2 setosa small ## 3 4.7 3.2 1.3 0.2 setosa small ## 4 4.6 3.1 1.5 0.2 setosa small ## 5 5.0 3.6 1.4 0.2 setosa small ## 6 5.4 3.9 1.7 0.4 setosa medium * Using table function, find how many Sepal_Size are small, medium and big. Name the table as Tab1. Also, using species column and table function, find how many data are setosa, versicolor and virginica. Name the second table as Tab2. ```r Tab1=table(B$Sepal_Size) Tab1 ## ## small medium big ## 32 83 35 Tab2 = table (B $ Species) Tab2 ## ## setosa versicolor virginica ## 50 50 50 Find the average, median and variance of the column Sepal.Length. Also find the 55th percentile of the column Sepal.Width. mean (B $ Sepal.Length) ## [1] 5.843333 median (B $ Sepal.Length) ## [1] 5.8
quantile (B $ Sepal.Width, 0.55 ) ## 55% ## 3 Draw barplot of Tab1, the number of small, medium and big Sepal.Length. Write labels on x-axis, y-axis and title of the plot.Also, draw a horizontal line at the bottom of the plot barplot (Tab1, col = ( 2 : 4 ), main = 'Sepal Length' , xlab = 'Sepal Length' , ylab = '# of Sepal' ) Draw pie-chart for the Tab2, the number of different species. Also draw 3D pie chart. Make sure you use the library: library(plotrix) pie (Tab2, labels= Tab2, col= 2 : 4 , main= "Species Type" , xlab = 'Type of Species' , ylab = '# of Species' )
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
library (plotrix) pie3D (Tab2, labels= c ( 'short' , 'medium' , 'long' ), col= 2 : 6 , main= "Species Type" , radius= 2 , explode= 0.1 , labelcex= 1.0 )