Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in R Programming by (5.3k points)

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 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

Derek

1 Answer

0 votes
by

To fix these warnings, you can either mention all the column names that are to be imported in the colClasses function or mention the column that you want to specify.i.e.,

Assuming that there are five columns in your data set.

colClasses=c("character",rep("numeric",4))

OR

colClasses=c("time"="character")

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.2k users

Browse Categories

...