The question is: Count the number of storms per year since 1975 and write their names What I have so far is the code below:
storms %>%
count(name, year >= 1975, sort = TRUE)
I got this output:
name `year >= 1975` n
<chr> <lgl> <int>
1 Emily TRUE 217
2 Bonnie TRUE 209
3 Alberto TRUE 184
4 Claudette TRUE 180
5 Felix TRUE 178
6 Danielle TRUE 165
7 Josephine TRUE 165
8 Edouard TRUE 159
9 Gordon TRUE 158
10 Gabrielle TRUE 157
I think this is the correct output, but I just want to make sure.
CodePudding user response:
Technically, year >= 1975
part should be in filter
and not in count
. However, the data starts from 1975 so your output is correct as well. You get the same output even if you remove filter
part from the below code.
library(dplyr)
storms %>% filter(year >= 1975) %>% count(name, sort = TRUE)
# A tibble: 214 × 2
# name n
# <chr> <int>
# 1 Emily 217
# 2 Bonnie 209
# 3 Alberto 184
# 4 Claudette 180
# 5 Felix 178
# 6 Danielle 165
# 7 Josephine 165
# 8 Edouard 159
# 9 Gordon 158
#10 Gabrielle 157
# … with 204 more rows