I have a vector like below
vec <- c(\"abc\\edw\\www\", \"nmn\\ggg\", \"rer\\qqq\\fdf\"......)
I want to remove everything after as soon
another solution :
sub("\\\\.*", "", x)
vec <- c("abc\\edw\\www", "nmn\\ggg", "rer\\qqq\\fdf") sub("([^\\\\])\\\\.*","\\1", vec) [1] "abc" "nmn" "rer"
strssplit(vec, "\\\\") should do the job.
strssplit(vec, "\\\\")
TO select the first element [[1]][1] 2nd [[1]][2]
[[1]][1]
[[1]][2]