Function to split and fetch string components based on a specific delimiter
Arguments
- vec
character vector to apply splitting to
- delim
character specifying the delimitor to separate string by
- part
integer specifying the part to fetch after splitting
Examples
my_string <- c("This_is_random_string.111","Yes_it_is.222")
# Get first part splitting on _
splitAndFetch(vec=my_string,delim="_",part=1)
#> [1] "This" "Yes"
# Get first two parts splitting on _
splitAndFetch(vec=my_string,delim="_",part=1:2)
#> [1] "This_is" "Yes_it"
# Get second part splitting on .
splitAndFetch(vec=my_string,delim=".",part=2)
#> [1] "111" "222"