R-Beginner: How to seperate to groups

As an R beginner you need to learn how to properly ask for help, this FAQ is going to help you with that.

Having that said, this is one example of how you could solve your problem applied to the iris dataset

library(dplyr)
iris %>% 
    group_by(Species) %>% 
    summarise(Sepal.Length = mean(Sepal.Length), Sepal.Width = mean(Sepal.Width)) %>% 
    mutate(group = ifelse(Sepal.Length > Sepal.Width, "A", "B"))
#> # A tibble: 3 x 4
#>   Species    Sepal.Length Sepal.Width group
#>   <fct>             <dbl>       <dbl> <chr>
#> 1 setosa             5.01        3.43 A    
#> 2 versicolor         5.94        2.77 A    
#> 3 virginica          6.59        2.97 A

Created on 2019-01-10 by the reprex package (v0.2.1)

3 Likes