roslinazairimah zakaria
2015-Jun-10 07:46 UTC
[R] Change Julian function in SPlus to R date code
Dear r-users,
I have a code in SPlus which use julian function. What is the similar code
used in R?
define.date1<-function(dt1,mt1,mt2,nn,da)
{ mt2<-mt2+1
start<-julian(mt1, 1, nn, origin=c(month=1, day=1, year=1971))+1
end<-julian(mt2, 1, nn, origin=c(month=1, day=1, year=1971))+da
a<-dt1[start:end,]
am<-as.matrix(a[,5])
}
I have check the Date package in R but not so sure how to adjust it.
Thank you for any help given.
[[alternative HTML version deleted]]
Try looking at the julian() function in base ... ?julian Jean On Wed, Jun 10, 2015 at 2:46 AM, roslinazairimah zakaria < roslinaump at gmail.com> wrote:> Dear r-users, > > I have a code in SPlus which use julian function. What is the similar code > used in R? > > define.date1<-function(dt1,mt1,mt2,nn,da) > { mt2<-mt2+1 > start<-julian(mt1, 1, nn, origin=c(month=1, day=1, year=1971))+1 > end<-julian(mt2, 1, nn, origin=c(month=1, day=1, year=1971))+da > a<-dt1[start:end,] > am<-as.matrix(a[,5]) > } > > I have check the Date package in R but not so sure how to adjust it. > > Thank you for any help given. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
The parameters for the built-in julian() are a bit different. This
should be what you can use:
start <- julian(as.Date(sprintf("%d-%d-%d", nn, mt1, 1)),
origin=as.Date("1971-01-01"))
end <- julian(as.Date(sprintf("%d-%d-%d", nn, mt2, 1)),
origin=as.Date("1971-01-01"))
On Wed, Jun 10, 2015 at 8:08 AM, Adams, Jean <jvadams at usgs.gov>
wrote:> Try looking at the julian() function in base ...
>
> ?julian
>
> Jean
>
> On Wed, Jun 10, 2015 at 2:46 AM, roslinazairimah zakaria <
> roslinaump at gmail.com> wrote:
>
>> Dear r-users,
>>
>> I have a code in SPlus which use julian function. What is the similar
code
>> used in R?
>>
>> define.date1<-function(dt1,mt1,mt2,nn,da)
>> { mt2<-mt2+1
>> start<-julian(mt1, 1, nn, origin=c(month=1, day=1, year=1971))+1
>> end<-julian(mt2, 1, nn, origin=c(month=1, day=1, year=1971))+da
>> a<-dt1[start:end,]
>> am<-as.matrix(a[,5])
>> }
>>
>> I have check the Date package in R but not so sure how to adjust it.
>>
>> Thank you for any help given.
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.