I compiled a program on my Apple MacBook that takes as inputs Year and Month and Day Latitude and Longitude And then computes these two outputs Sunrise Year-Month-Day Hour:Minute:Second Sunset Year-Month-Day Hour:Minute:Second It automatically handles Daylight Savings Time. A typical input, followed by the automatically computed outputs looks likes this. ./sunrise_05 2022 01 1 38.8586314239524 77.0512533684194 2022-01-01 07:26:45 2022-01-01 16:57:07 ./sunrise_05 2022 01 2 38.8586314239524 77.0512533684194 2022-01-02 07:26:52 2022-01-02 16:57:56 I want to use R?s lines() command to show the sunrise and sunset times for the year 2012. How do I tell R that the first computed output is sunrise, and the second computer output is sunset? Greg Coats
Using R lines() to show sunrise and sunset
7 messages · Gregory Coats, David Winsemius, Ebert,Timothy Aaron +3 more
The first thought it to do is make sure you have the data in POSIXct format for the date times. Sent from my iPhone
On Jul 18, 2022, at 6:51 PM, Gregory Coats via R-help <r-help at r-project.org> wrote: ?I compiled a program on my Apple MacBook that takes as inputs Year and Month and Day Latitude and Longitude And then computes these two outputs Sunrise Year-Month-Day Hour:Minute:Second Sunset Year-Month-Day Hour:Minute:Second It automatically handles Daylight Savings Time. A typical input, followed by the automatically computed outputs looks likes this. ./sunrise_05 2022 01 1 38.8586314239524 77.0512533684194 2022-01-01 07:26:45 2022-01-01 16:57:07 ./sunrise_05 2022 01 2 38.8586314239524 77.0512533684194 2022-01-02 07:26:52 2022-01-02 16:57:56 I want to use R?s lines() command to show the sunrise and sunset times for the year 2012. How do I tell R that the first computed output is sunrise, and the second computer output is sunset? Greg Coats [[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.
Thanks. Yes, I can follow https://www.stat.berkeley.edu/~s133/dates.html Dates and Times in R But my problem is, How to direct R to accept the first computed value as a sunrise, and the second computed values as a sunset? Greg Coats 571-423-9847
On Jul 18, 2022, at 7:58 PM, David Winsemius <dwinsemius at comcast.net> wrote: The first thought it to do is make sure you have the data in POSIXct format for the date times. Sent from my iPhone
On Jul 18, 2022, at 6:51 PM, Gregory Coats via R-help <r-help at r-project.org> wrote: ?I compiled a program on my Apple MacBook that takes as inputs Year and Month and Day Latitude and Longitude And then computes these two outputs Sunrise Year-Month-Day Hour:Minute:Second Sunset Year-Month-Day Hour:Minute:Second It automatically handles Daylight Savings Time. A typical input, followed by the automatically computed outputs looks likes this. ./sunrise_05 2022 01 1 38.8586314239524 77.0512533684194 2022-01-01 07:26:45 2022-01-01 16:57:07 ./sunrise_05 2022 01 2 38.8586314239524 77.0512533684194 2022-01-02 07:26:52 2022-01-02 16:57:56 I want to use R?s lines() command to show the sunrise and sunset times for the year 2012. How do I tell R that the first computed output is sunrise, and the second computer output is sunset? Greg Coats [[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.
Make a dummy variable using an if test. Ifelse(as.numeric(hour(time))<11,df$rise=0,df$rise=1) Then you could use filter() to split the dataset into two parts, or you could use pivot_wider(). Tim -----Original Message----- From: R-help <r-help-bounces at r-project.org> On Behalf Of Gregory Coats via R-help Sent: Monday, July 18, 2022 8:18 PM To: David Winsemius <dwinsemius at comcast.net> Cc: Gregory Coats via R-help <r-help at r-project.org> Subject: Re: [R] Using R lines() to show sunrise and sunset [External Email] Thanks. Yes, I can follow https://urldefense.proofpoint.com/v2/url?u=https-3A__www.stat.berkeley.edu_-7Es133_dates.html&d=DwIFaQ&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRzsn7AkP-g&m=cc9Eq3DGpCl6kcfJbKVLDsJ9i6TKk7SF79PHaRy8-GoQctAlVTXhQIVEHHwO08Q8&s=ym6pjfQa0pw3I4kXT4_gM3iUDXXy52lWTJkwCbXi2NM&e= Dates and Times in R But my problem is, How to direct R to accept the first computed value as a sunrise, and the second computed values as a sunset? Greg Coats 571-423-9847
On Jul 18, 2022, at 7:58 PM, David Winsemius <dwinsemius at comcast.net> wrote: The first thought it to do is make sure you have the data in POSIXct format for the date times. Sent from my iPhone
On Jul 18, 2022, at 6:51 PM, Gregory Coats via R-help <r-help at r-project.org> wrote: ?I compiled a program on my Apple MacBook that takes as inputs Year and Month and Day Latitude and Longitude And then computes these two outputs Sunrise Year-Month-Day Hour:Minute:Second Sunset Year-Month-Day Hour:Minute:Second It automatically handles Daylight Savings Time. A typical input, followed by the automatically computed outputs looks likes this. ./sunrise_05 2022 01 1 38.8586314239524 77.0512533684194 2022-01-01 07:26:45 2022-01-01 16:57:07 ./sunrise_05 2022 01 2 38.8586314239524 77.0512533684194 2022-01-02 07:26:52 2022-01-02 16:57:56 I want to use R?s lines() command to show the sunrise and sunset times for the year 2012. How do I tell R that the first computed output is sunrise, and the second computer output is sunset? Greg Coats [[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mai lman_listinfo_r-2Dhelp&d=DwIFaQ&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVe AsRzsn7AkP-g&m=cc9Eq3DGpCl6kcfJbKVLDsJ9i6TKk7SF79PHaRy8-GoQctAlVTXhQI VEHHwO08Q8&s=7qZYIyeP1-uuz3co5hy-m-ZI7YGOslQI_-_I89eoJ5I&e= PLEASE do read the posting guide https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.o rg_posting-2Dguide.html&d=DwIFaQ&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kV eAsRzsn7AkP-g&m=cc9Eq3DGpCl6kcfJbKVLDsJ9i6TKk7SF79PHaRy8-GoQctAlVTXhQ IVEHHwO08Q8&s=EZBJpqiZa4ZdtRdgor6WYiCsrheRBMsp1O31mCpoHPU&e= and provide commented, minimal, self-contained, reproducible code.
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dhelp&d=DwIFaQ&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRzsn7AkP-g&m=cc9Eq3DGpCl6kcfJbKVLDsJ9i6TKk7SF79PHaRy8-GoQctAlVTXhQIVEHHwO08Q8&s=7qZYIyeP1-uuz3co5hy-m-ZI7YGOslQI_-_I89eoJ5I&e= PLEASE do read the posting guide https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posting-2Dguide.html&d=DwIFaQ&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRzsn7AkP-g&m=cc9Eq3DGpCl6kcfJbKVLDsJ9i6TKk7SF79PHaRy8-GoQctAlVTXhQIVEHHwO08Q8&s=EZBJpqiZa4ZdtRdgor6WYiCsrheRBMsp1O31mCpoHPU&e= and provide commented, minimal, self-contained, reproducible code.
a) Wouldn't distinguishing between sunrise and sunset just amount to referring to the relevant column in your data frame? Why is this a problem you need help with? b) There is no problem with plotting datetimes in R. But you might want to consider plotting hour-of-day instead on the y axis to avoid the monotonocally increasing appearance you would end up with. R does not have a concept of time-of-day separate from date, due to different days having different numbers of hours in them. To compute hour-of-day subtract the beginning of day (use trunc.POSIXt, units = "days") from the actual time and convert the resulting difftime to numeric. 3) General challenges with formulating a response: I can't tell what to do with your command lines, and your use of formatted email is mushing stuff together. You have been vague about what inputs you have (have you imported the data?) or what kind of plot you expect to get using the lines function. (Also I avoid base R plotting functions most of the time, so I tend to sit out on threads that are looking for help with it.)
On July 18, 2022 5:17:51 PM PDT, Gregory Coats via R-help <r-help at r-project.org> wrote:
Thanks. Yes, I can follow https://www.stat.berkeley.edu/~s133/dates.html Dates and Times in R But my problem is, How to direct R to accept the first computed value as a sunrise, and the second computed values as a sunset? Greg Coats 571-423-9847
On Jul 18, 2022, at 7:58 PM, David Winsemius <dwinsemius at comcast.net> wrote: The first thought it to do is make sure you have the data in POSIXct format for the date times. Sent from my iPhone
On Jul 18, 2022, at 6:51 PM, Gregory Coats via R-help <r-help at r-project.org> wrote: ?I compiled a program on my Apple MacBook that takes as inputs Year and Month and Day Latitude and Longitude And then computes these two outputs Sunrise Year-Month-Day Hour:Minute:Second Sunset Year-Month-Day Hour:Minute:Second It automatically handles Daylight Savings Time. A typical input, followed by the automatically computed outputs looks likes this. ./sunrise_05 2022 01 1 38.8586314239524 77.0512533684194 2022-01-01 07:26:45 2022-01-01 16:57:07 ./sunrise_05 2022 01 2 38.8586314239524 77.0512533684194 2022-01-02 07:26:52 2022-01-02 16:57:56 I want to use R?s lines() command to show the sunrise and sunset times for the year 2012. How do I tell R that the first computed output is sunrise, and the second computer output is sunset? Greg Coats [[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.
Sent from my phone. Please excuse my brevity.
Your description is insufficiently precise for us to do more than guess at
what you have. I shall assume your data consists of text strings as shown.
Presumably, you can remove the inputs and collect the outputs into a data
frame, e.g.
dat <- read.table( text = "
2022-01-01 07:26:45 2022-01-01 16:57:07
2022-01-02 07:26:52 2022-01-02 16:57:56"
)[,-3]
## there are 4 text columns. The [,-3] removes the replicated date.
Then, as Jeff suggested,
names(dat) <- c('Date','Sunrise', 'Sunset')
dat
## gives:
Date Sunrise Sunset
1 2022-01-01 07:26:45 16:57:07
2 2022-01-02 07:26:52 16:57:56
But, again, as you have not described your data structure in sufficient
detail (at least for me), this is just a guess.
Once you have the data in this format, you can extract what you need and
maybe use strptime() to convert to appropriate numeric formats. Or maybe
simply use strplit():
strsplit(dat$Sunrise, split = ":")
[[1]] [1] "07" "26" "45" [[2]] [1] "07" "26" "52" Note: as.numeric() converts number strings to numbers:
as.numeric("45")
[1] 45 Again, just a guess, and therefore perhaps useless. -- Bert On Mon, Jul 18, 2022 at 4:51 PM Gregory Coats via R-help <
r-help at r-project.org> wrote:
I compiled a program on my Apple MacBook that takes as inputs
Year and Month and Day
Latitude and Longitude
And then computes these two outputs
Sunrise Year-Month-Day Hour:Minute:Second
Sunset Year-Month-Day Hour:Minute:Second
It automatically handles Daylight Savings Time.
A typical input, followed by the automatically computed outputs looks
likes this.
./sunrise_05 2022 01 1 38.8586314239524 77.0512533684194
2022-01-01 07:26:45 2022-01-01 16:57:07
./sunrise_05 2022 01 2 38.8586314239524 77.0512533684194
2022-01-02 07:26:52 2022-01-02 16:57:56
I want to use R?s lines() command to show the sunrise and sunset times for
the year 2012. How do I tell R that the first computed output is sunrise,
and the second computer output is sunset?
Greg Coats
[[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.
Questions like this keep popping up. Your example shows a single string containing 4 parts: 2022-01-01 07:26:45 2022-01-01 16:57:07 So forget how to ask lines() to do anything. Ask how YOU can make what lines wants. You need to preprocess what sounds like a vector of such strings into four parts and conveniently you have spaces between them. 2022-01-01 07:26:45 2022-01-01 16:57:07 As it happens, your data is measuring sunrise and sunset on the same day so I suspect you can toss the third part as redundant. How you extract them is one of many ways. Pick any you like. But use the parts to make three vectors with names like theDate, sunUp and sundown that are character strings. Use one of many ways to convert the above into a pure Date format and a pure Time Format of your choice as long as your choice of the plot() function can handle them. Using the same names above, you would call plot once with the appropriate arguments to set up your graph and hand it theDate and sunup to place on the axes you want. Then, before the plot is closed, add a call to lines() using theDate and sundown. The answer as to how to tell R or lines() (neither of which are sentient or will pay any attention) is to ask a different question. What arguments do you provide to lines. The answer is you provide two different vectors with each being of a type that plot() and lines() and other such functions can handle. They do not handle text for plotting. They handle integers, floating point, or things that can in some way be converted to them such as the number of seconds since midnight or the number of seconds since Jan 1, 1970. Some would also suggest using ggplot() instead as it allows you to specify multiple sets of lines in a somewhat different way and supplies much more. The first step is asking the right question. You may have intended it but I repeat, NOTHING will get plot() or line() to handle your text version directly. What you want is to feed it what it wants. Some have suggested specifics and there should be enough info for you to do some reading and put the pieces together. -----Original Message----- From: R-help <r-help-bounces at r-project.org> On Behalf Of Gregory Coats via R-help Sent: Monday, July 18, 2022 8:18 PM To: David Winsemius <dwinsemius at comcast.net> Cc: Gregory Coats via R-help <r-help at r-project.org> Subject: Re: [R] Using R lines() to show sunrise and sunset Thanks. Yes, I can follow https://www.stat.berkeley.edu/~s133/dates.html Dates and Times in R But my problem is, How to direct R to accept the first computed value as a sunrise, and the second computed values as a sunset? Greg Coats 571-423-9847
On Jul 18, 2022, at 7:58 PM, David Winsemius <dwinsemius at comcast.net> wrote: The first thought it to do is make sure you have the data in POSIXct format for the date times. Sent from my iPhone
On Jul 18, 2022, at 6:51 PM, Gregory Coats via R-help <r-help at r-project.org> wrote: ?I compiled a program on my Apple MacBook that takes as inputs Year and Month and Day Latitude and Longitude And then computes these two outputs Sunrise Year-Month-Day Hour:Minute:Second Sunset Year-Month-Day Hour:Minute:Second It automatically handles Daylight Savings Time. A typical input, followed by the automatically computed outputs looks likes this. ./sunrise_05 2022 01 1 38.8586314239524 77.0512533684194 2022-01-01 07:26:45 2022-01-01 16:57:07 ./sunrise_05 2022 01 2 38.8586314239524 77.0512533684194 2022-01-02 07:26:52 2022-01-02 16:57:56 I want to use R?s lines() command to show the sunrise and sunset times for the year 2012. How do I tell R that the first computed output is sunrise, and the second computer output is sunset? Greg Coats [[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.
______________________________________________ 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.