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"
Have you also included the library call in your Rmd file? have in mind that code run through reprex, runs on a separate clean environment, it doesn't leave anything on your current working environment.
Also, I recommend you take out the " Gov 1005 pset 4" part in your topic title since it seems like you are posting for this topic and those posts are not meant to be solved.