Read csv file with hidden or invisible character ^M

前端 未结 3 979
死守一世寂寞
死守一世寂寞 2021-01-25 08:48

I am attempting unsuccessfully to read a *.csv file containing hidden or invisible characters. The file contents are shown here:

my.data2 <- read.table(text          


        
3条回答
  •  无人共我
    2021-01-25 09:43

    In gVim you should be able to remove the ^M characters by typing the following:

    :%s/VM//g
    

    If you've typed it in correctly it will look like ':%s/^M//g' in gVim. When you press return, gVim searches (the 's') for what's between the first and second slash and replaces it with what's between the second and third slash, globally (the 'g').

    NOTE: If you are on a Windows box and V seems to be pasting text, then gVim may be configured with 'windows behavior'. In that case, use QM instead of VM.

    When I load your sample file into gVim 7.3, it looks like this:

    enter image description here

    After typing the characters

    :%s/VM//g
    

    but BEFORE hitting return I see this:

    enter image description here

    After hitting return I see this:

    enter image description here

    You can then do File->Save or File->Save As, which do what you would expect.

提交回复
热议问题