read.csv falsly converts string to integer

后端 未结 3 404
盖世英雄少女心
盖世英雄少女心 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:25

    You can use as.character() on your two columns.

    Example :

    vec <- c(1,2,3)
    > vec
    [1] 1 2 3
    
    vec <- as.character(vec)
    > vec
    [1] "1" "2" "3"
    

    So just write :

    datSwm[,4:5] <- as.character(datSwm[,4:5])
    

提交回复
热议问题