r - extracting hour minute from non-delimited data -
i have instrument data contains hours , minutes in non-delimited format (e.g., 0, 30, 100, 130, ... 2300, 2300
). convert column posix
object in r (e.g., looks "2016-01-07 11:07:59 est"
) , first step extract out hour , minute data column. (i have corresponding julian date , year columns.)
i getting tripped because hour , minutes not delimited , have been unable use strptime
function. have searched using both google , (using r
, datatime
tags on so), have been unable find solution. of examples find on (e.g., here or here) have hour , minute separated such 0:30
.
here mcve:
hour <- c(0, 30, 100, 130, 1000, 1030, 2300, 2330) year <- c(2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007) day <- c(2, 2, 2, 2, 2, 2, 2, 2) strptime(hour, "%h%m")
so, how extract out hour , minute when have non-delimited data?
you can use sprintf
add leading 0s hours have less 4 digits:
strptime(sprintf("%04d", hour), "%h%m")
you can convert date:
as.posixct(paste(year,day,sprintf("%04d", hour),sep="-"),format = '%y-%j-%h%m')
Comments
Post a Comment