Choosing specific Date Range from non-sequential Date

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Choosing specific Date Range from non-sequential Date

Ogbos
Dear Contributors,
I have a data frame of the form:
1997-11-23 -2.91709629064653
1997-12-07 -0.960255426066815
1997-12-11 -1.98210752999868
1997-12-20 -1.10800598439855
1998-01-01 -1.00090115428118
1998-01-29 -1.03056081882709
1998-03-27 -0.873243859498216
1998-04-09 -2.06378384750109
1998-04-12 -2.06826431469008
1998-04-19 -2.49834620746286
1998-05-02 -6.4357083781542
1998-05-17 -2.25359807972754
1998-05-21 -2.55799006865995
1999-08-22 -2.25114162617707
1999-08-25 -1.47905397376409
1999-09-05 -0.641589808755325
1999-09-09 -0.648954682695949
1999-09-13 -0.726364489272492
1999-09-16 -1.28445236942011

The events happen randomly and so the date is non-sequential. It run form
1953 to 2019.

I would like to select all the events/dates between 1998 to 2005.

One of the things I tried is:
Year <- subset(MOSCFD50, date > "1998-01-01" & date < "2005-12-31").

But it didn't work.

I would be thankful if you could please redirect me.

Thank you very much.
Best regards
Ogbos

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Choosing specific Date Range from non-sequential Date

Bert Gunter-2
I would guess that you first need to convert your textual dates to a
date-time object via as.date, but as you failed to provide a reproducible
example (e.g. via dput) I may be wrong. Maybe others may have greater
insight.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Mon, Sep 9, 2019 at 8:55 AM Ogbos Okike <[hidden email]> wrote:

> Dear Contributors,
> I have a data frame of the form:
> 1997-11-23 -2.91709629064653
> 1997-12-07 -0.960255426066815
> 1997-12-11 -1.98210752999868
> 1997-12-20 -1.10800598439855
> 1998-01-01 -1.00090115428118
> 1998-01-29 -1.03056081882709
> 1998-03-27 -0.873243859498216
> 1998-04-09 -2.06378384750109
> 1998-04-12 -2.06826431469008
> 1998-04-19 -2.49834620746286
> 1998-05-02 -6.4357083781542
> 1998-05-17 -2.25359807972754
> 1998-05-21 -2.55799006865995
> 1999-08-22 -2.25114162617707
> 1999-08-25 -1.47905397376409
> 1999-09-05 -0.641589808755325
> 1999-09-09 -0.648954682695949
> 1999-09-13 -0.726364489272492
> 1999-09-16 -1.28445236942011
>
> The events happen randomly and so the date is non-sequential. It run form
> 1953 to 2019.
>
> I would like to select all the events/dates between 1998 to 2005.
>
> One of the things I tried is:
> Year <- subset(MOSCFD50, date > "1998-01-01" & date < "2005-12-31").
>
> But it didn't work.
>
> I would be thankful if you could please redirect me.
>
> Thank you very much.
> Best regards
> Ogbos
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Choosing specific Date Range from non-sequential Date

Jeff Newmiller
Or the column is not named "date", or it is a factor... and the question is not posted in plain text....

On September 9, 2019 9:55:48 AM PDT, Bert Gunter <[hidden email]> wrote:

>I would guess that you first need to convert your textual dates to a
>date-time object via as.date, but as you failed to provide a
>reproducible
>example (e.g. via dput) I may be wrong. Maybe others may have greater
>insight.
>
>Bert Gunter
>
>"The trouble with having an open mind is that people keep coming along
>and
>sticking things into it."
>-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
>On Mon, Sep 9, 2019 at 8:55 AM Ogbos Okike <[hidden email]>
>wrote:
>
>> Dear Contributors,
>> I have a data frame of the form:
>> 1997-11-23 -2.91709629064653
>> 1997-12-07 -0.960255426066815
>> 1997-12-11 -1.98210752999868
>> 1997-12-20 -1.10800598439855
>> 1998-01-01 -1.00090115428118
>> 1998-01-29 -1.03056081882709
>> 1998-03-27 -0.873243859498216
>> 1998-04-09 -2.06378384750109
>> 1998-04-12 -2.06826431469008
>> 1998-04-19 -2.49834620746286
>> 1998-05-02 -6.4357083781542
>> 1998-05-17 -2.25359807972754
>> 1998-05-21 -2.55799006865995
>> 1999-08-22 -2.25114162617707
>> 1999-08-25 -1.47905397376409
>> 1999-09-05 -0.641589808755325
>> 1999-09-09 -0.648954682695949
>> 1999-09-13 -0.726364489272492
>> 1999-09-16 -1.28445236942011
>>
>> The events happen randomly and so the date is non-sequential. It run
>form
>> 1953 to 2019.
>>
>> I would like to select all the events/dates between 1998 to 2005.
>>
>> One of the things I tried is:
>> Year <- subset(MOSCFD50, date > "1998-01-01" & date < "2005-12-31").
>>
>> But it didn't work.
>>
>> I would be thankful if you could please redirect me.
>>
>> Thank you very much.
>> Best regards
>> Ogbos
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] 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]]
>
>______________________________________________
>[hidden email] 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.

--
Sent from my phone. Please excuse my brevity.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Choosing specific Date Range from non-sequential Date

Ogbos
Dear Bert and Jeff,
Thank you for looking at this.
I am surprised my message was not in plain text. It has been
configured to send message to the list in plain text earlier before.

The data again please.

1997-11-23 -2.91709629064653
1997-12-07 -0.960255426066815
1997-12-11 -1.98210752999868
1997-12-20 -1.10800598439855
1998-01-01 -1.00090115428118
1998-01-29 -1.03056081882709
1998-03-27 -0.873243859498216
1998-04-09 -2.06378384750109
1998-04-12 -2.06826431469008
1998-04-19 -2.49834620746286
1998-05-02 -6.4357083781542
1998-05-17 -2.25359807972754
1998-05-21 -2.55799006865995
1999-08-22 -2.25114162617707
1999-08-25 -1.47905397376409
1999-09-05 -0.641589808755325
1999-09-09 -0.648954682695949
1999-09-13 -0.726364489272492
1999-09-16 -1.28445236942011

The first column is  date and the second is another data of interest.

The date is long but note sequential. Runs randomly from 1953 to 2019.

I would like to select any range of date from year A to year B.

Thank you again for your help.
Best
Ogbos


On Mon, Sep 9, 2019 at 6:18 PM Jeff Newmiller <[hidden email]> wrote:

>
> Or the column is not named "date", or it is a factor... and the question is not posted in plain text....
>
> On September 9, 2019 9:55:48 AM PDT, Bert Gunter <[hidden email]> wrote:
> >I would guess that you first need to convert your textual dates to a
> >date-time object via as.date, but as you failed to provide a
> >reproducible
> >example (e.g. via dput) I may be wrong. Maybe others may have greater
> >insight.
> >
> >Bert Gunter
> >
> >"The trouble with having an open mind is that people keep coming along
> >and
> >sticking things into it."
> >-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> >
> >
> >On Mon, Sep 9, 2019 at 8:55 AM Ogbos Okike <[hidden email]>
> >wrote:
> >
> >> Dear Contributors,
> >> I have a data frame of the form:
> >> 1997-11-23 -2.91709629064653
> >> 1997-12-07 -0.960255426066815
> >> 1997-12-11 -1.98210752999868
> >> 1997-12-20 -1.10800598439855
> >> 1998-01-01 -1.00090115428118
> >> 1998-01-29 -1.03056081882709
> >> 1998-03-27 -0.873243859498216
> >> 1998-04-09 -2.06378384750109
> >> 1998-04-12 -2.06826431469008
> >> 1998-04-19 -2.49834620746286
> >> 1998-05-02 -6.4357083781542
> >> 1998-05-17 -2.25359807972754
> >> 1998-05-21 -2.55799006865995
> >> 1999-08-22 -2.25114162617707
> >> 1999-08-25 -1.47905397376409
> >> 1999-09-05 -0.641589808755325
> >> 1999-09-09 -0.648954682695949
> >> 1999-09-13 -0.726364489272492
> >> 1999-09-16 -1.28445236942011
> >>
> >> The events happen randomly and so the date is non-sequential. It run
> >form
> >> 1953 to 2019.
> >>
> >> I would like to select all the events/dates between 1998 to 2005.
> >>
> >> One of the things I tried is:
> >> Year <- subset(MOSCFD50, date > "1998-01-01" & date < "2005-12-31").
> >>
> >> But it didn't work.
> >>
> >> I would be thankful if you could please redirect me.
> >>
> >> Thank you very much.
> >> Best regards
> >> Ogbos
> >>
> >>         [[alternative HTML version deleted]]
> >>
> >> ______________________________________________
> >> [hidden email] 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]]
> >
> >______________________________________________
> >[hidden email] 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.
>
> --
> Sent from my phone. Please excuse my brevity.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Choosing specific Date Range from non-sequential Date

Jeff Newmiller
Works for me. Apparently you are not showing us everything you are doing. As Bert recommended, you need to use the dput function rather than dumping numbers into the email if we are to know how your data are stored in memory which will affect what results you get. I highly recommend using the reprex package to verify that your example is reproducible.

On September 9, 2019 12:14:50 PM PDT, Ogbos Okike <[hidden email]> wrote:

>Dear Bert and Jeff,
>Thank you for looking at this.
>I am surprised my message was not in plain text. It has been
>configured to send message to the list in plain text earlier before.
>
>The data again please.
>
>1997-11-23 -2.91709629064653
>1997-12-07 -0.960255426066815
>1997-12-11 -1.98210752999868
>1997-12-20 -1.10800598439855
>1998-01-01 -1.00090115428118
>1998-01-29 -1.03056081882709
>1998-03-27 -0.873243859498216
>1998-04-09 -2.06378384750109
>1998-04-12 -2.06826431469008
>1998-04-19 -2.49834620746286
>1998-05-02 -6.4357083781542
>1998-05-17 -2.25359807972754
>1998-05-21 -2.55799006865995
>1999-08-22 -2.25114162617707
>1999-08-25 -1.47905397376409
>1999-09-05 -0.641589808755325
>1999-09-09 -0.648954682695949
>1999-09-13 -0.726364489272492
>1999-09-16 -1.28445236942011
>
>The first column is  date and the second is another data of interest.
>
>The date is long but note sequential. Runs randomly from 1953 to 2019.
>
>I would like to select any range of date from year A to year B.
>
>Thank you again for your help.
>Best
>Ogbos
>
>
>On Mon, Sep 9, 2019 at 6:18 PM Jeff Newmiller
><[hidden email]> wrote:
>>
>> Or the column is not named "date", or it is a factor... and the
>question is not posted in plain text....
>>
>> On September 9, 2019 9:55:48 AM PDT, Bert Gunter
><[hidden email]> wrote:
>> >I would guess that you first need to convert your textual dates to a
>> >date-time object via as.date, but as you failed to provide a
>> >reproducible
>> >example (e.g. via dput) I may be wrong. Maybe others may have
>greater
>> >insight.
>> >
>> >Bert Gunter
>> >
>> >"The trouble with having an open mind is that people keep coming
>along
>> >and
>> >sticking things into it."
>> >-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>> >
>> >
>> >On Mon, Sep 9, 2019 at 8:55 AM Ogbos Okike
><[hidden email]>
>> >wrote:
>> >
>> >> Dear Contributors,
>> >> I have a data frame of the form:
>> >> 1997-11-23 -2.91709629064653
>> >> 1997-12-07 -0.960255426066815
>> >> 1997-12-11 -1.98210752999868
>> >> 1997-12-20 -1.10800598439855
>> >> 1998-01-01 -1.00090115428118
>> >> 1998-01-29 -1.03056081882709
>> >> 1998-03-27 -0.873243859498216
>> >> 1998-04-09 -2.06378384750109
>> >> 1998-04-12 -2.06826431469008
>> >> 1998-04-19 -2.49834620746286
>> >> 1998-05-02 -6.4357083781542
>> >> 1998-05-17 -2.25359807972754
>> >> 1998-05-21 -2.55799006865995
>> >> 1999-08-22 -2.25114162617707
>> >> 1999-08-25 -1.47905397376409
>> >> 1999-09-05 -0.641589808755325
>> >> 1999-09-09 -0.648954682695949
>> >> 1999-09-13 -0.726364489272492
>> >> 1999-09-16 -1.28445236942011
>> >>
>> >> The events happen randomly and so the date is non-sequential. It
>run
>> >form
>> >> 1953 to 2019.
>> >>
>> >> I would like to select all the events/dates between 1998 to 2005.
>> >>
>> >> One of the things I tried is:
>> >> Year <- subset(MOSCFD50, date > "1998-01-01" & date <
>"2005-12-31").
>> >>
>> >> But it didn't work.
>> >>
>> >> I would be thankful if you could please redirect me.
>> >>
>> >> Thank you very much.
>> >> Best regards
>> >> Ogbos
>> >>
>> >>         [[alternative HTML version deleted]]
>> >>
>> >> ______________________________________________
>> >> [hidden email] 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]]
>> >
>> >______________________________________________
>> >[hidden email] 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.
>>
>> --
>> Sent from my phone. Please excuse my brevity.

--
Sent from my phone. Please excuse my brevity.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Choosing specific Date Range from non-sequential Date: Problem Fixed

Ogbos
Dear Bert and Jeff,
The result is an output of another code and it will be too long or
unnecessary to show all I'm I did to arrive at the given data frame.

Since my single line code works for Jeff, I had to take a second look
and try to get it working for me. I then read the data frame using
d<-read.table("MOSC",colClasses=c("Date","numeric"))  and tried:
Year <- subset(d1, d1[[1]] > "1998-01-01" & d1[[1]] < "2006-01-01")
and arrived at my goal.

Thank you for the hint.
Best regards
Ogbos


On Mon, Sep 9, 2019 at 8:22 PM Jeff Newmiller <[hidden email]> wrote:

>
> Works for me. Apparently you are not showing us everything you are doing. As Bert recommended, you need to use the dput function rather than dumping numbers into the email if we are to know how your data are stored in memory which will affect what results you get. I highly recommend using the reprex package to verify that your example is reproducible.
>
> On September 9, 2019 12:14:50 PM PDT, Ogbos Okike <[hidden email]> wrote:
> >Dear Bert and Jeff,
> >Thank you for looking at this.
> >I am surprised my message was not in plain text. It has been
> >configured to send message to the list in plain text earlier before.
> >
> >The data again please.
> >
> >1997-11-23 -2.91709629064653
> >1997-12-07 -0.960255426066815
> >1997-12-11 -1.98210752999868
> >1997-12-20 -1.10800598439855
> >1998-01-01 -1.00090115428118
> >1998-01-29 -1.03056081882709
> >1998-03-27 -0.873243859498216
> >1998-04-09 -2.06378384750109
> >1998-04-12 -2.06826431469008
> >1998-04-19 -2.49834620746286
> >1998-05-02 -6.4357083781542
> >1998-05-17 -2.25359807972754
> >1998-05-21 -2.55799006865995
> >1999-08-22 -2.25114162617707
> >1999-08-25 -1.47905397376409
> >1999-09-05 -0.641589808755325
> >1999-09-09 -0.648954682695949
> >1999-09-13 -0.726364489272492
> >1999-09-16 -1.28445236942011
> >
> >The first column is  date and the second is another data of interest.
> >
> >The date is long but note sequential. Runs randomly from 1953 to 2019.
> >
> >I would like to select any range of date from year A to year B.
> >
> >Thank you again for your help.
> >Best
> >Ogbos
> >
> >
> >On Mon, Sep 9, 2019 at 6:18 PM Jeff Newmiller
> ><[hidden email]> wrote:
> >>
> >> Or the column is not named "date", or it is a factor... and the
> >question is not posted in plain text....
> >>
> >> On September 9, 2019 9:55:48 AM PDT, Bert Gunter
> ><[hidden email]> wrote:
> >> >I would guess that you first need to convert your textual dates to a
> >> >date-time object via as.date, but as you failed to provide a
> >> >reproducible
> >> >example (e.g. via dput) I may be wrong. Maybe others may have
> >greater
> >> >insight.
> >> >
> >> >Bert Gunter
> >> >
> >> >"The trouble with having an open mind is that people keep coming
> >along
> >> >and
> >> >sticking things into it."
> >> >-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> >> >
> >> >
> >> >On Mon, Sep 9, 2019 at 8:55 AM Ogbos Okike
> ><[hidden email]>
> >> >wrote:
> >> >
> >> >> Dear Contributors,
> >> >> I have a data frame of the form:
> >> >> 1997-11-23 -2.91709629064653
> >> >> 1997-12-07 -0.960255426066815
> >> >> 1997-12-11 -1.98210752999868
> >> >> 1997-12-20 -1.10800598439855
> >> >> 1998-01-01 -1.00090115428118
> >> >> 1998-01-29 -1.03056081882709
> >> >> 1998-03-27 -0.873243859498216
> >> >> 1998-04-09 -2.06378384750109
> >> >> 1998-04-12 -2.06826431469008
> >> >> 1998-04-19 -2.49834620746286
> >> >> 1998-05-02 -6.4357083781542
> >> >> 1998-05-17 -2.25359807972754
> >> >> 1998-05-21 -2.55799006865995
> >> >> 1999-08-22 -2.25114162617707
> >> >> 1999-08-25 -1.47905397376409
> >> >> 1999-09-05 -0.641589808755325
> >> >> 1999-09-09 -0.648954682695949
> >> >> 1999-09-13 -0.726364489272492
> >> >> 1999-09-16 -1.28445236942011
> >> >>
> >> >> The events happen randomly and so the date is non-sequential. It
> >run
> >> >form
> >> >> 1953 to 2019.
> >> >>
> >> >> I would like to select all the events/dates between 1998 to 2005.
> >> >>
> >> >> One of the things I tried is:
> >> >> Year <- subset(MOSCFD50, date > "1998-01-01" & date <
> >"2005-12-31").
> >> >>
> >> >> But it didn't work.
> >> >>
> >> >> I would be thankful if you could please redirect me.
> >> >>
> >> >> Thank you very much.
> >> >> Best regards
> >> >> Ogbos
> >> >>
> >> >>         [[alternative HTML version deleted]]
> >> >>
> >> >> ______________________________________________
> >> >> [hidden email] 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]]
> >> >
> >> >______________________________________________
> >> >[hidden email] 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.
> >>
> >> --
> >> Sent from my phone. Please excuse my brevity.
>
> --
> Sent from my phone. Please excuse my brevity.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Choosing specific Date Range from non-sequential Date

R help mailing list-2
In reply to this post by Ogbos
To get a quick answer to your question you should provide a smallexample
that one can simply copy and paste into an R session.  It also helps to
show some details about how something does not work, more than " But it
didn't work."   E.g.,

d <- read.table(header=FALSE, text="1997-11-23 -2.91709629064653
1997-12-07 -0.960255426066815
1997-12-11 -1.98210752999868
1997-12-20 -1.10800598439855
1998-01-01 -1.00090115428118
1998-01-29 -1.03056081882709")
names(d) <- c("date", "measurement")
subset(d, date > "1997-12-15" & date < "1998-01-16")

which gave:

[1] date        measurement
<0 rows> (or 0-length row.names)
Warning messages:
1: In Ops.factor(date, "1997-12-15") : ‘>’ not meaningful for factors
2: In Ops.factor(date, "1998-01-16") : ‘<’ not meaningful for factors

People seeing the call to read.table() and the warning messages from
subset() could quickly and confidently recommend adding
the colClasses=c("Date", "numeric") to the call to read.table.  Without
that information, both questioners and helpers become frustrated.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Sep 9, 2019 at 12:15 PM Ogbos Okike <[hidden email]>
wrote:

> Dear Bert and Jeff,
> Thank you for looking at this.
> I am surprised my message was not in plain text. It has been
> configured to send message to the list in plain text earlier before.
>
> The data again please.
>
> 1997-11-23 -2.91709629064653
> 1997-12-07 -0.960255426066815
> 1997-12-11 -1.98210752999868
> 1997-12-20 -1.10800598439855
> 1998-01-01 -1.00090115428118
> 1998-01-29 -1.03056081882709
> 1998-03-27 -0.873243859498216
> 1998-04-09 -2.06378384750109
> 1998-04-12 -2.06826431469008
> 1998-04-19 -2.49834620746286
> 1998-05-02 -6.4357083781542
> 1998-05-17 -2.25359807972754
> 1998-05-21 -2.55799006865995
> 1999-08-22 -2.25114162617707
> 1999-08-25 -1.47905397376409
> 1999-09-05 -0.641589808755325
> 1999-09-09 -0.648954682695949
> 1999-09-13 -0.726364489272492
> 1999-09-16 -1.28445236942011
>
> The first column is  date and the second is another data of interest.
>
> The date is long but note sequential. Runs randomly from 1953 to 2019.
>
> I would like to select any range of date from year A to year B.
>
> Thank you again for your help.
> Best
> Ogbos
>
>
> On Mon, Sep 9, 2019 at 6:18 PM Jeff Newmiller <[hidden email]>
> wrote:
> >
> > Or the column is not named "date", or it is a factor... and the question
> is not posted in plain text....
> >
> > On September 9, 2019 9:55:48 AM PDT, Bert Gunter <[hidden email]>
> wrote:
> > >I would guess that you first need to convert your textual dates to a
> > >date-time object via as.date, but as you failed to provide a
> > >reproducible
> > >example (e.g. via dput) I may be wrong. Maybe others may have greater
> > >insight.
> > >
> > >Bert Gunter
> > >
> > >"The trouble with having an open mind is that people keep coming along
> > >and
> > >sticking things into it."
> > >-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> > >
> > >
> > >On Mon, Sep 9, 2019 at 8:55 AM Ogbos Okike <[hidden email]>
> > >wrote:
> > >
> > >> Dear Contributors,
> > >> I have a data frame of the form:
> > >> 1997-11-23 -2.91709629064653
> > >> 1997-12-07 -0.960255426066815
> > >> 1997-12-11 -1.98210752999868
> > >> 1997-12-20 -1.10800598439855
> > >> 1998-01-01 -1.00090115428118
> > >> 1998-01-29 -1.03056081882709
> > >> 1998-03-27 -0.873243859498216
> > >> 1998-04-09 -2.06378384750109
> > >> 1998-04-12 -2.06826431469008
> > >> 1998-04-19 -2.49834620746286
> > >> 1998-05-02 -6.4357083781542
> > >> 1998-05-17 -2.25359807972754
> > >> 1998-05-21 -2.55799006865995
> > >> 1999-08-22 -2.25114162617707
> > >> 1999-08-25 -1.47905397376409
> > >> 1999-09-05 -0.641589808755325
> > >> 1999-09-09 -0.648954682695949
> > >> 1999-09-13 -0.726364489272492
> > >> 1999-09-16 -1.28445236942011
> > >>
> > >> The events happen randomly and so the date is non-sequential. It run
> > >form
> > >> 1953 to 2019.
> > >>
> > >> I would like to select all the events/dates between 1998 to 2005.
> > >>
> > >> One of the things I tried is:
> > >> Year <- subset(MOSCFD50, date > "1998-01-01" & date < "2005-12-31").
> > >>
> > >> But it didn't work.
> > >>
> > >> I would be thankful if you could please redirect me.
> > >>
> > >> Thank you very much.
> > >> Best regards
> > >> Ogbos
> > >>
> > >>         [[alternative HTML version deleted]]
> > >>
> > >> ______________________________________________
> > >> [hidden email] 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]]
> > >
> > >______________________________________________
> > >[hidden email] 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.
> >
> > --
> > Sent from my phone. Please excuse my brevity.
>
> ______________________________________________
> [hidden email] 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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Choosing specific Date Range from non-sequential Date

Rui Barradas
In reply to this post by Ogbos
Hello,

I cannot reproduce the error but I coerce to class "Date" first.


MOSCFD50[[1]] <- as.Date(MOSCFD50[[1]])
names(MOSCFD50) <- c("date", "value")

# Your subset
Year <- subset(MOSCFD50, date > "1998-01-01" & date < "2005-12-31")

# Another way, if there are NA's, use which(i)
i <- MOSCFD50$date > "1998-01-01" & MOSCFD50$date < "2005-12-31"
Year2 <- MOSCFD50[i, ]

identical(Year, Year2)
#[1] TRUE


Data:


MOSCFD50 <- read.table(text = "
1997-11-23 -2.91709629064653
1997-12-07 -0.960255426066815
1997-12-11 -1.98210752999868
1997-12-20 -1.10800598439855
1998-01-01 -1.00090115428118
1998-01-29 -1.03056081882709
1998-03-27 -0.873243859498216
1998-04-09 -2.06378384750109
1998-04-12 -2.06826431469008
1998-04-19 -2.49834620746286
1998-05-02 -6.4357083781542
1998-05-17 -2.25359807972754
1998-05-21 -2.55799006865995
1999-08-22 -2.25114162617707
1999-08-25 -1.47905397376409
1999-09-05 -0.641589808755325
1999-09-09 -0.648954682695949
1999-09-13 -0.726364489272492
1999-09-16 -1.28445236942011
")


Hope this helps,

Rui Barradas


Às 20:14 de 09/09/19, Ogbos Okike escreveu:

> Dear Bert and Jeff,
> Thank you for looking at this.
> I am surprised my message was not in plain text. It has been
> configured to send message to the list in plain text earlier before.
>
> The data again please.
>
> 1997-11-23 -2.91709629064653
> 1997-12-07 -0.960255426066815
> 1997-12-11 -1.98210752999868
> 1997-12-20 -1.10800598439855
> 1998-01-01 -1.00090115428118
> 1998-01-29 -1.03056081882709
> 1998-03-27 -0.873243859498216
> 1998-04-09 -2.06378384750109
> 1998-04-12 -2.06826431469008
> 1998-04-19 -2.49834620746286
> 1998-05-02 -6.4357083781542
> 1998-05-17 -2.25359807972754
> 1998-05-21 -2.55799006865995
> 1999-08-22 -2.25114162617707
> 1999-08-25 -1.47905397376409
> 1999-09-05 -0.641589808755325
> 1999-09-09 -0.648954682695949
> 1999-09-13 -0.726364489272492
> 1999-09-16 -1.28445236942011
>
> The first column is  date and the second is another data of interest.
>
> The date is long but note sequential. Runs randomly from 1953 to 2019.
>
> I would like to select any range of date from year A to year B.
>
> Thank you again for your help.
> Best
> Ogbos
>
>
> On Mon, Sep 9, 2019 at 6:18 PM Jeff Newmiller <[hidden email]> wrote:
>>
>> Or the column is not named "date", or it is a factor... and the question is not posted in plain text....
>>
>> On September 9, 2019 9:55:48 AM PDT, Bert Gunter <[hidden email]> wrote:
>>> I would guess that you first need to convert your textual dates to a
>>> date-time object via as.date, but as you failed to provide a
>>> reproducible
>>> example (e.g. via dput) I may be wrong. Maybe others may have greater
>>> insight.
>>>
>>> Bert Gunter
>>>
>>> "The trouble with having an open mind is that people keep coming along
>>> and
>>> sticking things into it."
>>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>>
>>>
>>> On Mon, Sep 9, 2019 at 8:55 AM Ogbos Okike <[hidden email]>
>>> wrote:
>>>
>>>> Dear Contributors,
>>>> I have a data frame of the form:
>>>> 1997-11-23 -2.91709629064653
>>>> 1997-12-07 -0.960255426066815
>>>> 1997-12-11 -1.98210752999868
>>>> 1997-12-20 -1.10800598439855
>>>> 1998-01-01 -1.00090115428118
>>>> 1998-01-29 -1.03056081882709
>>>> 1998-03-27 -0.873243859498216
>>>> 1998-04-09 -2.06378384750109
>>>> 1998-04-12 -2.06826431469008
>>>> 1998-04-19 -2.49834620746286
>>>> 1998-05-02 -6.4357083781542
>>>> 1998-05-17 -2.25359807972754
>>>> 1998-05-21 -2.55799006865995
>>>> 1999-08-22 -2.25114162617707
>>>> 1999-08-25 -1.47905397376409
>>>> 1999-09-05 -0.641589808755325
>>>> 1999-09-09 -0.648954682695949
>>>> 1999-09-13 -0.726364489272492
>>>> 1999-09-16 -1.28445236942011
>>>>
>>>> The events happen randomly and so the date is non-sequential. It run
>>> form
>>>> 1953 to 2019.
>>>>
>>>> I would like to select all the events/dates between 1998 to 2005.
>>>>
>>>> One of the things I tried is:
>>>> Year <- subset(MOSCFD50, date > "1998-01-01" & date < "2005-12-31").
>>>>
>>>> But it didn't work.
>>>>
>>>> I would be thankful if you could please redirect me.
>>>>
>>>> Thank you very much.
>>>> Best regards
>>>> Ogbos
>>>>
>>>>          [[alternative HTML version deleted]]
>>>>
>>>> ______________________________________________
>>>> [hidden email] 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]]
>>>
>>> ______________________________________________
>>> [hidden email] 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.
>>
>> --
>> Sent from my phone. Please excuse my brevity.
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Choosing specific Date Range from non-sequential Date

Ogbos
Dear All,
Many thanks for all your contributions, suggestions and advice.
I find them all useful.
Best wishes
Ogbos

On Mon, Sep 9, 2019 at 9:35 PM Rui Barradas <[hidden email]> wrote:

>
> Hello,
>
> I cannot reproduce the error but I coerce to class "Date" first.
>
>
> MOSCFD50[[1]] <- as.Date(MOSCFD50[[1]])
> names(MOSCFD50) <- c("date", "value")
>
> # Your subset
> Year <- subset(MOSCFD50, date > "1998-01-01" & date < "2005-12-31")
>
> # Another way, if there are NA's, use which(i)
> i <- MOSCFD50$date > "1998-01-01" & MOSCFD50$date < "2005-12-31"
> Year2 <- MOSCFD50[i, ]
>
> identical(Year, Year2)
> #[1] TRUE
>
>
> Data:
>
>
> MOSCFD50 <- read.table(text = "
> 1997-11-23 -2.91709629064653
> 1997-12-07 -0.960255426066815
> 1997-12-11 -1.98210752999868
> 1997-12-20 -1.10800598439855
> 1998-01-01 -1.00090115428118
> 1998-01-29 -1.03056081882709
> 1998-03-27 -0.873243859498216
> 1998-04-09 -2.06378384750109
> 1998-04-12 -2.06826431469008
> 1998-04-19 -2.49834620746286
> 1998-05-02 -6.4357083781542
> 1998-05-17 -2.25359807972754
> 1998-05-21 -2.55799006865995
> 1999-08-22 -2.25114162617707
> 1999-08-25 -1.47905397376409
> 1999-09-05 -0.641589808755325
> 1999-09-09 -0.648954682695949
> 1999-09-13 -0.726364489272492
> 1999-09-16 -1.28445236942011
> ")
>
>
> Hope this helps,
>
> Rui Barradas
>
>
> Às 20:14 de 09/09/19, Ogbos Okike escreveu:
> > Dear Bert and Jeff,
> > Thank you for looking at this.
> > I am surprised my message was not in plain text. It has been
> > configured to send message to the list in plain text earlier before.
> >
> > The data again please.
> >
> > 1997-11-23 -2.91709629064653
> > 1997-12-07 -0.960255426066815
> > 1997-12-11 -1.98210752999868
> > 1997-12-20 -1.10800598439855
> > 1998-01-01 -1.00090115428118
> > 1998-01-29 -1.03056081882709
> > 1998-03-27 -0.873243859498216
> > 1998-04-09 -2.06378384750109
> > 1998-04-12 -2.06826431469008
> > 1998-04-19 -2.49834620746286
> > 1998-05-02 -6.4357083781542
> > 1998-05-17 -2.25359807972754
> > 1998-05-21 -2.55799006865995
> > 1999-08-22 -2.25114162617707
> > 1999-08-25 -1.47905397376409
> > 1999-09-05 -0.641589808755325
> > 1999-09-09 -0.648954682695949
> > 1999-09-13 -0.726364489272492
> > 1999-09-16 -1.28445236942011
> >
> > The first column is  date and the second is another data of interest.
> >
> > The date is long but note sequential. Runs randomly from 1953 to 2019.
> >
> > I would like to select any range of date from year A to year B.
> >
> > Thank you again for your help.
> > Best
> > Ogbos
> >
> >
> > On Mon, Sep 9, 2019 at 6:18 PM Jeff Newmiller <[hidden email]> wrote:
> >>
> >> Or the column is not named "date", or it is a factor... and the question is not posted in plain text....
> >>
> >> On September 9, 2019 9:55:48 AM PDT, Bert Gunter <[hidden email]> wrote:
> >>> I would guess that you first need to convert your textual dates to a
> >>> date-time object via as.date, but as you failed to provide a
> >>> reproducible
> >>> example (e.g. via dput) I may be wrong. Maybe others may have greater
> >>> insight.
> >>>
> >>> Bert Gunter
> >>>
> >>> "The trouble with having an open mind is that people keep coming along
> >>> and
> >>> sticking things into it."
> >>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> >>>
> >>>
> >>> On Mon, Sep 9, 2019 at 8:55 AM Ogbos Okike <[hidden email]>
> >>> wrote:
> >>>
> >>>> Dear Contributors,
> >>>> I have a data frame of the form:
> >>>> 1997-11-23 -2.91709629064653
> >>>> 1997-12-07 -0.960255426066815
> >>>> 1997-12-11 -1.98210752999868
> >>>> 1997-12-20 -1.10800598439855
> >>>> 1998-01-01 -1.00090115428118
> >>>> 1998-01-29 -1.03056081882709
> >>>> 1998-03-27 -0.873243859498216
> >>>> 1998-04-09 -2.06378384750109
> >>>> 1998-04-12 -2.06826431469008
> >>>> 1998-04-19 -2.49834620746286
> >>>> 1998-05-02 -6.4357083781542
> >>>> 1998-05-17 -2.25359807972754
> >>>> 1998-05-21 -2.55799006865995
> >>>> 1999-08-22 -2.25114162617707
> >>>> 1999-08-25 -1.47905397376409
> >>>> 1999-09-05 -0.641589808755325
> >>>> 1999-09-09 -0.648954682695949
> >>>> 1999-09-13 -0.726364489272492
> >>>> 1999-09-16 -1.28445236942011
> >>>>
> >>>> The events happen randomly and so the date is non-sequential. It run
> >>> form
> >>>> 1953 to 2019.
> >>>>
> >>>> I would like to select all the events/dates between 1998 to 2005.
> >>>>
> >>>> One of the things I tried is:
> >>>> Year <- subset(MOSCFD50, date > "1998-01-01" & date < "2005-12-31").
> >>>>
> >>>> But it didn't work.
> >>>>
> >>>> I would be thankful if you could please redirect me.
> >>>>
> >>>> Thank you very much.
> >>>> Best regards
> >>>> Ogbos
> >>>>
> >>>>          [[alternative HTML version deleted]]
> >>>>
> >>>> ______________________________________________
> >>>> [hidden email] 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]]
> >>>
> >>> ______________________________________________
> >>> [hidden email] 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.
> >>
> >> --
> >> Sent from my phone. Please excuse my brevity.
> >
> > ______________________________________________
> > [hidden email] 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.
> >

______________________________________________
[hidden email] 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.