Re: [R] add trailing dates with rbind

2020-08-13 Thread PIKAL Petr
Hi

I am not sure if I understand correctly. You want to change starting days to 
some common value?

It seems to me that you actually want start at zero date and continue in each 
dataset regardless of actual starting date. If it is the case, I would use day 
numbers like in these examples

> x <- seq(as.Date("2020-03-01"), by=1,length.out=20)
> x-x[1]
Time differences in days
 [1]  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19
> y <- seq(as.Date("2020-03-01"), by=2,length.out=10)
> y-y[1]
Time differences in days
 [1]  0  2  4  6  8 10 12 14 16 18
> z <- seq(as.Date("2019-03-01"), by=2,length.out=50)
> z -z[1]
Time differences in days
 [1]  0  2  4  6  8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48
[26] 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98
>

Cheers
Petr

> -Original Message-
> From: R-help  On Behalf Of Frederik Feys
> Sent: Wednesday, August 12, 2020 1:44 PM
> To: R-help 
> Subject: [R] add trailing dates with rbind
> 
> I am having a hell of a time, this must surely be simple to solve….
> 
> Basically I want to add trailing dates to datasets with differing starting 
> dates
> so that across datasets I have the same starting date.
> 
> # make dataset with the same starting date
> start_date = as.Date("2020-03-01")
> d_start_date = min(agg_d_h$Group.date)
> 
> diff_in_days = as.numeric(difftime(d_start_date, start_date, units = "days"))
> 
> for(i in 1:diff_in_days) {
>   next_date  = start_date+i
>   app_d <- rbind(agg_d_h, c(next_date, 0) )
> }
> 
> gives:
> Error in as.Date.numeric(value) : 'origin' must be supplied
> 
> Thank you for your time to help me!
> 
> Frederik Feys
> 
> __
> R-help@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.
__
R-help@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.


Re: [R] add trailing dates with rbind

2020-08-12 Thread Joshua Ulrich
Eric,

Thanks for the recommendation for xts!

Frederik,

Please direct future questions about xts to R-SIG-Finance, or
Stackoverflow.  I (and other users) are more likely to see your
questions there than here on R-help.

Best,
Josh

On Wed, Aug 12, 2020 at 8:08 AM Frederik Feys  wrote:
>
> Thank you so much Eric! Wonderful to have an R community helping out so 
> quickly!
>
> > Op 12 aug. 2020, om 14:10 heeft Eric Berger  het 
> > volgende geschreven:
> >
> > Hi Frederik,
> > (short answer) modify the assignment statement to
> > agg_d_h <- rbind( agg_d_h, data.frame(Group.date=next_date,x=0) )
> >
> > Note: replace x=0 by your-variable-name=0
> > Note: left-hand-side of the assignment statement should be agg_d_h
> >
> > (longer answer) Your approach is far from the best way to do this task, for 
> > a variety of reasons.
> > If you think that in the future you will be working a lot with daily time 
> > series and need to perform similar tasks, I would strongly recommend 
> > learning the xts data structure in the xts package.
> > If you have several time series with different date ranges, and all of them 
> > are xts objects, you can merge them with 'joins' (left joins, right joins, 
> > full joins). xts will automatically handle alignment
> > and preserving dates, etc.
> >
> > HTH,
> > Eric
> >
> >
> >
> >
> > On Wed, Aug 12, 2020 at 2:44 PM Frederik Feys  > > wrote:
> > I am having a hell of a time, this must surely be simple to solve….
> >
> > Basically I want to add trailing dates to datasets with differing starting 
> > dates so that across datasets I have the same starting date.
> >
> > # make dataset with the same starting date
> > start_date = as.Date("2020-03-01")
> > d_start_date = min(agg_d_h$Group.date)
> >
> > diff_in_days = as.numeric(difftime(d_start_date, start_date, units = 
> > "days"))
> >
> > for(i in 1:diff_in_days) {
> >   next_date  = start_date+i
> >   app_d <- rbind(agg_d_h, c(next_date, 0) )
> > }
> >
> > gives:
> > Error in as.Date.numeric(value) : 'origin' must be supplied
> >
> > Thank you for your time to help me!
> >
> > Frederik Feys
> >
> > __
> > R-help@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@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.



-- 
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com

__
R-help@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.


Re: [R] add trailing dates with rbind

2020-08-12 Thread Frederik Feys
Thank you so much Eric! Wonderful to have an R community helping out so 
quickly! 

> Op 12 aug. 2020, om 14:10 heeft Eric Berger  het 
> volgende geschreven:
> 
> Hi Frederik,
> (short answer) modify the assignment statement to
> agg_d_h <- rbind( agg_d_h, data.frame(Group.date=next_date,x=0) )
> 
> Note: replace x=0 by your-variable-name=0
> Note: left-hand-side of the assignment statement should be agg_d_h
> 
> (longer answer) Your approach is far from the best way to do this task, for a 
> variety of reasons.
> If you think that in the future you will be working a lot with daily time 
> series and need to perform similar tasks, I would strongly recommend learning 
> the xts data structure in the xts package.
> If you have several time series with different date ranges, and all of them 
> are xts objects, you can merge them with 'joins' (left joins, right joins, 
> full joins). xts will automatically handle alignment
> and preserving dates, etc. 
> 
> HTH,
> Eric
> 
> 
>   
> 
> On Wed, Aug 12, 2020 at 2:44 PM Frederik Feys  > wrote:
> I am having a hell of a time, this must surely be simple to solve….
> 
> Basically I want to add trailing dates to datasets with differing starting 
> dates so that across datasets I have the same starting date.
> 
> # make dataset with the same starting date
> start_date = as.Date("2020-03-01")
> d_start_date = min(agg_d_h$Group.date)
> 
> diff_in_days = as.numeric(difftime(d_start_date, start_date, units = "days")) 
> 
> for(i in 1:diff_in_days) {
>   next_date  = start_date+i
>   app_d <- rbind(agg_d_h, c(next_date, 0) )
> }
> 
> gives:
> Error in as.Date.numeric(value) : 'origin' must be supplied
> 
> Thank you for your time to help me!
> 
> Frederik Feys
> 
> __
> R-help@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@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.


Re: [R] add trailing dates with rbind

2020-08-12 Thread Eric Berger
Hi Frederik,
(short answer) modify the assignment statement to
agg_d_h <- rbind( agg_d_h, data.frame(Group.date=next_date,x=0) )

Note: replace x=0 by your-variable-name=0
Note: left-hand-side of the assignment statement should be agg_d_h

(longer answer) Your approach is far from the best way to do this task, for
a variety of reasons.
If you think that in the future you will be working a lot with daily time
series and need to perform similar tasks, I would strongly recommend
learning the xts data structure in the xts package.
If you have several time series with different date ranges, and all of them
are xts objects, you can merge them with 'joins' (left joins, right joins,
full joins). xts will automatically handle alignment
and preserving dates, etc.

HTH,
Eric




On Wed, Aug 12, 2020 at 2:44 PM Frederik Feys  wrote:

> I am having a hell of a time, this must surely be simple to solve….
>
> Basically I want to add trailing dates to datasets with differing starting
> dates so that across datasets I have the same starting date.
>
> # make dataset with the same starting date
> start_date = as.Date("2020-03-01")
> d_start_date = min(agg_d_h$Group.date)
>
> diff_in_days = as.numeric(difftime(d_start_date, start_date, units =
> "days"))
>
> for(i in 1:diff_in_days) {
>   next_date  = start_date+i
>   app_d <- rbind(agg_d_h, c(next_date, 0) )
> }
>
> gives:
> Error in as.Date.numeric(value) : 'origin' must be supplied
>
> Thank you for your time to help me!
>
> Frederik Feys
>
> __
> R-help@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@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.


[R] add trailing dates with rbind

2020-08-12 Thread Frederik Feys
I am having a hell of a time, this must surely be simple to solve….

Basically I want to add trailing dates to datasets with differing starting 
dates so that across datasets I have the same starting date.

# make dataset with the same starting date
start_date = as.Date("2020-03-01")
d_start_date = min(agg_d_h$Group.date)

diff_in_days = as.numeric(difftime(d_start_date, start_date, units = "days")) 

for(i in 1:diff_in_days) {
  next_date  = start_date+i
  app_d <- rbind(agg_d_h, c(next_date, 0) )
}

gives:
Error in as.Date.numeric(value) : 'origin' must be supplied

Thank you for your time to help me!

Frederik Feys

__
R-help@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.