CÂU 1:

# Su dung bo du lieu iris
data(iris)
# Lay cot Sepal.Width
sw <- iris$Sepal.Width
# Tinh trung binh
mean_sw <- mean(sw)
# Tinh phuong sai
var_sw <- var(sw)
# Tinh do lech chuan
sd_sw <- sd(sw)
# Hien thi ket qua
mean_sw
## [1] 3.057333
var_sw
## [1] 0.1899794
sd_sw
## [1] 0.4358663
# Nap thu vien ggplot2
library(ggplot2)

# Ve bieu do scatter
ggplot(iris, aes(x = Petal.Length,
                 y = Petal.Width,
                 color = Species)) +
  geom_point(size = 2) +
  labs(title = "Scatter plot Petal.Length va Petal.Width",
       x = "Petal Length",
       y = "Petal Width") +
  theme_minimal()

CÂU 2:

data(iris)
write.csv(iris, "iris.csv", row.names = FALSE)
import pandas as pd

df = pd.read_csv("iris.csv")

total_by_species = (
df.groupby("Species")[["Sepal.Length", "Sepal.Width"]]
.sum()
.reset_index()
)

total_by_species
##       Species  Sepal.Length  Sepal.Width
## 0      setosa         250.3        171.4
## 1  versicolor         296.8        138.5
## 2   virginica         329.4        148.7