How to use dplyr for solving these questions



Dear All,

My experiment data set is similat to iris data set. if possible could you please help me to solve below questions by using dplyr and pipes.

  1. Count number of rows that have a Sepal Length higher than Sepal Length average in Species setosa and virginica
  2. The min, average, max of Petal Width by Species, order them by Species
  3. Add a new column named score that will be the sum of all quantitave variables. Then select the rows that have a score higher than 10.2


Hi @kynda

Try the following codes…

df1 = iris %>%
      filter(Species %in% c('setosa', 'virginica')) %>%
      filter(Sepal.Length > mean(Sepal.Length))
df2 = iris %>%
  group_by(Species) %>%
  summarise(min = min(Petal.Width), max = max(Petal.Width), mean = mean(Petal.Width))
df3 = iris %>%
  mutate(score = Sepal.Length + Sepal.Width + Petal.Length + Petal.Width) %>%
  filter(score > 10.2)


Thank you very much Joshi :blush: Greatly appreciate your kind help.