I have the following data:
structure(list(ciclo = c("Basler_2020-12-01 00_34_52.441983_frames_automat.lif",
"Basler_2020-12-01 00_34_52.441983_frames_automat.lif", "Basler_2020-12-01 00_34_52.441983_frames_automat.lif",
"Basler_2020-12-01 00_34_52.441983_frames_automat.lif", "Basler_2020-12-01 00_34_52.441983_frames_automat.lif"
), name = c("2020-12-01_00_34_54.029_1009_1943.png", "2020-12-01_00_34_54.029_1025_394.png",
"2020-12-01_00_34_54.029_1077_1739.png", "2020-12-01_00_34_54.029_1345_631.jpg",
"2020-12-01_00_34_54.029_1360_1538.jpg")), row.names = c(NA,
-5L), class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x0000022bfc1eba70>)
I would remove the names "Basler_" and "_frames_automat.lif" from the first column and the names ".png" and ".jpg" from the second column.
Thanks
CodePudding user response:
using stringr::str_remove_all() can deal with multiple patterns by using the or operator | as per:
library(tidyverse)
df <- df %>%
mutate(
ciclo = str_remove_all(string = ciclo, pattern = "Basler_|_frames_automat.lif"),
name = str_remove_all(string = name, pattern = ".png|.jpeg")
)
Hope this is useful