[R] factor coercion with read.csv or read.table

eric ericstrom at aol.com
Thu Jun 7 04:09:52 CEST 2012


How do I fix this error ? I tried coercion to a vector but that didn't work.

msci <-read.csv("..MSCIexUS.csv", header=TRUE)

head(msci)

         Date  index
1 Dec 31, 1969    100
2 Jan 30, 1970 97.655
3 Feb 27, 1970 96.154
4 Mar 31, 1970 95.857
5 Apr 30, 1970 85.564
6 May 29, 1970 79.005

> str(msci)
'data.frame':	510 obs. of  2 variables:
 $ Date : Factor w/ 510 levels "Apr 28, 1972",..: 98 178 134 311 13 342 268
228 55 481 ...
 $ index: Factor w/ 510 levels "100","1,000.302",..: 1 499 493 488 444 412
418 434 441 448 ...


> msci$Date <-as.Date(msci$Date, dateFormat='%b %d, %Y')
Error in charToDate(x) : 
  character string is not in a standard unambiguous format


--
View this message in context: http://r.789695.n4.nabble.com/factor-coercion-with-read-csv-or-read-table-tp4632622.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list