mã đề: 48785

Bài 1:

data(iris)

sepal_width <- iris$Sepal.Width

trung binh - mean

mean_sw <- mean(sepal_width)

phuong sai - variance

var_sw <- var(sepal_width)

độ lệch chuẩn - standard deviation

sd_sw <- sd(sepal_width)

ket qua

data.frame(
  Mean = mean_sw,
  Variance = var_sw,
  Std_Deviation = sd_sw
)
##       Mean  Variance Std_Deviation
## 1 3.057333 0.1899794     0.4358663

plot

library(ggplot2)
ggplot(
  data=iris,
  mapping = aes(
    x=Petal.Length,
    y=Petal.Width,
    color = Species)
)+
  geom_point(size=2)+
  labs(
    title = "scatter plot of pedal length vs pedal width",
    x="pedal length",
    y="pedal width",
    color="Species")+
  theme_minimal()

# Bai 2:

write.csv(iris, "iris.csv", row.names = FALSE)



library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
total_by_species <- iris %>%
  group_by(Species) %>%
  summarise(
    total_sepal_length = sum(Sepal.Length),
    total_sepal_width  = sum(Sepal.Width)
  )


write.csv(total_by_species, "total_by_species.csv", row.names = FALSE)