0

When I read a csv file with read.zoo, the first column name is not imported and cannot be referenced. Reading the same file with read.csv is fine:

> BoE101<- read.csv(file="C:/Users/Charles/Documents/R/Working files/BoE100.csv",   header=TRUE,sep=",")
> head(BoE101)
      Date Notes SightBk SightBS
30/09/1997  2515   37808    1013
31/10/1997  2523   34744     910
30/11/1997  2591   36060    1040
31/12/1997  2832   44573     950
31/01/1998  2495   47145     894
28/02/1998  2501   47511    1174
> BoE101<- read.zoo(file="C:/Users/Charles/Documents/R/Working files/BoE100.csv",      header=TRUE,sep=",",format="%d/%m/%Y")
> head(BoE101)

           Notes SightBk SightBS
1997-09-30  2515   37808    1013
1997-10-31  2523   34744     910
1997-11-30  2591   36060    1040
1997-12-31  2832   44573     950
1998-01-31  2495   47145     894
1998-02-28  2501   47511    1174

In the .csv case, the column header "Date" appears, in the .zoo case, it does not for the same source file.

Does anyone know why this is so and how to avoid it?

Charles Brewer
  • 183
  • 2
  • 12
  • 2
    `read.zoo` assumes the first column of your file is what you want to use as the index of your zoo object. The index of a zoo object is not a column, so it does not get a column name. What's your actual problem? – Joshua Ulrich Apr 16 '14 at 13:57
  • Joshua, thanks. I understand. I was assuming that a zoo object behaved like a conventional data frame and that I would be able to reference this column. However, I see now that this is not the case. Many thanks for the quick and informative response. – Charles Brewer Apr 16 '14 at 14:16
  • The time index is accessed via: `time(BoE101)` or `index(BoE101)`. There is quite a bit of documentation that comes with the zoo package. Please read it. – G. Grothendieck Mar 19 '15 at 22:43

1 Answers1

0

You can recover a dataframe with a column holding the dates by doing

    BoE101 <- as.data.frame(BoE101) 
    BoE101$Date <- rownames(BoE101)