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

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -