I currently have a data frame in R that looks like this
V1 V2 V3 V4 Animal
1 2 2 3 5 Dog
2 2 4 3 1 Dog
3 1 4 1 1 Cat
4 5 5 1 3 Cat
5 5 5 5 3 Bird
6 3 3 3 4 Bird
Where I used group_by to group the data by animal. I would like to created a new column V6 that takes column V4, divides the lower values by the higher values, and if that value is smaller than .5 have V6= A and ifelse has V6 = b.. Is there a way do to that using the mutate function with conditional statement in R? The actual data frame is much larger so I would rather not have to do it manually. This is what I would like the final data frame to look like
V1 V2 V3 V4 Animal V6
1 2 2 3 5 Dog A
2 2 4 3 1 Dog A
3 1 4 1 1 Cat A
4 5 5 1 3 Cat A
5 5 5 5 3 Bird B
6 3 3 3 4 Bird B
And this is what I have started with
df %>% mutate(Type = if(min/max < .5)A,
ifelse, B)
But I know this is not correct. Thank you!
V4wheremin = 1andmax = 5you obtain for all values ofV6 = 1/5which is 0.2 and so alwaysA. Please explain well. Maybe you meant from V1 to V4 - SabDeMminandmaxvalue part is not clear - akrundat %>% group_by(Animal) %>% mutate(new = ifelse(min(V4)/max(V4) < 0.5, "A", "B"))- Veerendra Gadekar