R Markdown

My first Script 2024-05-27

Simple analysis of the iris dataset

’’’{r} # Print a message indicating the start of the file reading process print(“Reading File”)

Read the iris dataset from a CSV file, treating strings as factors

iris <- read.csv(“iris.csv”, stringsAsFactors = TRUE)

Calculate and print the mean of the Sepal Width

print(“Mean”) mean_sepal_width <- mean(iris$Sepal.Width) print(mean_sepal_width)

Calculate and print the standard deviation of the Sepal Width

print(“s.d”) sd_sepal_width <- sd(iris$Sepal.Width) print(sd_sepal_width)

Calculate and print the range of the Sepal Width

print(“range”) range_sepal_width <- range(iris$Sepal.Width) print(range_sepal_width)

Plot the Petal Length against Petal Width, using different colors for each species

plot(iris\(Petal.Length, iris\)Petal.Width, pch=16, col=as.factor(iris$Species), xlab=“Petal Length”, ylab=“Petal Width”, main=“Petal Dimensions by Species”)

Estimate the petal area using the formula for the area of an ellipse

iris\(Petal.Area <- pi * iris\)Petal.Length * iris$Petal.Width

Plot the estimated petal area, using different colors for each species

plot(iris\(Petal.Area, pch=16, col=as.factor(iris\)Species), xlab=“Index”, ylab=“Petal Area”, main=“Petal Area by Species”)

Write the modified iris dataset to a new CSV file without row names

write.csv(iris, “iris2.csv”, row.names = FALSE) print(“Modified dataset saved as iris2.csv”) ’’’