data <- data.table(column1 = paste0("/url/", c("xyz", "dsas", "ffdsfsd", "fsfddsfds", "ffdfd"))) %>%
mutate(column1 = paste0(column1, "/app/"),
column1 = paste0(column1, sample(5)),
column1 = paste0(column1, "app"))
我想删除第二个子目录之后的内容。我尝试了separate
方法,但无法使其正常工作。
答案 0 :(得分:2)
可能是
setDT(data)[, column1 := sub("\\/[^/]*$", "", column1)]
data$column1
#[1] "/url/xyz/app" "/url/dsas/app" "/url/ffdsfsd/app" "/url/fsfddsfds/app" "/url/ffdfd/app"
或者
setDT(data)[, column1 := sub("\\/[^/]*\\/[^/]*$", "", column1)]
data$column1
#[1] "/url/xyz" "/url/dsas" "/url/ffdsfsd" "/url/fsfddsfds" "/url/ffdfd"