Re: [R] Convert character date time to R date-time variable.

2023-12-08 Thread Duncan Murdoch
On 08/12/2023 4:30 p.m., David Winsemius wrote: On 12/7/23 08:21, Sorkin, John wrote: Colleagues, I have a matrix of character data that represents date and time. The format of each element of the matrix is "2020-09-17_00:00:00" How can I convert the elements into a valid R

Re: [R] Convert character date time to R date-time variable.

2023-12-08 Thread David Winsemius
On 12/7/23 08:21, Sorkin, John wrote: Colleagues, I have a matrix of character data that represents date and time. The format of each element of the matrix is "2020-09-17_00:00:00" How can I convert the elements into a valid R date-time constant? You will not be able to s

Re: [R] Convert character date time to R date-time variable.

2023-12-08 Thread Martin Maechler
17_00:00:00", format = "%Y-%m-%d_%H:%M:%S") [1] "2020-09-17 CEST" > (in my time zone). > -Original Message- From: R-help > On Behalf Of Sorkin, John > Sent: Thursday, December 7, 2023 11:22 AM To: > r-help@r-project.org (r-help@r-

Re: [R] Convert character date time to R date-time variable.

2023-12-07 Thread Dirk Eddelbuettel
`anytime` was written for this: > anytime::anytime("2020-09-17_00:00:00") [1] "2020-09-17 CDT" > class(anytime::anytime("2020-09-17_00:00:00")) [1] "POSIXct" "POSIXt" > Dirk -- dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org __

Re: [R] Convert character date time to R date-time variable.

2023-12-07 Thread Rui Barradas
Às 16:30 de 07/12/2023, Rui Barradas escreveu: Às 16:21 de 07/12/2023, Sorkin, John escreveu: Colleagues, I have a matrix of character data that represents date and time. The format of each element of the matrix is "2020-09-17_00:00:00" How can I convert the elements into a valid R

Re: [R] Convert character date time to R date-time variable.

2023-12-07 Thread Rui Barradas
Às 16:21 de 07/12/2023, Sorkin, John escreveu: Colleagues, I have a matrix of character data that represents date and time. The format of each element of the matrix is "2020-09-17_00:00:00" How can I convert the elements into a valid R date-time constant? Thank you, John John Da

Re: [R] Convert character date time to R date-time variable.

2023-12-07 Thread Ebert,Timothy Aaron
Look at the lubridate package in R. Regards, Tim -Original Message- From: R-help On Behalf Of Sorkin, John Sent: Thursday, December 7, 2023 11:22 AM To: r-help@r-project.org (r-help@r-project.org) Subject: [R] Convert character date time to R date-time variable. [External Email

[R] Convert character date time to R date-time variable.

2023-12-07 Thread Sorkin, John
Colleagues, I have a matrix of character data that represents date and time. The format of each element of the matrix is "2020-09-17_00:00:00" How can I convert the elements into a valid R date-time constant? Thank you, John John David Sorkin M.D., Ph.D. Professor of Medicine, Uni

Re: [R] Date order question

2023-01-04 Thread PIKAL Petr
annotate("text", x=date[2], y=.8, label="OOC",size=6,fontface="bold")+ annotate("text", x=date[2], y=-.05, label="PT Not Done",size=5,fontface="bold") Cheers Petr > -Original Message- > From: R-help On Behalf Of Thom

Re: [R] Date order question

2023-01-04 Thread CALUM POLWART
On Wed, 4 Jan 2023, 21:29 Ebert,Timothy Aaron, wrote: > > As you are plotting strings, you could put a space character in front of > the December dates so that they are first. > date<-c(" 12-29"," 12-30","01-01") > That fixes the problem in this example. You can order all the dates by > putting m

Re: [R] Date order question

2023-01-04 Thread Rui Barradas
Às 21:08 de 04/01/2023, Thomas Subia escreveu: Colleagues, date<-c("12-29","12-30","01-01") PT <- c(.106,.130,.121) data <- data.frame(date,PT) ggplot(data, aes(x=date,y=PT,group=1))+ geom_point(size=4)+ geom_line()+ geom_hline(yintercept =c(1,.60,0,.30,.25,.2))+ scale_y_continuous(

Re: [R] Date order question

2023-01-04 Thread Ebert,Timothy Aaron
lier years. That will get messy. Tim -Original Message- From: R-help On Behalf Of Thomas Subia Sent: Wednesday, January 4, 2023 4:08 PM To: r-help@r-project.org Subject: [R] Date order question [External Email] Colleagues, date<-c("12-29","12-30","01-01") PT

Re: [R] Date order question

2023-01-04 Thread Andrew Simmons
I converted `date` to a factor and it seemed to work: ``` library(ggplot2) library(cowplot) date <- c("12-29","12-30","01-01") date <- factor(date, labels = unique(date)) PT <- c(.106,.130,.121) data <- data.frame(date,PT) ggplot(data, aes(x=date,y=PT,group=1))+ geom_point(size=4)+ geom_line(

[R] Date order question

2023-01-04 Thread Thomas Subia
Colleagues, date<-c("12-29","12-30","01-01") PT <- c(.106,.130,.121) data <- data.frame(date,PT) ggplot(data, aes(x=date,y=PT,group=1))+ geom_point(size=4)+ geom_line()+ geom_hline(yintercept =c(1,.60,0,.30,.25,.2))+ scale_y_continuous(label=scales::label_percent(),breaks=c(1,0.6,0,.3,0.2

Re: [R] Date and Time

2022-07-18 Thread Ebert,Timothy Aaron
Jeff Newmiller Sent: Monday, July 18, 2022 12:35 AM To: Greg Comcast Coats ; Gregory Coats via R-help Subject: Re: [R] Date and Time [External Email] Maybe this [1] will help? Or just read ?strptime... You can also calculate sunrise/sunset (crepuscule) using maptools, but you need to be careful

Re: [R] Date and Time

2022-07-17 Thread Daniel Nordlund
On 7/17/2022 8:47 PM, Gregory Coats via R-help wrote: For the year from 2022-01-01 to 2022-12-31, I computed the sunrise and sunset times for Reston, Virginia, USA. I am seeking the syntax to direct R to read in these dates and times, and then graphical plot the sunrise and sunset times for ea

Re: [R] Date and Time

2022-07-17 Thread Jeff Newmiller
Maybe this [1] will help? Or just read ?strptime... You can also calculate sunrise/sunset (crepuscule) using maptools, but you need to be careful with timezones. [1] https://jdnewmil.github.io/time-2018-10/MoreDatetimeHowto.html On July 17, 2022 8:47:19 PM PDT, Gregory Coats via R-help wrote:

Re: [R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-23 Thread peter dalgaard
It reads other formats _if you specify them_. After all, no computer (or human) can tell whether 11/03/1959 is November 3 or March 11 without further hinting. So it tries the two ISO-like formats and leaves other cases for the user. -pd > On 20 Nov 2021, at 21:22 , Philip Monk wrote: > > Than

Re: [R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-22 Thread Spencer Graves
see if the data is what you expect or alter it to be what you need. -Original Message- From: R-help On Behalf Of Philip Monk Sent: Saturday, November 20, 2021 3:28 PM To: Jeff Newmiller Cc: R-help Mailing List Subject: Re: [R] Date read correctly from CSV, then reformatted incorr

Re: [R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-22 Thread Robert Knight
Richard, This response was awe-inspiring. Thank you. -Original Message- From: R-help On Behalf Of Richard O'Keefe Sent: Sunday, November 21, 2021 8:55 PM To: Philip Monk Cc: R Project Help Subject: Re: [R] Date read correctly from CSV, then reformatted incorrectly by R CSV da

Re: [R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-21 Thread Richard O'Keefe
CSV data is very often strangely laid out. For analysis, Buffer Date Reading 100... ... 100... ... and so on is more like what a data frame should be. I get quite annoyed when I finally manage to extract data from a government agency only to find that my tax money has been spent on maki

Re: [R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-20 Thread Avi Gross via R-help
that may also mean sanity checks along the way to see if the data is what you expect or alter it to be what you need. -Original Message- From: R-help On Behalf Of Philip Monk Sent: Saturday, November 20, 2021 3:28 PM To: Jeff Newmiller Cc: R-help Mailing List Subject: Re: [R] Date

Re: [R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-20 Thread Philip Monk
I am. Long day, poorly small children! P On Sat, 20 Nov 2021, 21:08 Bert Gunter, wrote: > "I also know that '/' is a special character in R (if that's the right > term) " > > That is false. I think you are confusing "/" with "\", which is R's > *escape* character. > > > cat("a/nb") > a/nb > >

Re: [R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-20 Thread Bert Gunter
"I also know that '/' is a special character in R (if that's the right term) " That is false. I think you are confusing "/" with "\", which is R's *escape* character. > cat("a/nb") a/nb > cat("a\nb") a b It gets confusing especially in regex's, because "\" is used in regex syntax also. Bert Gun

Re: [R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-20 Thread Philip Monk
Thanks, Jeff. I follow what you're doing below, but know I need to read up on Date / POSIXct. Helpful direction! :) On Sat, 20 Nov 2021 at 18:41, Jeff Newmiller wrote: > > Beat me to it! But it is also worth noting that once converted to Date or > POSIXct, timestamps should be treated as data

Re: [R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-20 Thread Philip Monk
Thanks, Andrew. I didn't realise as.Date *only* read two formats, I think I was tripped up by using %y instead of %Y, though I also know that '/' is a special character in R (if that's the right term) and as such know there is special syntax to use (which I don't know). On Sat, 20 Nov 2021 at 18:

Re: [R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-20 Thread Jeff Newmiller
Beat me to it! But it is also worth noting that once converted to Date or POSIXct, timestamps should be treated as data without regard to how that data is displayed. When you choose to output that data you will have options as to the display format associated with the function you are using for

Re: [R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-20 Thread Andrew Simmons
The as.Date function for a character class argument will try reading in two formats (%Y-%m-%d and %Y/%m/%d). This does not look like the format you have provided, which is why it doesn't work. Try something like: x <- c("28/10/2016", "19/11/2016", "31/12/2016", "16/01/2016", "05/03/2017") as.Da

Re: [R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-20 Thread Philip Monk
Thanks Eric & Jeff. I'll certainly read up on lubridate, and the posting guide (again) (this should be in plain text). CSV extract below... Philip Buffer28/10/201619/11/201631/12/201616/01/201705/03/2017 1002.437110889-8.696748953.2392998162.4431833042.34

Re: [R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-20 Thread Jeff Newmiller
a) R data frames are column oriented. Do not fight this. b) Data frame header names are character type. Period. Do not fight this. It sounds like you need to reshape your data after you read it in. Provide the first five lines of your CSV file (or a reasonable facsimile if your data are confide

Re: [R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-20 Thread Eric Berger
Hi Philip, This is a recurring question and there are many ways to do this. My preference is to use the lubridate package. library(lubridate) a <- "15/01/2010" b <- dmy(a) b # "2010-01-15" class(b) # [1] "Date" HTH, Eric On Sat, Nov 20, 2021 at 7:09 PM Philip Monk wrote: > Hello, > > Simple b

[R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-20 Thread Philip Monk
Hello, Simple but infuriating problem. Reading in CSV of data using : ``` # CSV file has column headers with date of scene capture in format dd/mm/ # check.names = FALSE averts R incorrectly processing dates due to '/' data <- read.csv("C:/R_data/Bungala (b2000) julian.csv", check.names = FA

Re: [R] Date

2021-11-05 Thread Val
Thank you All. The issue was not reading different file. I just mistyped the column name, instead of typing My_date I typed mydate in the email. The problem is solved by using this dat=read.csv("myfile.csv",stringsAsFactors=FALS) suggested by Jim. On Thu, Nov 4, 2021 at 7:58 PM Jeff Newmiller

Re: [R] Date

2021-11-04 Thread Jeff Newmiller
Then you are looking at a different file... check your filenames. You have imported the column as character, and R has not yet recognized that it is supposed to be a date, so it can only show what it found. You will almost certainly find your error if you make a reproducible example. On Novembe

Re: [R] Date

2021-11-04 Thread Val
Jeff, The date from y data file looks like as follow in the Linux environment, My_date 2019-09-16 2021-02-21 2021-02-22 2017-10-11 2017-10-10 2018-11-11 2017-10-27 2017-10-30 2019-05-20 On Thu, Nov 4, 2021 at 5:00 PM Jeff Newmiller wrote: > > You are claiming behavior that is not something R doe

Re: [R] Date

2021-11-04 Thread Spencer Graves
m your use two asDate commands. Cheers Petr -Original Message- From: R-help On Behalf Of Val Sent: Thursday, November 4, 2021 10:43 PM To: r-help@R-project.org (r-help@r-project.org) Subject: [R] Date IHi All, l, I am reading a csv file and one of the columns is named as "my

Re: [R] Date

2021-11-04 Thread PIKAL Petr
Val Sent: Thursday, November 4, 2021 10:43 PM To: r-help@R-project.org (r-help@r-project.org) Subject: [R] Date IHi All, l, I am reading a csv file and one of the columns is named as "mydate" with this form, 2019-09-16. I am reading this file as dat=read.csv("myfile

Re: [R] Date

2021-11-04 Thread Jim Lemon
Hi Val, Try this: dat=read.csv("myfile.csv",stringsAsFactors=FALSE) However, the apparently silent conversion of format is a mystery to me. The only time I have struck something like this was when exporting dates from Excel some years ago, and there was a silent conversion to mm/dd/ format if

Re: [R] Date

2021-11-04 Thread Jeff Newmiller
You are claiming behavior that is not something R does, but is something Excel does constantly. Compare what your data file looks like using a text editor with what R has imported. Absolutely do not use a spreadsheet program to do this. On November 4, 2021 2:43:25 PM PDT, Val wrote: >IHi All,

[R] Date

2021-11-04 Thread Val
IHi All, l, I am reading a csv file and one of the columns is named as "mydate" with this form, 2019-09-16. I am reading this file as dat=read.csv("myfile.csv") the structure of the data looks like as follow str(dat) mydate : chr "09/16/2019" "02/21/2021" "02/22/2021" "10/11/2017" ...

Re: [R] Date Time, as.POSIXct used locale, strange plot behavior

2021-04-30 Thread Tilmann Faul
Dear Enrico, Thanks a lot, that clarifies the topic for me. Checking the numeric representation i was not aware of. Best Regards Tilmann On 30.04.21 11:17, Enrico Schumann wrote: > On Fri, 30 Apr 2021, Tilmann Faul writes: > >> Dear Jeff, >> >> Thanks for your answer. >> Sys.timezone() gives >

Re: [R] Date Time, as.POSIXct used locale, strange plot behavior

2021-04-30 Thread Enrico Schumann
On Fri, 30 Apr 2021, Tilmann Faul writes: > Dear Jeff, > > Thanks for your answer. > Sys.timezone() gives > [1] "Europe/Berlin" > I tried "Europe/Berlin" as tz argument, giving the same result als using > "CEST" (Central European Summer Time). > It seems to me, that using as.POSIXct without tz ar

Re: [R] Date Time, as.POSIXct used locale, strange plot behavior

2021-04-30 Thread Tilmann Faul
Dear Jeff, Thanks for your answer. Sys.timezone() gives [1] "Europe/Berlin" I tried "Europe/Berlin" as tz argument, giving the same result als using "CEST" (Central European Summer Time). It seems to me, that using as.POSIXct without tz argument defaults to tz UTC and with tz argument, either "CE

Re: [R] Date Time, as.POSIXct used locale, strange plot behavior

2021-04-30 Thread PIKAL Petr
="CET"), 0.3, as.POSIXct("2021-04-21 00:00:00", tz="CET"), 0.2, length=0.07, angle=15) Cheers Petr > -Original Message- > From: R-help On Behalf Of Jeff Newmiller > Sent: Thursday, April 29, 2021 11:20 PM > To: r-hel

Re: [R] Date Time, as.POSIXct used locale, strange plot behavior

2021-04-29 Thread Jeff Newmiller
What is your TZ environment variable set to? That's what time conversion defaults to ?DateTimeClasses Also, I am not sure CEST is a valid timezone designation... it can be system dependent, but using one of the elements listed in ?OlsonNames. On April 29, 2021 12:22:44 PM PDT, Tilmann Faul w

[R] Date Time, as.POSIXct used locale, strange plot behavior

2021-04-29 Thread Tilmann Faul
Hy, stumbled over the following problem while plotting DateTime Objects. plot(as.POSIXct(c("2021-04-21 00:00:00", "2021-04-21 23:59:59")), c(0, 1), type='l') arrows(as.POSIXct("2021-04-21 00:00:00", tz="CEST"), 0.3, as.POSIXct("2021-04-21 00:00:00", tz="CEST"), 0.2, l

Re: [R] date

2020-09-21 Thread Duncan Murdoch
Another way to do this is to use the xtfrm() function. That function creates numerical values from many different starting types, so you can just change the sign to change the sort order: df[order(df$ID, -xtfrm(df$date2)),] I never did figure out where the name came from. Duncan Murdoch On

Re: [R] date

2020-09-21 Thread Sarah Goslee
Hi, Nice reproducible example. rev(df$date2) isn't doing what you think it's doing - try looking at it by itself. Some digging into ?order will get you what you are after: df[order(df$ID, df$date2, decreasing=c(FALSE, TRUE), method="radix"),] > df[order(df$ID, df$date2, decreasing=c(FALSE, TRU

[R] date

2020-09-21 Thread Val
Hi All, I am trying to sort dates within a group. My sample data is df <-read.table(text="ID date A1 09/17/04 A1 01/27/05 A1 05/07/03 A2 05/21/17 A2 09/12/16 A3 01/25/13 A4 09/27/19",header=TRUE,stringsAsFactors=F) df$date2 = as.Date(strptime(df$date,format="%m/%d/%y")) df$date =NUL

Re: [R] date conversion problem

2020-08-13 Thread Abdoulaye Sarr
Hi Jim, Thanks for the hint, that makes sense and I'll arrange accordingly. Best regards, Abdoulaye On Thu, Aug 13, 2020 at 8:38 AM Jim Lemon wrote: > Hi Abdoulaye, > It looks to me as though your offsets are in hours, not days. You can > get a rough date like this: > > time<-c(1569072,1569096,

Re: [R] date conversion problem

2020-08-13 Thread Jim Lemon
Hi Abdoulaye, It looks to me as though your offsets are in hours, not days. You can get a rough date like this: time<-c(1569072,1569096,1569120,1569144, 1569168,1569192,1569216,1569240) time_d<-as.Date("1800-01-01")+time/24 time_d [1] "1979-01-01" "1979-01-02" "1979-01-03" "1979-01-04" "1979-01-0

[R] date conversion problem

2020-08-13 Thread Abdoulaye Sarr
I have dataset with time sine 1800-01-01 and extracted data from 1981 to 2019 and used these lines for the data conversion: > time_d <- as.Date(time, format="%j", origin=as.Date("1800-01-01")) > time_years <- format(time_d, "%Y") > time_months <- format(time_d, "%m") > time_year_months <- format(ti

Re: [R] Date Conversion Problem

2020-08-12 Thread Eric Berger
nice On Wed, Aug 12, 2020 at 6:18 PM Bert Gunter wrote: > Extra packages are not needed. > > My question is: why change the character representation at all? See the > format argument of ?as.Date. > > > as.Date("20010102",format="%Y%m%d") > [1] "2001-01-02" ## the default format for the print me

Re: [R] Date Conversion Problem

2020-08-12 Thread Bert Gunter
Extra packages are not needed. My question is: why change the character representation at all? See the format argument of ?as.Date. > as.Date("20010102",format="%Y%m%d") [1] "2001-01-02" ## the default format for the print method for Date objects Bert Gunter "The trouble with having an open m

Re: [R] Date Conversion Problem

2020-08-12 Thread Eric Berger
library(lubridate) a <- "20200403" lubridate::ymd(a) # 2020-04-03 HTH, Eric On Wed, Aug 12, 2020 at 5:57 PM Stephen P. Molnar wrote: > i have written an R script which allow me to plot the number of Covid-10 > cases reported by he state of Ohio. In that se t of data the date format > is in the

[R] Date Conversion Problem

2020-08-12 Thread Stephen P. Molnar
i have written an R script which allow me to plot the number of Covid-10 cases reported by he state of Ohio. In that se t of data the date format is in the form -mm-dd. My script uses: datebreaks <- seq(as.Date("2020-01-01"), as.Date("2020-08-10"), by="1 week") . .

Re: [R] Date from text

2020-05-15 Thread Enrico Schumann
On Fri, 15 May 2020, Poizot Emmanuel writes: > Dear all, > > I've a data frame with a column "Date": > > [1] 11-1993 11-1993 11-1993 11-1993 11-1993 11-1993 11-1996 11-1996 11-1996 > [10] 11-1996 11-1996 11-1996 02-1998 02-1998 02-1998 02-1998 02-1998 02-1998 > [19] 11-1998 11-1998 11-1998 11-1998

Re: [R] Date from text

2020-05-15 Thread Marc Schwartz via R-help
Hi, For the usual R text to date conversions, you need a complete date. Since you are missing the day of the month in your source text, you would need to impute that part before making the conversion. Also, since you don't appear to need to worry about time of day, just use as.Date(), instead

[R] Date from text

2020-05-15 Thread Poizot Emmanuel
Dear all, I've a data frame with a column "Date": [1] 11-1993 11-1993 11-1993 11-1993 11-1993 11-1993 11-1996 11-1996 11-1996 [10] 11-1996 11-1996 11-1996 02-1998 02-1998 02-1998 02-1998 02-1998 02-1998 [19] 11-1998 11-1998 11-1998 11-1998 11-1998 11-1998 10-2001 10-2001 10-2001 [28] 10-2001 10-

Re: [R] Date format

2020-05-12 Thread Rainer Hurling
Hi Medic, Am 10.05.20 um 09:15 schrieb Medic: I took a SAMPLE CODE (for Connected scatterplot) from the R gallery and applied to MY DATA, but got: "Don't know how to automatically pick scale for object ..." P.S. 1) R ver. 4.0 (Yes, Jeff); 2) Attached: mydata_dput (1 КБ) SAMPLE CODE library(ggp

Re: [R] Date format

2020-05-10 Thread Medic
Many Thanks!!! > cpolw...@chemo.org.uk: > Your X axis is plotting mydata not date? > Use aes(x=date __ 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://

Re: [R] Date format

2020-05-10 Thread Medic
I took a SAMPLE CODE (for Connected scatterplot) from the R gallery and applied to MY DATA, but got: "Don't know how to automatically pick scale for object ..." P.S. 1) R ver. 4.0 (Yes, Jeff); 2) Attached: mydata_dput (1 КБ) SAMPLE CODE library(ggplot2) library(dplyr) library(hrbrthemes) data <-

Re: [R] Date format

2020-05-09 Thread Rainer Hurling
Am 10.05.20 um 04:17 schrieb Bert Gunter: > $date is a factor, which is coded as numeric values internally, which > as.date sees as numeric, and therefore: > "as.Date will accept numeric data (the number of days since an epoch), > but only if origin is supplied." (from ?as.Date) as.Date is also ab

Re: [R] Date format

2020-05-09 Thread Bert Gunter
True. Whence the error message then? Still, in my attempt to reproduce, the format statement worked. 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 Sat, May 9,

Re: [R] Date format

2020-05-09 Thread Jeff Newmiller
... but str says it is character. This must be 4.0... On May 9, 2020 7:17:16 PM PDT, Bert Gunter wrote: >$date is a factor, which is coded as numeric values internally, which >as.date sees as numeric, and therefore: >"as.Date will accept numeric data (the number of days since an epoch), >but only

Re: [R] Date format

2020-05-09 Thread Bert Gunter
$date is a factor, which is coded as numeric values internally, which as.date sees as numeric, and therefore: "as.Date will accept numeric data (the number of days since an epoch), but only if origin is supplied." (from ?as.Date) You need to supply a format argument to as.Date to get it to handle

[R] Date format

2020-05-09 Thread Medic
I took a SAMPLE CODE (for Connected scatterplot) from the R gallery and applied to MY DATA, but got: "Error in as.Date.numeric(mydata$date) : 'origin' must be supplied". P.S. I can not understand ?as.Date() SAMPLE CODE library(ggplot2) library(dplyr) library(hrbrthemes) data <- read.table("https:

Re: [R] date

2019-12-19 Thread David Stevens
Val Another all-base R solution: as.Date(strptime(gs$date,format="%m/%d/%y")) or if you want to add a time field later as.POSIXct(strptime(gs$date,format="%m/%d/%y"))) since strptime produces a list version of the date: class is POSIXt and the subclass is POSIXlt, that can be convenient for e

Re: [R] date

2019-12-19 Thread Jeff Newmiller
I agree that having convenience functions can be in the spirit of R, but I find that lubridate puts the cart before the horse so I avoid it. Specifically, the conceptual sequence - convert character to timestamp in GMT - "fix" erroneous timestamps to correct time zone more inefficient and error

Re: [R] date

2019-12-19 Thread Eric Berger
[ ... taking the bait regarding the "unnecessary discussion" ... ] The "Fortune nomination" that Bert sent includes the phrase "...then it is best to tell R ..." What metric is being used to do the ranking to get the "best"? If the metric is related to "providing the most unambiguous information

Re: [R] date

2019-12-19 Thread Bert Gunter
"But the important point is: If you know the structure of the data you want to parse, then it is best to tell R (or any other language) this structure explicitly. " Fortune nomination! -- Bert Thu, Dec 19, 2019, 2:49 AM Enrico Schumann wrote: > > Quoting Eric Berger : > > > Martin writes

Re: [R] date

2019-12-19 Thread Enrico Schumann
Quoting Eric Berger : Martin writes: "there's really no reason for going beyond base R" I disagree. Lubridate is a fantastic package. I use it all the time. It makes working with dates really easy, as evidenced by John Kane's suggestion. I strongly recommend learning to work with it. The bo

Re: [R] date

2019-12-19 Thread Eric Berger
Martin writes: "there's really no reason for going beyond base R" I disagree. Lubridate is a fantastic package. I use it all the time. It makes working with dates really easy, as evidenced by John Kane's suggestion. I strongly recommend learning to work with it. The bottom line: as is often the

Re: [R] date

2019-12-19 Thread Martin Maechler
> John Kane > on Tue, 17 Dec 2019 20:28:17 -0500 writes: > library(lubridate) > gs$dat1 <- mdy(gs$date) there's really no reason for going beyond base R. Using the proper format as per Patrick and Peter's advice (below) is perfectly clear and actually more robust (for the

Re: [R] date

2019-12-17 Thread John Kane
library(lubridate) gs$dat1 <- mdy(gs$date) On Tue, 17 Dec 2019 at 18:38, peter dalgaard wrote: > > ...and switch the order, and use %y for 2-digit years. > > > On 17 Dec 2019, at 23:57 , Patrick (Malone Quantitative) > > wrote: > > > > Try putting / instead of - in your format, to match the d

Re: [R] date

2019-12-17 Thread peter dalgaard
...and switch the order, and use %y for 2-digit years. > On 17 Dec 2019, at 23:57 , Patrick (Malone Quantitative) > wrote: > > Try putting / instead of - in your format, to match the data. > > On Tue, Dec 17, 2019 at 5:52 PM Val wrote: >> >> Hi All, >> >> I wanted to to convert character da

Re: [R] date

2019-12-17 Thread Patrick (Malone Quantitative)
Try putting / instead of - in your format, to match the data. On Tue, Dec 17, 2019 at 5:52 PM Val wrote: > > Hi All, > > I wanted to to convert character date mm/dd/yy to -mm-dd > The sample data and my attempt is shown below > > gs <-read.table(text="ID date > A1 09/27/03 > A2 05/27/16

[R] date

2019-12-17 Thread Val
Hi All, I wanted to to convert character date mm/dd/yy to -mm-dd The sample data and my attempt is shown below gs <-read.table(text="ID date A1 09/27/03 A2 05/27/16 A3 01/25/13 A4 09/27/19",header=TRUE,stringsAsFactors=F) Desired output ID date d1 A1 09/27/03 2003-09-27

[R] Date Time Conversion

2019-05-08 Thread reichmanj
r-Help Community Never mine figured it out just use the "as.POSIXct" function Jeff I need to convert a date-time field (column) but I'm losing the time when I convert using .. tsData <- myData[,10, drop=FALSE] tsData$date_time <- as.Date(tsData$date_time, format="%m/%d/%y %H:%M"

Re: [R] Date Time Conversion

2019-05-08 Thread Rui Barradas
Hello, as.Date() outputs an object of class "Date", you want an object of class c("POSIXt", "POSIXct"). Use as.POSIXct(). Hope this helps, Rui Barradas Às 16:04 de 08/05/19, reichm...@sbcglobal.net escreveu: r-Help Community I need to convert a date-time field (column) but I'm losing

[R] Date Time Conversion

2019-05-08 Thread reichmanj
r-Help Community I need to convert a date-time field (column) but I'm losing the time when I convert using .. tsData <- myData[,10, drop=FALSE] tsData$date_time <- as.Date(tsData$date_time, format="%m/%d/%y %H:%M") head(tsData) date_time 1 2013-06-20

Re: [R] date and time data on x axis

2018-11-03 Thread snowball0916
Hi, Bert I will check those two, by the way, how can you find the two function? have you used them before? Thanks very much. From: Bert Gunter Date: 2018-11-04 10:07 To: snowball0916 CC: MacQueen, Don; R-help Subject: Re: [R] date and time data on x axis See ?identify and ?locator Cheers

Re: [R] date and time data on x axis

2018-11-03 Thread Bert Gunter
e other way to get the same goal? > > Thanks very much. > > > > > > From: MacQueen, Don > Date: 2018-10-30 00:01 > To: snowball0916; r-help > Subject: Re: [R] date and time data on x axis > Here's an example of 24 hours of data at one second intervals. > &g

Re: [R] date and time data on x axis

2018-11-03 Thread snowball0916
hanks very much. From: MacQueen, Don Date: 2018-10-30 00:01 To: snowball0916; r-help Subject: Re: [R] date and time data on x axis Here's an example of 24 hours of data at one second intervals. npts <- 24*60*60 df <- data.frame( tm = seq( Sys.time(), by

Re: [R] date and time data on x axis

2018-10-30 Thread snowball0916
Hi, Don I got it, I will try and study . Thanks very much. From: MacQueen, Don Date: 2018-10-30 00:01 To: snowball0916; r-help Subject: Re: [R] date and time data on x axis Here's an example of 24 hours of data at one second intervals. npts <- 24*60*60 df <-

Re: [R] date and time data on x axis

2018-10-30 Thread snowball0916
Hi, Rui Thank you . I will try later. Thanks again. From: Rui Barradas Date: 2018-10-30 00:38 To: snowball0916; r-help Subject: Re: [R] date and time data on x axis Hello, Inline. Às 14:03 de 29/10/2018, snowball0916 escreveu: > Hi, Rui > Thanks for your code, even though I

Re: [R] date and time data on x axis

2018-10-29 Thread Rui Barradas
*From:* Rui Barradas <mailto:ruipbarra...@sapo.pt> *Date:* 2018-10-29 02:53 *To:* snowball0916 <mailto:snowball0...@163.com>; r-help <mailto:r-help@r-project.org> *Subject:* Re: [R] date and time data on x axis Hello, Maybe y

Re: [R] date and time data on x axis

2018-10-29 Thread MacQueen, Don via R-help
Here's an example of 24 hours of data at one second intervals. npts <- 24*60*60 df <- data.frame( tm = seq( Sys.time(), by='1 sec', length=npts), yd = round(runif(npts),2) ) head(df) with(df, plot(tm,yd)) The x axis appears to me to be display

Re: [R] date and time data on x axis

2018-10-29 Thread snowball0916
Hi, Jim Thanks very much, I will need to study your code, though. Will large volume of data will affect the x axis display? Thanks again. From: jim holtman Date: 2018-10-29 05:53 To: snowball0916 CC: R mailing list Subject: Re: [R] date and time data on x axis You need to specify what the

Re: [R] date and time data on x axis

2018-10-29 Thread snowball0916
d help(POSIXct) and not found the actual use. Thanks very much. From: Rui Barradas Date: 2018-10-29 02:53 To: snowball0916; r-help Subject: Re: [R] date and time data on x axis Hello, Maybe you could get some inspiration in the following code. op <- par(mar = c(4, 0, 0, 0) + par(&

Re: [R] date and time data on x axis

2018-10-28 Thread jim holtman
You need to specify what the format of the date will be. I am using ggplot for the plot: library(lubridate) library(tidyverse) mydata <- read.table(text = "time value 20181028_10:00:00 600 20181028_10:00:01 500 20181028_10:00:02 450 20181028_10:00:03 660", header = TR

Re: [R] date and time data on x axis

2018-10-28 Thread Rui Barradas
Hello, Maybe you could get some inspiration in the following code. op <- par(mar = c(4, 0, 0, 0) + par("mar")) plot(xdata, ydata, type = "o", xaxt = "n") axis.POSIXct(1, xdata, at = xdata, labels = xdata, las = 2) par(op) The important part is the call axis.POSIXct, argument las = 2 and the

[R] date and time data on x axis

2018-10-28 Thread snowball0916
Hi, guys How do you guys deal with the date and time data on x axis? I have some trouble with it. Could you help with this? = Sample Data = The sample data look like this: 20181028_10:00:00 600 20181028_10:00:01 500 20181028_10:00:02 450 20181028_10:00:03 660 .. ==

Re: [R] R Date Time

2017-04-25 Thread Dirk Eddelbuettel
On 25 April 2017 at 18:05, Duncan Murdoch wrote: | On 25/04/2017 5:41 PM, Dirk Eddelbuettel wrote: | > | > On 25 April 2017 at 16:04, Jeff Reichman wrote: | > | R Users | > | | > | Having problems converting the following DTG into an R recognized date/time | > | field | > | | > | 01-01-2016T14:02

Re: [R] R Date Time

2017-04-25 Thread Duncan Murdoch
On 25/04/2017 5:41 PM, Dirk Eddelbuettel wrote: On 25 April 2017 at 16:04, Jeff Reichman wrote: | R Users | | Having problems converting the following DTG into an R recognized date/time | field | | 01-01-2016T14:02:23.325 | | Would I separate it into a date field and time filed then put it back

Re: [R] R Date Time

2017-04-25 Thread Dirk Eddelbuettel
On 25 April 2017 at 16:04, Jeff Reichman wrote: | R Users | | Having problems converting the following DTG into an R recognized date/time | field | | 01-01-2016T14:02:23.325 | | Would I separate it into a date field and time filed then put it back | together??? The anytime package (on CRAN) do

Re: [R] R Date Time

2017-04-25 Thread William Dunlap via R-help
> z <- as.POSIXct("01-01-2016T14:02:23.325", format="%d-%m-%YT%H:%M:%OS") > dput(z) structure(1451685743.325, class = c("POSIXct", "POSIXt"), tzone = "") > z [1] "2016-01-01 14:02:23 PST" > format(z, "%H:%M:%OS3 on %b %d, %Y") [1] "14:02:23.325 on Jan 01, 2016" (Don't separate the date and time pa

Re: [R] R Date Time

2017-04-25 Thread Duncan Murdoch
On 25/04/2017 5:04 PM, Jeff Reichman wrote: R Users Having problems converting the following DTG into an R recognized date/time field 01-01-2016T14:02:23.325 Would I separate it into a date field and time filed then put it back together??? This appears to work (though I'm not sure whe

[R] R Date Time

2017-04-25 Thread Jeff Reichman
R Users Having problems converting the following DTG into an R recognized date/time field 01-01-2016T14:02:23.325 Would I separate it into a date field and time filed then put it back together??? Jeff [[alternative HTML version deleted]] __

Re: [R] Date operation Question in R

2017-03-31 Thread David Winsemius
> On Mar 30, 2017, at 3:16 PM, Thomas Petzoldt wrote: > > On 30.03.2017 23:34, Paul Bernal wrote: >> Hello everyone, >> >> Is there a way to use the function seq to generate a date sequence in >> this kind of format: jan-2007? > > format(seq(ISOdate(2017,1,1), ISOdate(2017,12,31), "months"), "

  1   2   3   4   5   >