string - strsplit with vertical bar (pipe) -
here,
> r<-c("aaandbb", "bbandcc") > strsplit(as.character(r),'and') [[1]] [1] "aa" "bb" [[2]] [1] "bb" "cc"
working well, but
> r<-c("aa|andbb", "bb|andcc") > strsplit(as.character(r),'|and') [[1]] [1] "a" "a" "|" "" "b" "b" [[2]] [1] "b" "b" "|" "" "c" "c"
here, answer not correct. how "aa" , "bb", when use '|and'?
in advance.
as can read on ?strsplit, argument split in function strsplit regular expression. hence either need escape vertical bar (it special character)
strsplit(r,split='\\|and')
or can choose fixed=true indicate split not regular expression
strsplit(r,split='|and',fixed=true)
Comments
Post a Comment