0
votes

I am trying to convert a date into a julian date. I have this data frame

      diff   yr mo dy hr
1 3.174583 1873 12  1  1
2 2.874583 1873 12  1  3
3 2.574583 1873 12  1  5
4 2.074583 1873 12  1  7
5 1.774583 1873 12  1  9
6 1.474583 1873 12  1 11

and for every row I want to assign the number of days since a particular date (e.g. "1870-01-01").

I tried like this

julian(as.Date(paste(dep$yr,dep$mo,dep$dy,sep="/"),"%Y/%m/%d")) 

but this gives me the days since "1970-01-01".. If I try to set the origin

  julian(as.Date(paste(dep$yr,dep$mo,dep$dy,sep="/"),"%Y/%m/%d"),origin = paste(1870,1,1,sep="-"))

then I get this error

Error in unclass(x) - unclass(origin) : 
  non-numeric argument to binary operator

Can some one help me?

Many thanks

1
If you read the help for julian() you will notice that you need to specify the origin which is 1970-01-01 by default.Andrie
@Andrie Yes but when I specify the origin I get the error Error in unclass(x) - unclass(origin) : non-numeric argument to binary operatoruser3706794
@Andrie see edited questionuser3706794
@Andrie no it is the argument for julianuser3706794
This works: julian(as.Date("1873-12-01"), origin = as.Date("1870-01-01")). Your origin should be a Date, not a string.Andrie

1 Answers

1
votes

Using ISOdate here and a proper origin date value should help you

julian(with(dep, ISOdate(yr,mo,dy,hr)), origin=as.Date("1870-1-1"))

# Time differences in days
# [1] 1430.042 1430.125 1430.208 1430.292 1430.375 1430.458