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

后端 未结 11 1289
情书的邮戳
情书的邮戳 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:59

    Using read_delim function, which is part of readr library, you can specify additional parameter:

    locale = locale(decimal_mark = ",")
    
    read_delim("filetoread.csv", ';", locale = locale(decimal_mark = ","))
    

    *Semicolon in second line means that read_delim will read csv semicolon separated values.

    This will help to read all numbers with a comma as proper numbers.

    Regards

    Mateusz Kania

提交回复
热议问题