The header has white space in it so skip over it, use header = FALSE and specify the column headers yourself. Also use fill=TRUE since the first row does not have 3 entries.
# generate test file cat("Date Adj Close lret 02-01-1997 737.01 03-01-1997 748.03 1.48416235 06-01-1997 747.65 -0.050813009 07-01-1997 753.23 0.743567202 08-01-1997 748.41 -0.64196699 09-01-1997 754.85 0.856809786 10-01-1997 759.5 0.614126802", file = "1.csv") # test library(zoo) read.zoo("1.csv", skip = 1, header = FALSE, format = "%m-%d-%Y", fill = TRUE, col.names = c(NA, "Adj_Close", "Close")) On Thu, Aug 3, 2023 at 10:53 AM Christofer Bogaso <bogaso.christo...@gmail.com> wrote: > > Hi, > > I have a CSV which contains data like below (only first few rows), > > Date Adj Close lret > 02-01-1997 737.01 > 03-01-1997 748.03 1.48416235 > 06-01-1997 747.65 -0.050813009 > 07-01-1997 753.23 0.743567202 > 08-01-1997 748.41 -0.64196699 > 09-01-1997 754.85 0.856809786 > 10-01-1997 759.5 0.614126802 > > However when I try to read this data using below code I get error, > > read.zoo("1.csv", sep = ',', format = '%d-%m-%Y') > > Error reads as, > > index has 4500 bad entries at data rows: 1 2 3 4 5 6 7 8 9..... > > Could you please help to understand why I am getting this error? > > > sessionInfo() > > R version 4.2.2 (2022-10-31) > > Platform: x86_64-apple-darwin17.0 (64-bit) > > Running under: macOS Big Sur ... 10.16 > > > Matrix products: default > > BLAS: > /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib > > LAPACK: > /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib > > > locale: > > [1] C/UTF-8/C/C/C/C > > > attached base packages: > > [1] stats graphics grDevices utils datasets methods base > > > other attached packages: > > [1] zoo_1.8-12 > > > loaded via a namespace (and not attached): > > [1] compiler_4.2.2 tools_4.2.2 grid_4.2.2 lattice_0.20-45 > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.