[R] How to group by and get distinct rows of of grouped rows based on certain criteria

Satish Vadlamani satish.vadlamani at gmail.com
Thu Jul 14 21:43:49 CEST 2016


Hello All:
I would like to get your help on the following problem.

I have the following data and the first row is the header. Spaces are not
important.
I want to find out distinct combinations of ATP Group and Business Event
(these are the field names that you can see in the data below) that have
the Category EQ (Category is the third field) and those that do not have
the category EQ. In the example below, the combinations 02/A and 02/B have
EQ and the combination ZM/A does not.

If I have a larger file, how to get to this answer?

What did I try (with dplyr)?

# I know that the below is not correct and not giving desired results
file1_1 <- file1  %>% group_by(ATP.Group,Business.Event) %>%
filter(Category != "EQ") %>% distinct(ATP.Group,Business.Event)
# for some reason, I have to convert to data.frame to print the data
correctly
file1_1 <- as.data.frame(file1_1)
file1_1


*Data shown below*
|ATP Group|Business Event|Category|
|02       |A             |AC      |
|02       |A             |AD      |
|02       |A             |EQ      |
|ZM       |A             |AU      |
|ZM       |A             |AV      |
|ZM       |A             |AW      |
|02       |B             |AC      |
|02       |B             |AY      |
|02       |B             |EQ      |

-- 

Satish Vadlamani

	[[alternative HTML version deleted]]



More information about the R-help mailing list