Specifying colClasses in the read.csv

前端 未结 7 1178
独厮守ぢ
独厮守ぢ 2020-11-27 10:37

I am trying to specify the colClasses options in the read.csv function in R. In my data, the first column \"time\" is basically a character vector

7条回答
  •  借酒劲吻你
    2020-11-27 11:19

    If you want to refer to names from the header rather than column numbers, you can use something like this:

    fname <- "test.csv"
    headset <- read.csv(fname, header = TRUE, nrows = 10)
    classes <- sapply(headset, class)
    classes[names(classes) %in% c("time")] <- "character"
    dataset <- read.csv(fname, header = TRUE, colClasses = classes)
    

提交回复
热议问题