1

I am working on a flight dataset using dplyr library. I am struggling by trying to group the 2 delays (WEATHER_DELAY, NAS_DELAY) based on the UNIQUE CARRIER.

That gives me :

UNIQUE_CARRIER WEATHER_DELAY NAS_DELAY
1 9E                               
2 9E                               
3 9E                                            
4 9A
5 9A                   

But I would like to get as below:

UNIQUE_CARRIER WEATHER_DELAY NAS_DELAY
1 9E                 
2 9A                        
3 9B

I wrote the following code:

complete.data %>%
filter(WEATHER_DELAY!=0, NAS_DELAY!=0) %>%
select(UNIQUE_CARRIER, WEATHER_DELAY, NAS_DELAY) %>%
group_by(UNIQUE_CARRIER) %>% 
as.data.frame() %>%
add_tally()
Shree
  • 10,835
  • 1
  • 14
  • 36
DaniB
  • 200
  • 2
  • 15
  • No idea what you need but maybe `complete.data %>% filter(blah blah) %>% count(UNIQUE_CARRIER, WEATHER_DELAY, NAS_DELAY)` – Shree Aug 12 '19 at 21:58
  • 2
    You are more likely to get help if you follow [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Shree Aug 12 '19 at 22:01
  • `tally` will count unique elements. From the sound of it, `WEATHER_DELAY` and `NAS_DELAY` need to be summed. If so, try `group_by(UNIQUE_CARRIER) %>% summarise_at(vars(WEATHER_DELAY, NAS_DELAY),sum)` – Rohit Aug 13 '19 at 06:48

0 Answers0