I want to read a CSV file separated by ";" which contains four columns, such as:
16/12/2006;17:24:00;0;1
16/12/2006;17:25:00;2;3
16/12/2006;17:26:00;4;5
but I want a dataframe with 3 columns rather than 4 (that is, merge the date and hour of the two first columns into a single one).
So far, I have come up with this portion of code inspired by Specify custom Date format for colClasses argument in read.table/read.csv to read the data. Then, I'd merge the two columns somehow.
setClass("myDate")
setAs("character","myDate", function(from) as.Date(from, format="%d/%m/%Y") )
setClass("myTime")
setAs("character","myTime", function(from) as.Date(from, format="%H:%M:%S") )
data <- read.table(file = "file.csv", header = FALSE, sep = ";", colClasses = c("myDate", "myTime", "numeric", "numeric"))
However, the resulting data frame does have a column V2 in which the hour is not properly read.
V1 V2 V3 V4
1 2006-12-16 2016-03-04 0 1
2 2006-12-16 2016-03-04 2 3
3 2006-12-16 2016-03-04 4 5
Is the myTime class badly defined? If so, how should I change it?