I am new to R and have been struggling a lot with this problem. Tried to find a solution across places but couldn't.
I have a folder containing multiple csv files (about 158). Each csv has a column with date and time. I found out that the format of the date is not standard across csv files, which messes up my analyzes. Example:
>head(file1) # date format is in MONTH/day/year
DateTime Value
6/2/14 11:00:01 PM 24.111
6/3/14 1:30:01 AM 21.61
6/3/14 4:00:01 AM 20.609
>head(file2) # date format is in day/MONTH/year
DateTime Value
03/06/14 1:30:01 AM 21.588
03/06/14 4:00:01 AM 20.086
03/06/14 6:30:01 AM 18.584
I made the following loop to bind the files.
>files.names<-list.files(getwd(),pattern="*.csv")
>theList <- lapply(files.names,function(x){
> theData <- read.csv(x,skip=18) })
>theResult <- do.call(rbind,theList)
>head(theResult)
Date.Time Value
1 6/2/14 11:00:01 PM 24.111
2 6/3/14 1:30:01 AM 21.610
3 6/3/14 4:00:01 AM 20.609
4 6/3/14 6:30:01 AM 19.107
5 6/3/14 9:00:01 AM 19.608
6 6/3/14 11:30:01 AM 20.609
What I think: I am guessing that there must be a way to standardize the format of the Date.Time
column in the loop of each csv before binding them. That is, I think I have to do that before I do.call(rbind,theList)
, but not sure how (or if it is possible).
Formatting each csv file in Excel would be a pain in the ass, so I would appreciate some help :P .