-1

I am using the readr and bind_rows() function to read multiple csvs.

Example code:

library(readr)
library(dplyr)

df = lapply(c(
  "df 4-11-17.csv",
  "df 4-12-17.csv",
  "df 4-13-17.csv"),
  read_csv) %>% bind_rows()

When I do this I get an error stating:

Error: Can not automatically convert from character to Date in column "Date".

The first column name is "Date" and it is in a character format currently. this is what it looks like when I do str(df) for the first column.

Classes ‘tbl_df’, ‘tbl’ and 'data.frame':   961751 obs. of  15 variables:
 $ Date                       : chr  "4/10/2017" "4/10/2017" "4/10/2017" 
"4/10/2017" ...

If anyone knows how to read multiple csv files at the same time where it disregards the format of the column such as the Date column, it would be helpful!

nak5120
  • 4,089
  • 4
  • 35
  • 94
  • 1
    If you want it to parse for you, you'll need to specify the format in `col_date`; from what you've shown, it's not obvious if it's mdY or dmY. – alistaire Apr 18 '17 at 21:26
  • This is literally the very first item in the readr package documentation. – Ian Wesley Apr 18 '17 at 21:29
  • Possible duplicate of [Importing multiple .csv files with variable column types into R](http://stackoverflow.com/questions/40640132/importing-multiple-csv-files-with-variable-column-types-into-r) – shiny Apr 18 '17 at 22:29

1 Answers1

0

Importing multiple .csv files with variable column types into R

This answered the question:

add

read_csv, col_types = cols(.default = "c")) %>% bind_rows()
Community
  • 1
  • 1
nak5120
  • 4,089
  • 4
  • 35
  • 94