How to convert Julian day and year to a date format and calculate elapsed time in R -
i have matrix separate columns year (yyyy), julian day, , time (hhmm). attach column vector full gregorian date ("mm/dd/yyyy") , column vector give me elapsed time in days. how go this?
clear, referring these julian days: http://landweb.nascom.nasa.gov/browse/calendar.html help.
c7 <- read.table(text="year day time 2015 193 915 2015 193 930 2015 195 1400 2015 195 1415", header=t)
i add these 2 columns:
year day time date elapsed time (days) 2015 193 915 07/12/2015 0.00 2015 193 930 07/12/2015 0.01 2015 195 1400 07/14/2015 2.20 2015 195 1415 07/14/2015 2.21
first, i'd convert values proper posixt date/time values. here paste in string, separating out hours , minutes using math
pdates <- with(c7, strptime(paste(year,day,time %/% 100, time %% 100), "%y %j %h %m"))
now can desired columns downcasting date , using difftime()
.
format(pdates, "%m/%d/%y") # [1] "07/12/2015" "07/12/2015" "07/14/2015" "07/14/2015" round(c(difftime(pdates, min(pdates), units="days")),2) # [1] 0.00 0.01 2.20 2.21
Comments
Post a Comment