2  Inclass1

Author

Melih Can Akgül

Published

October 26, 2023

library(dplyr)
versicolor <- iris %>%
  select(Species,Petal.Length ) %>% filter(Species=="versicolor")
head(versicolor,10)
      Species Petal.Length
1  versicolor          4.7
2  versicolor          4.5
3  versicolor          4.9
4  versicolor          4.0
5  versicolor          4.6
6  versicolor          4.5
7  versicolor          4.7
8  versicolor          3.3
9  versicolor          4.6
10 versicolor          3.9

This code block creates a subset by selecting the “Species” and “Petal.Length” columns of flowers of type “versicolor” from the “iris” dataset and filtering observations of this type.

library(dplyr)
azdrate<-iris %>%
   mutate(azd = Petal.Length / ((Petal.Length / 50)^2)) %>%
    arrange(desc(azd))
head(azdrate,10)
   Sepal.Length Sepal.Width Petal.Length Petal.Width Species      azd
1           4.6         3.6          1.0         0.2  setosa 2500.000
2           4.3         3.0          1.1         0.1  setosa 2272.727
3           5.8         4.0          1.2         0.2  setosa 2083.333
4           5.0         3.2          1.2         0.2  setosa 2083.333
5           4.7         3.2          1.3         0.2  setosa 1923.077
6           5.4         3.9          1.3         0.4  setosa 1923.077
7           5.5         3.5          1.3         0.2  setosa 1923.077
8           4.4         3.0          1.3         0.2  setosa 1923.077
9           5.0         3.5          1.3         0.3  setosa 1923.077
10          4.5         2.3          1.3         0.3  setosa 1923.077

This code divides Petal.Length by 50, squares the result, and divides again by Petal.Length. The result of this operation is assigned to the azd column. It then sorts the dataset in descending order based on the created azd column. That is, it organizes the data set so that the observations with the highest azd value are at the top.