Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Data Science
  3. Question
Data Science

Specifying colClasses in the read.csv

Asked by Dipika Agarwal May 18, 2021 3.4K views 1 answer
Share

About this question

 I am trying to specify the collapses options in the read.csv function in R. In my data, the first column "time" is basically a character vector while the rest of the columns are numeric.

data <- read.csv("test.csv", comment.char="" , 
                 colClasses=c(time="character", "numeric"), 
                 strip.white=FALSE)

In the above command, I would want R to read in the "time" column as "character" and the rest as numeric. Although the "data" variable did have the correct result after the command completed, R returned the following warnings. I am wondering how I could fix these warnings?

Warning messages:

 1: In read.table(file = file, header = header, sep = sep, quote = quote,  :
    not all columns named in 'colClasses' exist
 2: In tmp[i[i > 0L]] <- colClasses :
    number of items to replace is not a multiple of replacement length

Your answer

1 Answer

More Data Science discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Data Science Blogs

Guides, tips and career advice on Data Science from JanBask experts.