Tuesday 15 July 2014

date - convert string to datetime R -


I get the string to r. I want to convert it to DAT time

For example, I want to convert it to 'date 2011 / 01-01 00:00' as the '20110101000' string. I would also like to '2011-01-01 01:00' minus '2011-01-01 00:00' = 1 hour. After all, I would like to put a condition where the time difference between two dates is not equal to 1 hour

  if (difference! = 1) {something}  

Currently, I've used as.Date which works fine to change the wires, but there is no substitute for time. Structure with POSIXt also gives me a strange result

  structure ('201101010000', class = C ('POSIXt', 'POSIXct')) [1] "8342-08-21 19 : 40: 00 EDT " 

I have 100,000 files which are to run this operation. Please tell me the most efficient solution.

You can use the Base R package.

Change the date to POSIXcts. See the code below

  dt1 & lt; - c ("201101010100") dt2 & lt; - c ("201101010200") Date 1 & lt; - as.POSIXct (dt1, format = "% Y% m% d% (diff) - difftime (date2, date1, units =" hours ") if variation (diff!); 2. = 1) {print (" something Do ")}  

No comments:

Post a Comment