# Calculando a média, menor e maior valor de largura de pétala
media_petal_width <- mean(iris$Petal.Width)
menor_petal_width <- min(iris$Petal.Width)
maior_petal_width <- max(iris$Petal.Width)
# Mostrando os resultados
media_petal_width
## [1] 1.199333
menor_petal_width
## [1] 0.1
maior_petal_width
## [1] 2.5
# Usando a função tapply para calcular as estatísticas por espécie
estatisticas_por_especie <- tapply(iris$Petal.Width, iris$Species, function(x) c(media = mean(x), menor = min(x), maior = max(x)))
Espécie | Média | Menor | Maior |
---|---|---|---|
setosa | 0.246 | 0.1 | 0.6 |
versicolor | 1.326 | 1 | 1.8 |
virginica | 2.026 | 1.4 | 2.5 |
# Dividir o dispositivo gráfico em 1 linha e 1 coluna
par(mfrow = c(1, 1))
# Plotar um gráfico de dispersão para cada espécie
plot(iris$Petal.Width[iris$Species == "setosa"], col = "red", ylim = c(0, 3), xlim = c(0.5, 3), main = "Largura da Pétala por Espécie", xlab = "Espécie", ylab = "Largura da Pétala")
points(iris$Petal.Width[iris$Species == "versicolor"], col = "green")
points(iris$Petal.Width[iris$Species == "virginica"], col = "blue")
# Adicionar legenda
legend("topright", legend = levels(iris$Species), col = c("red", "green", "blue"), pch = 1)
Comentario: O gráfico mostra a distribuição da largura da pétala para cada espécie de íris. Podemos observar que a espécie “setosa” tende a ter a menor largura de pétala, enquanto a “virginica” tende a ter a maior largura.
\[ x = \frac{{-b \pm \sqrt{{b^2 - 4ac}}}}{{2a}} \]
\[ \sum_{i=1}^n \lambda x_i = \lambda \sum_{i=1}^n x_i \]
\[ \bar{x} = \frac{1}{n} \sum_{i=1}^n x_i \]