0

For a file ts.csv with contents

Date,Foo
2000-01-01,1.45
2000-02-01,1.59

the R code

library(zoo)
infile = "ts.csv"
df = read.zoo(infile, header=TRUE, index=1, read=read.csv)
print(df)
cat("\ncolnames =",colnames(df),"\ndone\n")

that reads ts.csv loses the column names, giving output

Attaching package: 'zoo'

The following objects are masked from 'package:base':

    as.Date, as.Date.numeric

2000-01-01 2000-02-01 
      1.45       1.59 

colnames = 
done

How do I fix this?

Fortranner
  • 2,525
  • 2
  • 22
  • 25
  • Possible duplicate of https://stackoverflow.com/questions/23111450/r-losing-column-heading-with-read-zoo-read-csv-is-fine – akrun Feb 09 '23 at 20:06
  • read.zoo has a drop= argument. The time index can be accessed using the time or index functions. Suggest you read the documentation that comes with the zoo package. – G. Grothendieck Feb 09 '23 at 20:38

0 Answers0