How to strsplit using '|' character, it behaves unexpectedly?

前端 未结 4 1374
自闭症患者
自闭症患者 2020-12-03 22:01

I would like to split a string of character at pattern \"|\"

but

unlist(strsplit(\"I am | very smart\", \" | \"))

[1] \"I\"     \"am\"    \"|\"              


        
4条回答
  •  一生所求
    2020-12-03 22:31

    If you are parsing a table than calling read.table might be a better option. Tiny example:

    > txt <- textConnection("I am | very smart")
    > read.table(txt, sep='|')
         V1          V2
    1 I am   very smart
    

    So I would suggest to fetch the wiki page with Rcurl, grab the interesting part of the page with XML (which has a really neat function to parse HTML tables also) and if HTML format is not available call read.table with specified sep. Good luck!

提交回复
热议问题