How to read data when some numbers contain commas as thousand separator?

后端 未结 11 1290
情书的邮戳
情书的邮戳 2020-11-22 02:29

I have a csv file where some of the numerical values are expressed as strings with commas as thousand separator, e.g. \"1,513\" instead of 1513. Wh

11条回答
  •  爱一瞬间的悲伤
    2020-11-22 02:56

    I think preprocessing is the way to go. You could use Notepad++ which has a regular expression replace option.

    For example, if your file were like this:

    "1,234","123","1,234"
    "234","123","1,234"
    123,456,789
    

    Then, you could use the regular expression "([0-9]+),([0-9]+)" and replace it with \1\2

    1234,"123",1234
    "234","123",1234
    123,456,789
    

    Then you could use x <- read.csv(file="x.csv",header=FALSE) to read the file.

提交回复
热议问题