I am trying to delete the rows in my dataset that has a U.S state name. I hope there is a way to input into the code without typing all 50 of them. Below I am sharing the big picture and where I would like to have these states input.
cshealthpredictors %>%
filter(!region %in% c("Alabama", "Arkansas" ,"Missouri","Texas","Georgia"))
CodePudding user response:
As @Ritchie mentions in the comments there's a built in for that in base R.
state.name
#> [1] "Alabama" "Alaska" "Arizona" "Arkansas"
#> [5] "California" "Colorado" "Connecticut" "Delaware"
#> [9] "Florida" "Georgia" "Hawaii" "Idaho"
#> [13] "Illinois" "Indiana" "Iowa" "Kansas"
#> [17] "Kentucky" "Louisiana" "Maine" "Maryland"
#> [21] "Massachusetts" "Michigan" "Minnesota" "Mississippi"
#> [25] "Missouri" "Montana" "Nebraska" "Nevada"
#> [29] "New Hampshire" "New Jersey" "New Mexico" "New York"
#> [33] "North Carolina" "North Dakota" "Ohio" "Oklahoma"
#> [37] "Oregon" "Pennsylvania" "Rhode Island" "South Carolina"
#> [41] "South Dakota" "Tennessee" "Texas" "Utah"
#> [45] "Vermont" "Virginia" "Washington" "West Virginia"
#> [49] "Wisconsin" "Wyoming"
Created on 2022-02-10 by the reprex package (v2.0.1)