I have a dataframe withs ports and n voyages:
library(dplyr)
ports <- c("Nantes", "Bordeaux", "Liverpool", "Bayonne", "Brest", "Bristol")
n <- c(47, 78, 45, 1, 1, 2)
ports_n <- data.frame(ports, n)
Here is my output :
ports n
1 Nantes 47
2 Bordeaux 78
3 Liverpool 45
4 Bayonne 1
5 Brest 1
6 Bristol 2
What I want : group all the values <= 2 in a group called "others" with dplyr package.
Expected output :
ports n
1 Nantes 47
2 Bordeaux 78
3 Liverpool 45
4 Others 4
What I tried :
top_ports <- ports_n %>%
filter(n>1)
minor_ports <- ports_n %>%
filter(n <=2)