I have a dataset which contains two date and time columns. I would like to line up the date and time columns in the same row and delete everything to the right of the second date and time column if they don't match. A sample of my dataset problem looks like the following.
Note that Time.1!=Time. A cleaned final version of the dataset should look like this:
I would like to remove everything to the right of the column Date.1 until both Date.1=Date and Time.1=Time.
I have wrote the following R code to do this:
rm(list = ls())
data<-read.csv(file="data.csv",header=T,stringsAsFactors=FALSE)
datacol<-ncol(data)
datarow<-nrow(data)
for (i in 1:datarow){
for (j in 1:(datarow-1)){
while(data$Date[i]!=data$Date.1[j] | data$Time[i]!=data$Time.1[j]){data[j,6:datacol]<-data[j+1,6:datacol];
if (j<datarow) next; if (j == datarow) break; print(data[i,]);}
}
}
However R just keeps running without stop even though I specified break when the length of the row is met. I would appreciate any advice on how to solve this issue.
Thank you.