I can't seem to find an elegant solution to a relatively simple problem in R. I would like to extract characters from a string based on a vector of positions. For example, how could I extract the 1st, 3rd, and 5th characters from example.string? substr does not work without a beginning and end.
example.string <- "ApplesAndCookies"
characters.wanted <- c(1,3,5)
Expected output would be:
Ape
I can design a loop or function to do this, but there has to be an easier way...