Hey! Trying to extract the state name from a list of "city, state" variables for Problem Set 4. The weird thing is that this exact code chunk works when I run it through Reprex, but it gives the " Error in FUN(X[[i]], ...) : subscript out of bounds " message when I run it in the Rmd file or the Console.
Any help is appreciated, and I apologize for messing up this reprex format when posting the first time.
library(tidyverse)
library(magrittr)
#>
#> Attaching package: 'magrittr'
#> The following object is masked from 'package:purrr':
#>
#> set_names
#> The following object is masked from 'package:tidyr':
#>
#> extract
library(reprex)
get_state <- function(countystate){
countystate %>%
str_split_fixed(.,", ", 2) %>%
pluck(2) %>%
return()
}
get_state("Treasure County, Montana")
#> [1] "Montana"