0

I am trying to read a file with read.csv in R. Unfortunately, some of the records in the file have the following format:

16-Oct-14,6,14228,441,1035,643,921,4679,679,84,2707,370,1322,12882,"-1,346"

Is there anyway I can read the last column as numeric instead of character? To be more precise "1,346" should be read as a decimal numeric.

dem2010 <- read.csv("C:\\Users\\Utilisateur\\Desktop\\H2017\\Méthode de Prévision\\Sessions\\Session 1\\ZonalDemands_2003-2015.csv",
        col.names=c("Date","Hour","TotalOntario", "Northwest","Northeast","Ottawa","East","Toronto", "Essa","Bruce","Southwest","Niagara","West", "TotalZones","diff"),
        colClasses=c("character", rep("integer",13), "character"))

Thanks

user2058291
  • 107
  • 3
  • 10
  • To be clear: Do you want to read both quoted values individually, or something else? – Tim Biegeleisen Jan 07 '17 at 06:33
  • You could use something like the following code snippet to transform the value `as.numeric(gsub(',', '', x))` where `x` is your value like `"-1,346"`. – steveb Jan 07 '17 at 06:51
  • See a similar question (and answers) on StackOverflow [here](http://stackoverflow.com/questions/1523126/how-to-read-data-when-some-numbers-contain-commas-as-thousand-separator). – conrad-mac Jan 07 '17 at 07:18

0 Answers0