Lauri Nikkinen | 20 Aug 08:04
Favicon

Random sequence of days?

Dear list,

I tried to find a solution for this problem from the archives but
couldn't find any. I would like sample sequence of ten days from
vector d

d <- seq(as.Date("2007-02-12"), as.Date("2008-08-18"), by="days")

so that the days follow each other (sample(d, 10) is not the
appropriate solution). Any ideas?

Best regards,
Lauri

______________________________________________
R-help <at> r-project.org mailing list
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.

Moshe Olshansky | 20 Aug 08:12
Favicon

Re: Random sequence of days?

How about

d[sample(length(d),10)]

--- On Wed, 20/8/08, Lauri Nikkinen <lauri.nikkinen <at> iki.fi> wrote:

> From: Lauri Nikkinen <lauri.nikkinen <at> iki.fi>
> Subject: [R] Random sequence of days?
> To: r-help <at> stat.math.ethz.ch
> Received: Wednesday, 20 August, 2008, 4:04 PM
> Dear list,
> 
> I tried to find a solution for this problem from the
> archives but
> couldn't find any. I would like sample sequence of ten
> days from
> vector d
> 
> d <- seq(as.Date("2007-02-12"),
> as.Date("2008-08-18"), by="days")
> 
> so that the days follow each other (sample(d, 10) is not
> the
> appropriate solution). Any ideas?
> 
> Best regards,
> Lauri
> 
> ______________________________________________
> R-help <at> r-project.org mailing list
(Continue reading)

Lauri Nikkinen | 20 Aug 08:18
Favicon

Re: Random sequence of days?

Thanks for quick reply. I meant that the sequence should be like this:

"2007-06-16" "2007-06-17" "2007-06-18" "2007-06-19" "2007-06-20"
"2007-06-21" "2007-06-22" "2007-06-23"
"2007-06-24" "2007-06-25"

so that the the days are adjacent...

-Lauri

2008/8/20, Moshe Olshansky <m_olshansky <at> yahoo.com>:
> How about
>
> d[sample(length(d),10)]
>
>
> --- On Wed, 20/8/08, Lauri Nikkinen <lauri.nikkinen <at> iki.fi> wrote:
>
> > From: Lauri Nikkinen <lauri.nikkinen <at> iki.fi>
> > Subject: [R] Random sequence of days?
> > To: r-help <at> stat.math.ethz.ch
> > Received: Wednesday, 20 August, 2008, 4:04 PM
> > Dear list,
> >
> > I tried to find a solution for this problem from the
> > archives but
> > couldn't find any. I would like sample sequence of ten
> > days from
> > vector d
> >
(Continue reading)

Lauri Nikkinen | 20 Aug 08:45
Favicon

Re: Random sequence of days?

Thanks Jeff for pointing me the right direction. "Consecutive" was the
right word. This will do it

d.samp <- sample(d[1:(length(d)-10)], 1)
seq(d.samp, d.samp+10, by="days")

Regards,
Lauri

2008/8/20, Lauri Nikkinen <lauri.nikkinen <at> iki.fi>:
> Thanks for quick reply. I meant that the sequence should be like this:
>
> "2007-06-16" "2007-06-17" "2007-06-18" "2007-06-19" "2007-06-20"
> "2007-06-21" "2007-06-22" "2007-06-23"
> "2007-06-24" "2007-06-25"
>
> so that the the days are adjacent...
>
> -Lauri
>
> 2008/8/20, Moshe Olshansky <m_olshansky <at> yahoo.com>:
> > How about
> >
> > d[sample(length(d),10)]
> >
> >
> > --- On Wed, 20/8/08, Lauri Nikkinen <lauri.nikkinen <at> iki.fi> wrote:
> >
> > > From: Lauri Nikkinen <lauri.nikkinen <at> iki.fi>
> > > Subject: [R] Random sequence of days?
(Continue reading)

Jeff Newmiller | 20 Aug 08:15

Re: Random sequence of days?

Lauri Nikkinen wrote:
> Dear list,
> 
> I tried to find a solution for this problem from the archives but
> couldn't find any. I would like sample sequence of ten days from
> vector d
> 
> d <- seq(as.Date("2007-02-12"), as.Date("2008-08-18"), by="days")
> 
> so that the days follow each other (sample(d, 10) is not the
> appropriate solution). Any ideas?

"Follow each other" is not clear to me.  Do you want 10 consecutive days?
(Pick a random day between the first and the last less ten, and then
extract the consecutive days.)  Do you want random days, but in
sorted order? (sample ten days and sort the result.)

--

-- 
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil <at> dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                       Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k

______________________________________________
R-help <at> r-project.org mailing list
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.
(Continue reading)


Gmane