read.csv falsly converts string to integer

后端 未结 3 409
盖世英雄少女心
盖世英雄少女心 2021-01-22 23:19

I would like to read a csv file but there are columns that contain strings of digits (string variable). The values in the csv file are quoted (\"\") so easily identifyable as st

3条回答
  •  臣服心动
    2021-01-22 23:34

    You could use the read.csv argument: colClasses

    colClasses describes the content of the columns (see ?read.csv).

    below an example for the first five columns: you need to drop stringAsFactors (it would be overridden by colClasses)

    datSwm <- read.csv("datSwm.csv", header=T, quote='\"', 
    colClasses = c("factor", "numeric", "character", "character", "character") )
    

    You will need to add more details for the remaining columns.

提交回复
热议问题