I am currently writing a project, where I have to remove part of a string before and after. I have a attached an example in the bottom, and I am only able to use the packages stringr, tidyverse and dplyr. The different examples have different length, but I only need to keep the "r1" part or "r2". There is r1-4 for 96 different examples. Is anybody able to help me only keep this part af the variable. So I have a variable only containing of the r1, r2, r3 and r4.
[19] "data/r1-23-8-312.json" "data/r1-23-8-66.json" "data/r1-23-8-68.json"
[22] "data/r1-23-8-85.json" "data/r1-23-8-88.json" "data/r2-65-12-200.json"
[25] "data/r2-65-12-202.json" "data/r2-65-12-214.json" "data/r2-65-12-215.json"
class(dat2$route)
[1] "character"
I have figured out, I can use "substr(dat2$route, 6, 7)", but if I use it this way:
dat2 <- substr(dat2$route, 6, 7)
It removes all the other variables beside route, how is that? Got 11 other variables as well.