Re: [R] strptime, date and conversion of week number into POSIX

2021-02-22 Thread PIKAL Petr
Hallo Patrick

I found quite usefull for working with weeks package ISOweek

https://cran.r-project.org/web/packages/ISOweek/index.html

Cheers.
Petr
> -Original Message-
> From: R-help  On Behalf Of Patrick
> Giraudoux
> Sent: Monday, February 22, 2021 5:24 PM
> To: Uwe Ligges ; R mailing list  project.org>; Bert Gunter 
> Subject: Re: [R] strptime, date and conversion of week number into POSIX
> 
> Thanks Uwe and  Bert,
> I got the essential now, and can manage. Date handling stays quite a
> challenge with a variable number of weeks in a year, but I can understand
> why. Means eye-control (or NA detection) of strptime conversion stays
> necessary...
> Best,
> Patrick
> 
> 
> Le 22/02/2021 à 17:09, Uwe Ligges a écrit :
> > That monday does not exist. FOr the week before:
> >
> > strptime(paste0("2020-52","-1"),format="%Y-%W-%u")
> > [1] "2020-12-28"
> >
> > One week later is no longer in 2020, so there is no 53th week.
> >
> > Best,
> > Uwe Ligges
> >
> >
> >
> >
> >
> > On 22.02.2021 16:15, Patrick Giraudoux wrote:
> >> Sorry to answer to myself, but the format was clearly incorrect in
> >> the previous post. It should read, refering to the 1th day of the week:
> >>
> >> strptime(paste0(mydate,"-1"),format="%Y-%W-%u")
> >>
> >> It converts better, but with a NA on week 53
> >>
> >>> strptime(paste0(pays$year_week,"-1"),format="%Y-%W-%u")
> >>[1] "2020-01-06 CET"  "2020-01-13 CET"  "2020-01-20 CET"
> >> "2020-01-27 CET"
> >>[5] "2020-02-03 CET"  "2020-02-10 CET"  "2020-02-17 CET"
> >> "2020-02-24 CET"
> >>[9] "2020-03-02 CET"  "2020-03-09 CET"  "2020-03-16 CET"
> >> "2020-03-23 CET"
> >> [13] "2020-03-30 CEST" "2020-04-06 CEST" "2020-04-13 CEST"
> >> "2020-04-20 CEST"
> >> [17] "2020-04-27 CEST" "2020-05-04 CEST" "2020-05-11 CEST"
> >> "2020-05-18 CEST"
> >> [21] "2020-05-25 CEST" "2020-06-01 CEST" "2020-06-08 CEST"
> >> "2020-06-15 CEST"
> >> [25] "2020-06-22 CEST" "2020-06-29 CEST" "2020-07-06 CEST"
> >> "2020-07-13 CEST"
> >> [29] "2020-07-20 CEST" "2020-07-27 CEST" "2020-08-03 CEST"
> >> "2020-08-10 CEST"
> >> [33] "2020-08-17 CEST" "2020-08-24 CEST" "2020-08-31 CEST"
> >> "2020-09-07 CEST"
> >> [37] "2020-09-14 CEST" "2020-09-21 CEST" "2020-09-28 CEST"
> >> "2020-10-05 CEST"
> >> [41] "2020-10-12 CEST" "2020-10-19 CEST" "2020-10-26 CET" "2020-11-02
> >> CET"
> >> [45] "2020-11-09 CET"  "2020-11-16 CET"  "2020-11-23 CET" "2020-11-30
> >> CET"
> >> [49] "2020-12-07 CET"  "2020-12-14 CET"  "2020-12-21 CET" "2020-12-28
> >> CET"
> >> [53] NA"2021-01-04 CET"  "2021-01-11 CET" "2021-01-18
> >> CET"
> >> [57] "2021-01-25 CET"  "2021-02-01 CET"  "2021-02-08 CET"
> >> Warning message:
> >> In strptime(paste0(pays$year_week, "-1"), format = "%Y-%W-%u") :
> >> (0-based) yday 369 in year 2020 is invalid
> >>
> >>
> >> Any idea on how to handle this ?
> >>
> >>
> >>
> >>
> >> Le 22/02/2021 à 15:26, Patrick Giraudoux a écrit :
> >>>
> >>> Dear all,
> >>>
> >>> I have a trouble trying to convert dates  given in character to POSIX.
> >>> The date is expressed as a year then the week number e.g. "2020-01"
> >>> (first week of 2020). I thought is can be converted as following:
> >>>
> >>> strptime(mydate,format="%Y-%W")
> >>>
> >>> %W refering to the week of the year as decimal number (00–53) using
> >>> Monday as the first day of week (and typically with the first Monday
> >>> of the year as day 1 of week 1), as indicated in the doc.
> >>>
> >>> However, I got this result, with the month fixed to 02 (february)
> >>> and day 22 (only the year is  converted correctly):
> >>>
> >>> strptime(mydate,format="%Y-%W") [1] "2020-02-22 CET" "2020-02-22
> CET"
> >>> "2020-02-22 CET" "2020-02-22 CET" [5] "2020-02-22 CET" "2020-02-22
> >>> CET" "2020-02-22 CET" "2020-02-22 CET" [9] "2020-02-22 CET"
> >>> "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" [13] "2020-02-22
> >>> CET" "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" [17]
> >>> "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET"
> >>> [21] "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" "2020-02-22
> >>> CET" [25] "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET"
> >>> "2020-02-22 CET" [29] "2020-02-22 CET" "2020-02-22 CET" "2020-02-22
> >>> CET" "2020-02-22 CET" [33] "2020-02-22 CET" "2020-02-22 CET"
> >>> "2020-02-22 CET" "2020-02-22 CET" [37] "2020-02-22 CET" "2020-02-22
> >>> CET" "2020-02-22 CET" "2020-02-22 CET" [41] "2020-02-22 CET"
> >>> "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" [45] "2020-02-22
> >>> CET" "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" [49]
> >>> "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET"
> >>> [53] "2020-02-22 CET" "2021-02-22 CET" "2021-02-22 CET" "2021-02-22
> >>> CET" [57] "2021-02-22 CET" "2021-02-22 CET" "2021-02-22 CET"
> >>>
> >>> You'll find below a dump of "mydate" you can copy and paster if you
> >>> need a try
> >>>
> >>> Any hint welcome...
> >>>
> >>> Best,
> >>>
> >>> Patrick
> >>>
> >>> mydate <-
> >>> c("2020-01", "2020-02", "2

Re: [R] Read

2021-02-22 Thread jim holtman
This gives the desired output:

> library(tidyverse)
> text <-  "x1  x2  x3 x4\n1 B12 \n2   C23 \n322 B32  D34 \n4   
>  D44 \n51 D53\n60 D62 "
>
> # read in the data as characters and split to a list
> input <- str_split(str_trim(read_lines(text)), ' +')
>
> max_cols <- 4  # assume a max of 4 columns
>
> put data in the correct column
> x_matrix <- do.call(rbind, map(input, ~{
+   result <- character(max_cols)
+   result[1] <- .x[1]
+   for (i in 2:length(.x)){
+ result[as.integer(str_sub(.x[i], -1))] <- .x[i]
+   }
+   result
+ }))
>
> # now add commas to convert to CSV
> x_csv <- apply(x_matrix, 1, paste, collapse = ',')
>
> # now read in and create desired output
> read_csv(x_csv)
# A tibble: 6 x 4
 x1 x2x3x4
 
1 1 B12 
2 2   C23   
3   322 B32 D34
4 4 D44
551   D53   
660 D62 
>



Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.


Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.


On Mon, Feb 22, 2021 at 6:20 PM Avi Gross via R-help
 wrote:
>
> This discussion is a bit weird so can we step back.
>
> Someone wants help on how to read in a file that apparently was not written
> following one of several consistent sets of rules.
>
> If it was fixed width, R has functions that can read that.
>
> If it was separated by commas, tabs, single spaces, arbitrary whitespace,
> with or without a header line, we have functions that can read that if
> properly called.
>
> ALL the above normally assume that all the resulting columns are the same
> length. If any are meant to be shorter, you still leave the separators in
> place and put some NA or similar into the result. And, the functions we
> normally talk about do NOT read in and produce multiple vectors but
> something like a data.frame.
>
> So the choice is either to make sure the darn data is in a consistent
> format, or try a different plan. Fair enough?
>
> Some are suggesting parsing it yourself line by line. Certainly that can be
> done. But unless you know some schema to help you disambiguate, what do you
> do it you reach a row that is too short and has enough data for two columns.
> Which of the columns do you assign it to? If you had a clear rule, ...
>
> And what if you have different data types? R does not handle that within a
> single vector or row of a data.frame, albeit it can if you make it a list
> column.
>
> If this data is a one-time thing, perhaps it should be copied into something
> like EXCEL by a human and edited so every column is filled as you wish and
> THEN saved as something like a CSV file and then it can happily be imported
> the usual way, including NA values as needed.
>
> If the person really wants 4 independent vectors of different lengths to
> read in, there are plenty of ways to do that and no need to lump them in
> this odd format.
>
>
>
> -Original Message-
> From: R-help  On Behalf Of jim holtman
> Sent: Monday, February 22, 2021 9:01 PM
> To: Jeff Newmiller 
> Cc: r-help@R-project.org (r-help@r-project.org) 
> Subject: Re: [R] Read
>
> It looks like we can look at the last digit of the data and that would be
> the column number; is that correct?
>
> Jim Holtman
> Data Munger Guru
>
> What is the problem that you are trying to solve?
> Tell me what you want to do, not how you want to do it.
>
>
> Jim Holtman
> Data Munger Guru
>
> What is the problem that you are trying to solve?
> Tell me what you want to do, not how you want to do it.
>
>
> On Mon, Feb 22, 2021 at 5:34 PM Jeff Newmiller 
> wrote:
> >
> > This gets it into a data frame. If you know which columns should be
> numeric you can convert them.
> >
> > s <-
> > "x1  x2  x3 x4
> > 1 B22
> > 2 C33
> > 322 B22  D34
> > 4 D44
> > 51 D53
> > 60 D62
> > "
> >
> > tc <- textConnection( s )
> > lns <- readLines(tc)
> > close(tc)
> > if ( "" == lns[ length( lns ) ] )
> >   lns <- lns[ -length( lns ) ]
> >
> > L <- strsplit( lns, " +" )
> > m <- do.call( rbind, lapply( L[-1], function(v) if
> > (length(v) > ) else v ) ) colnames( m ) <- L[[1]] result <- as.data.frame( m,
> > stringsAsFactors = FALSE ) result
> >
> > On February 22, 2021 4:42:57 PM PST, Val  wrote:
> > >That is my problem. The spacing between columns is not consistent.
> > >It
> > >  may be  single space  or multiple spaces (two or three).
> > >
> > >On Mon, Feb 22, 2021 at 6:14 PM Bill Dunlap
> > >
> > >wrote:
> > >>
> > >> You said the column values were separated by space characters.
> > >> Copying the text from gmail shows that some column names and column
> > >> values are separated by single spaces (e.g., between x1 and x2) and
> > >> some by multiple spaces (e.g., between x3 and x4.  Did the mail
> > >> mess up the spacing or is there some other way to tell where the
> > >> omitted values are?
> > >>
> 

Re: [R] Read

2021-02-22 Thread Avi Gross via R-help
This discussion is a bit weird so can we step back.

Someone wants help on how to read in a file that apparently was not written
following one of several consistent sets of rules.

If it was fixed width, R has functions that can read that.

If it was separated by commas, tabs, single spaces, arbitrary whitespace,
with or without a header line, we have functions that can read that if
properly called.

ALL the above normally assume that all the resulting columns are the same
length. If any are meant to be shorter, you still leave the separators in
place and put some NA or similar into the result. And, the functions we
normally talk about do NOT read in and produce multiple vectors but
something like a data.frame.

So the choice is either to make sure the darn data is in a consistent
format, or try a different plan. Fair enough?

Some are suggesting parsing it yourself line by line. Certainly that can be
done. But unless you know some schema to help you disambiguate, what do you
do it you reach a row that is too short and has enough data for two columns.
Which of the columns do you assign it to? If you had a clear rule, ...

And what if you have different data types? R does not handle that within a
single vector or row of a data.frame, albeit it can if you make it a list
column.

If this data is a one-time thing, perhaps it should be copied into something
like EXCEL by a human and edited so every column is filled as you wish and
THEN saved as something like a CSV file and then it can happily be imported
the usual way, including NA values as needed. 

If the person really wants 4 independent vectors of different lengths to
read in, there are plenty of ways to do that and no need to lump them in
this odd format.



-Original Message-
From: R-help  On Behalf Of jim holtman
Sent: Monday, February 22, 2021 9:01 PM
To: Jeff Newmiller 
Cc: r-help@R-project.org (r-help@r-project.org) 
Subject: Re: [R] Read

It looks like we can look at the last digit of the data and that would be
the column number; is that correct?

Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.


Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.


On Mon, Feb 22, 2021 at 5:34 PM Jeff Newmiller 
wrote:
>
> This gets it into a data frame. If you know which columns should be
numeric you can convert them.
>
> s <-
> "x1  x2  x3 x4
> 1 B22
> 2 C33
> 322 B22  D34
> 4 D44
> 51 D53
> 60 D62
> "
>
> tc <- textConnection( s )
> lns <- readLines(tc)
> close(tc)
> if ( "" == lns[ length( lns ) ] )
>   lns <- lns[ -length( lns ) ]
>
> L <- strsplit( lns, " +" )
> m <- do.call( rbind, lapply( L[-1], function(v) if 
> (length(v) ) else v ) ) colnames( m ) <- L[[1]] result <- as.data.frame( m, 
> stringsAsFactors = FALSE ) result
>
> On February 22, 2021 4:42:57 PM PST, Val  wrote:
> >That is my problem. The spacing between columns is not consistent.  
> >It
> >  may be  single space  or multiple spaces (two or three).
> >
> >On Mon, Feb 22, 2021 at 6:14 PM Bill Dunlap 
> >
> >wrote:
> >>
> >> You said the column values were separated by space characters.
> >> Copying the text from gmail shows that some column names and column 
> >> values are separated by single spaces (e.g., between x1 and x2) and 
> >> some by multiple spaces (e.g., between x3 and x4.  Did the mail 
> >> mess up the spacing or is there some other way to tell where the 
> >> omitted values are?
> >>
> >> -Bill
> >>
> >> On Mon, Feb 22, 2021 at 2:54 PM Val  wrote:
> >> >
> >> > I Tried that one and it did not work. Please see the error message
> >> > Error in read.table(text = "x1  x2  x3 x4\n1 B12 \n2   C23
> >> > \n322 B32  D34 \n4D44 \n51 D53\n60 D62
> >",
> >> > :
> >> >   more columns than column names
> >> >
> >> > On Mon, Feb 22, 2021 at 5:39 PM Bill Dunlap
> > wrote:
> >> > >
> >> > > Since the columns in the file are separated by a space 
> >> > > character,
> >" ",
> >> > > add the read.table argument sep=" ".
> >> > >
> >> > > -Bill
> >> > >
> >> > > On Mon, Feb 22, 2021 at 2:21 PM Val  wrote:
> >> > > >
> >> > > > Hi all, I am trying to read a messy data  but facing
> >difficulty.  The
> >> > > > data has several columns separated by blank space(s).  Each
> >column
> >> > > > value may have different lengths across the rows.   The first
> >> > > > row(header) has four columns. However, each row may not have
> >the four
> >> > > > column values.  For instance, the first data row has only the
> >first
> >> > > > two column values. The fourth data row has the first and last
> >column
> >> > > > values, the second and the third column values are missing 
> >> > > > for
> >this
> >> > > > row..  How do I read this data set correctly? Here is my 
> >> > > > sample
> >data
> >> > > > set, output and desired output.   To make it clear to each data
> >poin

Re: [R] Read

2021-02-22 Thread jim holtman
It looks like we can look at the last digit of the data and that would
be the column number; is that correct?

Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.


Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.


On Mon, Feb 22, 2021 at 5:34 PM Jeff Newmiller  wrote:
>
> This gets it into a data frame. If you know which columns should be numeric 
> you can convert them.
>
> s <-
> "x1  x2  x3 x4
> 1 B22
> 2 C33
> 322 B22  D34
> 4 D44
> 51 D53
> 60 D62
> "
>
> tc <- textConnection( s )
> lns <- readLines(tc)
> close(tc)
> if ( "" == lns[ length( lns ) ] )
>   lns <- lns[ -length( lns ) ]
>
> L <- strsplit( lns, " +" )
> m <- do.call( rbind, lapply( L[-1], function(v) if (length(v) c( v, rep(NA, length(L[[1]]) - length(v) ) ) else v ) )
> colnames( m ) <- L[[1]]
> result <- as.data.frame( m, stringsAsFactors = FALSE )
> result
>
> On February 22, 2021 4:42:57 PM PST, Val  wrote:
> >That is my problem. The spacing between columns is not consistent.  It
> >  may be  single space  or multiple spaces (two or three).
> >
> >On Mon, Feb 22, 2021 at 6:14 PM Bill Dunlap 
> >wrote:
> >>
> >> You said the column values were separated by space characters.
> >> Copying the text from gmail shows that some column names and column
> >> values are separated by single spaces (e.g., between x1 and x2) and
> >> some by multiple spaces (e.g., between x3 and x4.  Did the mail mess
> >> up the spacing or is there some other way to tell where the omitted
> >> values are?
> >>
> >> -Bill
> >>
> >> On Mon, Feb 22, 2021 at 2:54 PM Val  wrote:
> >> >
> >> > I Tried that one and it did not work. Please see the error message
> >> > Error in read.table(text = "x1  x2  x3 x4\n1 B12 \n2   C23
> >> > \n322 B32  D34 \n4D44 \n51 D53\n60 D62
> >",
> >> > :
> >> >   more columns than column names
> >> >
> >> > On Mon, Feb 22, 2021 at 5:39 PM Bill Dunlap
> > wrote:
> >> > >
> >> > > Since the columns in the file are separated by a space character,
> >" ",
> >> > > add the read.table argument sep=" ".
> >> > >
> >> > > -Bill
> >> > >
> >> > > On Mon, Feb 22, 2021 at 2:21 PM Val  wrote:
> >> > > >
> >> > > > Hi all, I am trying to read a messy data  but facing
> >difficulty.  The
> >> > > > data has several columns separated by blank space(s).  Each
> >column
> >> > > > value may have different lengths across the rows.   The first
> >> > > > row(header) has four columns. However, each row may not have
> >the four
> >> > > > column values.  For instance, the first data row has only the
> >first
> >> > > > two column values. The fourth data row has the first and last
> >column
> >> > > > values, the second and the third column values are missing for
> >this
> >> > > > row..  How do I read this data set correctly? Here is my sample
> >data
> >> > > > set, output and desired output.   To make it clear to each data
> >point
> >> > > > I have added the row and column numbers. I cannot use fixed
> >width
> >> > > > format reading because each row  may have different length for
> >a
> >> > > > given column.
> >> > > >
> >> > > > dat<-read.table(text="x1  x2  x3 x4
> >> > > > 1 B22
> >> > > > 2 C33
> >> > > > 322 B22  D34
> >> > > > 4 D44
> >> > > > 51 D53
> >> > > > 60 D62",header=T, fill=T,na.strings=c("","NA"))
> >> > > >
> >> > > > Output
> >> > > >   x1  x2 x3 x4
> >> > > > 1   1 B12  NA
> >> > > > 2   2C23   NA
> >> > > > 3 322  B32  D34   NA
> >> > > > 4   4   D44NA
> >> > > > 5  51 D53 NA
> >> > > > 6  60 D62NA
> >> > > >
> >> > > >
> >> > > > Desired output
> >> > > >x1   x2 x3   x4
> >> > > > 1   1B22   NA
> >> > > > 2   2 C33 NA
> >> > > > 3 322  B32NA  D34
> >> > > > 4   4  NA  D44
> >> > > > 5  51D53 NA
> >> > > > 6  60   D62  NA
> >> > > >
> >> > > > Thank you,
> >> > > >
> >> > > > __
> >> > > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more,
> >see
> >> > > > https://stat.ethz.ch/mailman/listinfo/r-help
> >> > > > PLEASE do read the posting guide
> >http://www.R-project.org/posting-guide.html
> >> > > > and provide commented, minimal, self-contained, reproducible
> >code.
> >
> >__
> >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >https://stat.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide
> >http://www.R-project.org/posting-guide.html
> >and provide commented, minimal, self-contained, reproducible code.
>
> --
> Sent from my phone. Please excuse my brevity.
> --
> Sent from my phone. Please excuse my brevity.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https:

Re: [R] Read

2021-02-22 Thread Jeff Newmiller
This gets it into a data frame. If you know which columns should be numeric you 
can convert them.

s <- 
"x1  x2  x3 x4
1 B22
2 C33
322 B22  D34
4 D44
51 D53
60 D62
"

tc <- textConnection( s )
lns <- readLines(tc)
close(tc)
if ( "" == lns[ length( lns ) ] )
  lns <- lns[ -length( lns ) ]

L <- strsplit( lns, " +" )
m <- do.call( rbind, lapply( L[-1], function(v) if (length(v) wrote:
>That is my problem. The spacing between columns is not consistent.  It
>  may be  single space  or multiple spaces (two or three).
>
>On Mon, Feb 22, 2021 at 6:14 PM Bill Dunlap 
>wrote:
>>
>> You said the column values were separated by space characters.
>> Copying the text from gmail shows that some column names and column
>> values are separated by single spaces (e.g., between x1 and x2) and
>> some by multiple spaces (e.g., between x3 and x4.  Did the mail mess
>> up the spacing or is there some other way to tell where the omitted
>> values are?
>>
>> -Bill
>>
>> On Mon, Feb 22, 2021 at 2:54 PM Val  wrote:
>> >
>> > I Tried that one and it did not work. Please see the error message
>> > Error in read.table(text = "x1  x2  x3 x4\n1 B12 \n2   C23
>> > \n322 B32  D34 \n4D44 \n51 D53\n60 D62
>",
>> > :
>> >   more columns than column names
>> >
>> > On Mon, Feb 22, 2021 at 5:39 PM Bill Dunlap
> wrote:
>> > >
>> > > Since the columns in the file are separated by a space character,
>" ",
>> > > add the read.table argument sep=" ".
>> > >
>> > > -Bill
>> > >
>> > > On Mon, Feb 22, 2021 at 2:21 PM Val  wrote:
>> > > >
>> > > > Hi all, I am trying to read a messy data  but facing 
>difficulty.  The
>> > > > data has several columns separated by blank space(s).  Each
>column
>> > > > value may have different lengths across the rows.   The first
>> > > > row(header) has four columns. However, each row may not have
>the four
>> > > > column values.  For instance, the first data row has only the
>first
>> > > > two column values. The fourth data row has the first and last
>column
>> > > > values, the second and the third column values are missing for
>this
>> > > > row..  How do I read this data set correctly? Here is my sample
>data
>> > > > set, output and desired output.   To make it clear to each data
>point
>> > > > I have added the row and column numbers. I cannot use fixed
>width
>> > > > format reading because each row  may have different length for 
>a
>> > > > given column.
>> > > >
>> > > > dat<-read.table(text="x1  x2  x3 x4
>> > > > 1 B22
>> > > > 2 C33
>> > > > 322 B22  D34
>> > > > 4 D44
>> > > > 51 D53
>> > > > 60 D62",header=T, fill=T,na.strings=c("","NA"))
>> > > >
>> > > > Output
>> > > >   x1  x2 x3 x4
>> > > > 1   1 B12  NA
>> > > > 2   2C23   NA
>> > > > 3 322  B32  D34   NA
>> > > > 4   4   D44NA
>> > > > 5  51 D53 NA
>> > > > 6  60 D62NA
>> > > >
>> > > >
>> > > > Desired output
>> > > >x1   x2 x3   x4
>> > > > 1   1B22   NA
>> > > > 2   2 C33 NA
>> > > > 3 322  B32NA  D34
>> > > > 4   4  NA  D44
>> > > > 5  51D53 NA
>> > > > 6  60   D62  NA
>> > > >
>> > > > Thank you,
>> > > >
>> > > > __
>> > > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more,
>see
>> > > > https://stat.ethz.ch/mailman/listinfo/r-help
>> > > > PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>> > > > and provide commented, minimal, self-contained, reproducible
>code.
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

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

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read

2021-02-22 Thread Val
Let us take the max space is two and the output should not be fixed
filed but preferable a csv file.

On Mon, Feb 22, 2021 at 8:05 PM jim holtman  wrote:
>
> Messed up did not see your 'desired' output which will be hard since there is 
> not a consistent number of spaces that would represent the desired column 
> number.  Do you have any hit as to how to interpret the spacing especially 
> you have several hundred more lines?  Is the output supposed to the 'fixed' 
> field?
>
> Jim Holtman
> Data Munger Guru
>
> What is the problem that you are trying to solve?
> Tell me what you want to do, not how you want to do it.
>
>
> On Mon, Feb 22, 2021 at 5:00 PM jim holtman  wrote:
>>
>> Try this:
>>
>> > library(tidyverse)
>>
>> > text <-  "x1  x2  x3 x4\n1 B12 \n2   C23 \n322 B32  D34 \n4
>> > D44 \n51 D53\n60 D62 "
>>
>> > # read in the data as characters and replace multiple blanks with single 
>> > blank
>> > input <- read_lines(text)
>>
>> > input <- str_replace_all(input, ' +', ' ')
>>
>> > mydata <- read_delim(input, ' ', col_names = TRUE)
>> Warning: 5 parsing failures.
>> row col  expectedactual file
>>   1  -- 4 columns 3 columns literal data
>>   2  -- 4 columns 3 columns literal data
>>   4  -- 4 columns 3 columns literal data
>>   5  -- 4 columns 2 columns literal data
>>   6  -- 4 columns 3 columns literal data
>>
>> > mydata
>> # A tibble: 6 x 4
>>  x1 x2x3x4
>>  
>> 1 1 B12   NANA
>> 2 2 C23   NANA
>> 3   322 B32   D34   NA
>> 4 4 D44   NANA
>> 551 D53   NANA
>> 660 D62   NANA
>> >
>>
>> Jim Holtman
>> Data Munger Guru
>>
>> What is the problem that you are trying to solve?
>> Tell me what you want to do, not how you want to do it.
>>
>>
>> Jim Holtman
>> Data Munger Guru
>>
>> What is the problem that you are trying to solve?
>> Tell me what you want to do, not how you want to do it.
>>
>>
>> On Mon, Feb 22, 2021 at 4:49 PM Val  wrote:
>>>
>>> That is my problem. The spacing between columns is not consistent.  It
>>>   may be  single space  or multiple spaces (two or three).
>>>
>>> On Mon, Feb 22, 2021 at 6:14 PM Bill Dunlap  
>>> wrote:
>>> >
>>> > You said the column values were separated by space characters.
>>> > Copying the text from gmail shows that some column names and column
>>> > values are separated by single spaces (e.g., between x1 and x2) and
>>> > some by multiple spaces (e.g., between x3 and x4.  Did the mail mess
>>> > up the spacing or is there some other way to tell where the omitted
>>> > values are?
>>> >
>>> > -Bill
>>> >
>>> > On Mon, Feb 22, 2021 at 2:54 PM Val  wrote:
>>> > >
>>> > > I Tried that one and it did not work. Please see the error message
>>> > > Error in read.table(text = "x1  x2  x3 x4\n1 B12 \n2   C23
>>> > > \n322 B32  D34 \n4D44 \n51 D53\n60 D62 ",
>>> > > :
>>> > >   more columns than column names
>>> > >
>>> > > On Mon, Feb 22, 2021 at 5:39 PM Bill Dunlap  
>>> > > wrote:
>>> > > >
>>> > > > Since the columns in the file are separated by a space character, " ",
>>> > > > add the read.table argument sep=" ".
>>> > > >
>>> > > > -Bill
>>> > > >
>>> > > > On Mon, Feb 22, 2021 at 2:21 PM Val  wrote:
>>> > > > >
>>> > > > > Hi all, I am trying to read a messy data  but facing  difficulty.  
>>> > > > > The
>>> > > > > data has several columns separated by blank space(s).  Each column
>>> > > > > value may have different lengths across the rows.   The first
>>> > > > > row(header) has four columns. However, each row may not have the 
>>> > > > > four
>>> > > > > column values.  For instance, the first data row has only the first
>>> > > > > two column values. The fourth data row has the first and last column
>>> > > > > values, the second and the third column values are missing for this
>>> > > > > row..  How do I read this data set correctly? Here is my sample data
>>> > > > > set, output and desired output.   To make it clear to each data 
>>> > > > > point
>>> > > > > I have added the row and column numbers. I cannot use fixed width
>>> > > > > format reading because each row  may have different length for  a
>>> > > > > given column.
>>> > > > >
>>> > > > > dat<-read.table(text="x1  x2  x3 x4
>>> > > > > 1 B22
>>> > > > > 2 C33
>>> > > > > 322 B22  D34
>>> > > > > 4 D44
>>> > > > > 51 D53
>>> > > > > 60 D62",header=T, fill=T,na.strings=c("","NA"))
>>> > > > >
>>> > > > > Output
>>> > > > >   x1  x2 x3 x4
>>> > > > > 1   1 B12  NA
>>> > > > > 2   2C23   NA
>>> > > > > 3 322  B32  D34   NA
>>> > > > > 4   4   D44NA
>>> > > > > 5  51 D53 NA
>>> > > > > 6  60 D62NA
>>> > > > >
>>> > > > >
>>> > > > > Desired output
>>> > > > >x1   x2 x3   x4
>>> > > > > 1   1B22   NA
>>> > > > > 2   2 C33 NA
>>> > > > > 3 322  B32NA  D34
>>> > > > > 4   4  NA  D44
>>> > > > > 5  51D53 NA
>>> > > > > 6  60   D62

Re: [R] Read

2021-02-22 Thread jim holtman
Messed up did not see your 'desired' output which will be hard since there
is not a consistent number of spaces that would represent the desired
column number.  Do you have any hit as to how to interpret the spacing
especially you have several hundred more lines?  Is the output supposed to
the 'fixed' field?

Jim Holtman
*Data Munger Guru*


*What is the problem that you are trying to solve?Tell me what you want to
do, not how you want to do it.*


On Mon, Feb 22, 2021 at 5:00 PM jim holtman  wrote:

> Try this:
>
> > library(tidyverse)
>
> > text <-  "x1  x2  x3 x4\n1 B12 \n2   C23 \n322 B32  D34 \n4
>D44 \n51 D53\n60 D62 "
>
> > # read in the data as characters and replace multiple blanks with single
> blank
> > input <- read_lines(text)
>
> > input <- str_replace_all(input, ' +', ' ')
>
> > mydata <- read_delim(input, ' ', col_names = TRUE)
> Warning: 5 parsing failures.
> row col  expectedactual file
>   1  -- 4 columns 3 columns literal data
>   2  -- 4 columns 3 columns literal data
>   4  -- 4 columns 3 columns literal data
>   5  -- 4 columns 2 columns literal data
>   6  -- 4 columns 3 columns literal data
>
> > mydata
> # A tibble: 6 x 4
>  x1 x2x3x4
>  
> 1 1 B12   NANA
> 2 2 C23   NANA
> 3   322 B32   D34   NA
> 4 4 D44   NANA
> 551 D53   NANA
> 660 D62   NANA
> >
>
> Jim Holtman
> Data Munger Guru
>
> What is the problem that you are trying to solve?
> Tell me what you want to do, not how you want to do it.
>
>
> Jim Holtman
> *Data Munger Guru*
>
>
> *What is the problem that you are trying to solve?Tell me what you want to
> do, not how you want to do it.*
>
>
> On Mon, Feb 22, 2021 at 4:49 PM Val  wrote:
>
>> That is my problem. The spacing between columns is not consistent.  It
>>   may be  single space  or multiple spaces (two or three).
>>
>> On Mon, Feb 22, 2021 at 6:14 PM Bill Dunlap 
>> wrote:
>> >
>> > You said the column values were separated by space characters.
>> > Copying the text from gmail shows that some column names and column
>> > values are separated by single spaces (e.g., between x1 and x2) and
>> > some by multiple spaces (e.g., between x3 and x4.  Did the mail mess
>> > up the spacing or is there some other way to tell where the omitted
>> > values are?
>> >
>> > -Bill
>> >
>> > On Mon, Feb 22, 2021 at 2:54 PM Val  wrote:
>> > >
>> > > I Tried that one and it did not work. Please see the error message
>> > > Error in read.table(text = "x1  x2  x3 x4\n1 B12 \n2   C23
>> > > \n322 B32  D34 \n4D44 \n51 D53\n60 D62 ",
>> > > :
>> > >   more columns than column names
>> > >
>> > > On Mon, Feb 22, 2021 at 5:39 PM Bill Dunlap 
>> wrote:
>> > > >
>> > > > Since the columns in the file are separated by a space character, "
>> ",
>> > > > add the read.table argument sep=" ".
>> > > >
>> > > > -Bill
>> > > >
>> > > > On Mon, Feb 22, 2021 at 2:21 PM Val  wrote:
>> > > > >
>> > > > > Hi all, I am trying to read a messy data  but facing
>> difficulty.  The
>> > > > > data has several columns separated by blank space(s).  Each column
>> > > > > value may have different lengths across the rows.   The first
>> > > > > row(header) has four columns. However, each row may not have the
>> four
>> > > > > column values.  For instance, the first data row has only the
>> first
>> > > > > two column values. The fourth data row has the first and last
>> column
>> > > > > values, the second and the third column values are missing for
>> this
>> > > > > row..  How do I read this data set correctly? Here is my sample
>> data
>> > > > > set, output and desired output.   To make it clear to each data
>> point
>> > > > > I have added the row and column numbers. I cannot use fixed width
>> > > > > format reading because each row  may have different length for  a
>> > > > > given column.
>> > > > >
>> > > > > dat<-read.table(text="x1  x2  x3 x4
>> > > > > 1 B22
>> > > > > 2 C33
>> > > > > 322 B22  D34
>> > > > > 4 D44
>> > > > > 51 D53
>> > > > > 60 D62",header=T, fill=T,na.strings=c("","NA"))
>> > > > >
>> > > > > Output
>> > > > >   x1  x2 x3 x4
>> > > > > 1   1 B12  NA
>> > > > > 2   2C23   NA
>> > > > > 3 322  B32  D34   NA
>> > > > > 4   4   D44NA
>> > > > > 5  51 D53 NA
>> > > > > 6  60 D62NA
>> > > > >
>> > > > >
>> > > > > Desired output
>> > > > >x1   x2 x3   x4
>> > > > > 1   1B22   NA
>> > > > > 2   2 C33 NA
>> > > > > 3 322  B32NA  D34
>> > > > > 4   4  NA  D44
>> > > > > 5  51D53 NA
>> > > > > 6  60   D62  NA
>> > > > >
>> > > > > Thank you,
>> > > > >
>> > > > > __
>> > > > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > > > > https://stat.ethz.ch/mailman/listinfo/r-help
>> > > > > PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>

Re: [R] Read

2021-02-22 Thread jim holtman
Try this:

> library(tidyverse)

> text <-  "x1  x2  x3 x4\n1 B12 \n2   C23 \n322 B32  D34 \n4
 D44 \n51 D53\n60 D62 "

> # read in the data as characters and replace multiple blanks with single
blank
> input <- read_lines(text)

> input <- str_replace_all(input, ' +', ' ')

> mydata <- read_delim(input, ' ', col_names = TRUE)
Warning: 5 parsing failures.
row col  expectedactual file
  1  -- 4 columns 3 columns literal data
  2  -- 4 columns 3 columns literal data
  4  -- 4 columns 3 columns literal data
  5  -- 4 columns 2 columns literal data
  6  -- 4 columns 3 columns literal data

> mydata
# A tibble: 6 x 4
 x1 x2x3x4
 
1 1 B12   NANA
2 2 C23   NANA
3   322 B32   D34   NA
4 4 D44   NANA
551 D53   NANA
660 D62   NANA
>

Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.


Jim Holtman
*Data Munger Guru*


*What is the problem that you are trying to solve?Tell me what you want to
do, not how you want to do it.*


On Mon, Feb 22, 2021 at 4:49 PM Val  wrote:

> That is my problem. The spacing between columns is not consistent.  It
>   may be  single space  or multiple spaces (two or three).
>
> On Mon, Feb 22, 2021 at 6:14 PM Bill Dunlap 
> wrote:
> >
> > You said the column values were separated by space characters.
> > Copying the text from gmail shows that some column names and column
> > values are separated by single spaces (e.g., between x1 and x2) and
> > some by multiple spaces (e.g., between x3 and x4.  Did the mail mess
> > up the spacing or is there some other way to tell where the omitted
> > values are?
> >
> > -Bill
> >
> > On Mon, Feb 22, 2021 at 2:54 PM Val  wrote:
> > >
> > > I Tried that one and it did not work. Please see the error message
> > > Error in read.table(text = "x1  x2  x3 x4\n1 B12 \n2   C23
> > > \n322 B32  D34 \n4D44 \n51 D53\n60 D62 ",
> > > :
> > >   more columns than column names
> > >
> > > On Mon, Feb 22, 2021 at 5:39 PM Bill Dunlap 
> wrote:
> > > >
> > > > Since the columns in the file are separated by a space character, "
> ",
> > > > add the read.table argument sep=" ".
> > > >
> > > > -Bill
> > > >
> > > > On Mon, Feb 22, 2021 at 2:21 PM Val  wrote:
> > > > >
> > > > > Hi all, I am trying to read a messy data  but facing  difficulty.
> The
> > > > > data has several columns separated by blank space(s).  Each column
> > > > > value may have different lengths across the rows.   The first
> > > > > row(header) has four columns. However, each row may not have the
> four
> > > > > column values.  For instance, the first data row has only the first
> > > > > two column values. The fourth data row has the first and last
> column
> > > > > values, the second and the third column values are missing for this
> > > > > row..  How do I read this data set correctly? Here is my sample
> data
> > > > > set, output and desired output.   To make it clear to each data
> point
> > > > > I have added the row and column numbers. I cannot use fixed width
> > > > > format reading because each row  may have different length for  a
> > > > > given column.
> > > > >
> > > > > dat<-read.table(text="x1  x2  x3 x4
> > > > > 1 B22
> > > > > 2 C33
> > > > > 322 B22  D34
> > > > > 4 D44
> > > > > 51 D53
> > > > > 60 D62",header=T, fill=T,na.strings=c("","NA"))
> > > > >
> > > > > Output
> > > > >   x1  x2 x3 x4
> > > > > 1   1 B12  NA
> > > > > 2   2C23   NA
> > > > > 3 322  B32  D34   NA
> > > > > 4   4   D44NA
> > > > > 5  51 D53 NA
> > > > > 6  60 D62NA
> > > > >
> > > > >
> > > > > Desired output
> > > > >x1   x2 x3   x4
> > > > > 1   1B22   NA
> > > > > 2   2 C33 NA
> > > > > 3 322  B32NA  D34
> > > > > 4   4  NA  D44
> > > > > 5  51D53 NA
> > > > > 6  60   D62  NA
> > > > >
> > > > > Thank you,
> > > > >
> > > > > __
> > > > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > > > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > > > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > > > > and provide commented, minimal, self-contained, reproducible code.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide

Re: [R] Read

2021-02-22 Thread Val
That is my problem. The spacing between columns is not consistent.  It
  may be  single space  or multiple spaces (two or three).

On Mon, Feb 22, 2021 at 6:14 PM Bill Dunlap  wrote:
>
> You said the column values were separated by space characters.
> Copying the text from gmail shows that some column names and column
> values are separated by single spaces (e.g., between x1 and x2) and
> some by multiple spaces (e.g., between x3 and x4.  Did the mail mess
> up the spacing or is there some other way to tell where the omitted
> values are?
>
> -Bill
>
> On Mon, Feb 22, 2021 at 2:54 PM Val  wrote:
> >
> > I Tried that one and it did not work. Please see the error message
> > Error in read.table(text = "x1  x2  x3 x4\n1 B12 \n2   C23
> > \n322 B32  D34 \n4D44 \n51 D53\n60 D62 ",
> > :
> >   more columns than column names
> >
> > On Mon, Feb 22, 2021 at 5:39 PM Bill Dunlap  
> > wrote:
> > >
> > > Since the columns in the file are separated by a space character, " ",
> > > add the read.table argument sep=" ".
> > >
> > > -Bill
> > >
> > > On Mon, Feb 22, 2021 at 2:21 PM Val  wrote:
> > > >
> > > > Hi all, I am trying to read a messy data  but facing  difficulty.  The
> > > > data has several columns separated by blank space(s).  Each column
> > > > value may have different lengths across the rows.   The first
> > > > row(header) has four columns. However, each row may not have the four
> > > > column values.  For instance, the first data row has only the first
> > > > two column values. The fourth data row has the first and last column
> > > > values, the second and the third column values are missing for this
> > > > row..  How do I read this data set correctly? Here is my sample data
> > > > set, output and desired output.   To make it clear to each data point
> > > > I have added the row and column numbers. I cannot use fixed width
> > > > format reading because each row  may have different length for  a
> > > > given column.
> > > >
> > > > dat<-read.table(text="x1  x2  x3 x4
> > > > 1 B22
> > > > 2 C33
> > > > 322 B22  D34
> > > > 4 D44
> > > > 51 D53
> > > > 60 D62",header=T, fill=T,na.strings=c("","NA"))
> > > >
> > > > Output
> > > >   x1  x2 x3 x4
> > > > 1   1 B12  NA
> > > > 2   2C23   NA
> > > > 3 322  B32  D34   NA
> > > > 4   4   D44NA
> > > > 5  51 D53 NA
> > > > 6  60 D62NA
> > > >
> > > >
> > > > Desired output
> > > >x1   x2 x3   x4
> > > > 1   1B22   NA
> > > > 2   2 C33 NA
> > > > 3 322  B32NA  D34
> > > > 4   4  NA  D44
> > > > 5  51D53 NA
> > > > 6  60   D62  NA
> > > >
> > > > Thank you,
> > > >
> > > > __
> > > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > > PLEASE do read the posting guide 
> > > > http://www.R-project.org/posting-guide.html
> > > > and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read

2021-02-22 Thread Bill Dunlap
You said the column values were separated by space characters.
Copying the text from gmail shows that some column names and column
values are separated by single spaces (e.g., between x1 and x2) and
some by multiple spaces (e.g., between x3 and x4.  Did the mail mess
up the spacing or is there some other way to tell where the omitted
values are?

-Bill

On Mon, Feb 22, 2021 at 2:54 PM Val  wrote:
>
> I Tried that one and it did not work. Please see the error message
> Error in read.table(text = "x1  x2  x3 x4\n1 B12 \n2   C23
> \n322 B32  D34 \n4D44 \n51 D53\n60 D62 ",
> :
>   more columns than column names
>
> On Mon, Feb 22, 2021 at 5:39 PM Bill Dunlap  wrote:
> >
> > Since the columns in the file are separated by a space character, " ",
> > add the read.table argument sep=" ".
> >
> > -Bill
> >
> > On Mon, Feb 22, 2021 at 2:21 PM Val  wrote:
> > >
> > > Hi all, I am trying to read a messy data  but facing  difficulty.  The
> > > data has several columns separated by blank space(s).  Each column
> > > value may have different lengths across the rows.   The first
> > > row(header) has four columns. However, each row may not have the four
> > > column values.  For instance, the first data row has only the first
> > > two column values. The fourth data row has the first and last column
> > > values, the second and the third column values are missing for this
> > > row..  How do I read this data set correctly? Here is my sample data
> > > set, output and desired output.   To make it clear to each data point
> > > I have added the row and column numbers. I cannot use fixed width
> > > format reading because each row  may have different length for  a
> > > given column.
> > >
> > > dat<-read.table(text="x1  x2  x3 x4
> > > 1 B22
> > > 2 C33
> > > 322 B22  D34
> > > 4 D44
> > > 51 D53
> > > 60 D62",header=T, fill=T,na.strings=c("","NA"))
> > >
> > > Output
> > >   x1  x2 x3 x4
> > > 1   1 B12  NA
> > > 2   2C23   NA
> > > 3 322  B32  D34   NA
> > > 4   4   D44NA
> > > 5  51 D53 NA
> > > 6  60 D62NA
> > >
> > >
> > > Desired output
> > >x1   x2 x3   x4
> > > 1   1B22   NA
> > > 2   2 C33 NA
> > > 3 322  B32NA  D34
> > > 4   4  NA  D44
> > > 5  51D53 NA
> > > 6  60   D62  NA
> > >
> > > Thank you,
> > >
> > > __
> > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide 
> > > http://www.R-project.org/posting-guide.html
> > > and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read

2021-02-22 Thread Val
I Tried that one and it did not work. Please see the error message
Error in read.table(text = "x1  x2  x3 x4\n1 B12 \n2   C23
\n322 B32  D34 \n4D44 \n51 D53\n60 D62 ",
:
  more columns than column names

On Mon, Feb 22, 2021 at 5:39 PM Bill Dunlap  wrote:
>
> Since the columns in the file are separated by a space character, " ",
> add the read.table argument sep=" ".
>
> -Bill
>
> On Mon, Feb 22, 2021 at 2:21 PM Val  wrote:
> >
> > Hi all, I am trying to read a messy data  but facing  difficulty.  The
> > data has several columns separated by blank space(s).  Each column
> > value may have different lengths across the rows.   The first
> > row(header) has four columns. However, each row may not have the four
> > column values.  For instance, the first data row has only the first
> > two column values. The fourth data row has the first and last column
> > values, the second and the third column values are missing for this
> > row..  How do I read this data set correctly? Here is my sample data
> > set, output and desired output.   To make it clear to each data point
> > I have added the row and column numbers. I cannot use fixed width
> > format reading because each row  may have different length for  a
> > given column.
> >
> > dat<-read.table(text="x1  x2  x3 x4
> > 1 B22
> > 2 C33
> > 322 B22  D34
> > 4 D44
> > 51 D53
> > 60 D62",header=T, fill=T,na.strings=c("","NA"))
> >
> > Output
> >   x1  x2 x3 x4
> > 1   1 B12  NA
> > 2   2C23   NA
> > 3 322  B32  D34   NA
> > 4   4   D44NA
> > 5  51 D53 NA
> > 6  60 D62NA
> >
> >
> > Desired output
> >x1   x2 x3   x4
> > 1   1B22   NA
> > 2   2 C33 NA
> > 3 322  B32NA  D34
> > 4   4  NA  D44
> > 5  51D53 NA
> > 6  60   D62  NA
> >
> > Thank you,
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read

2021-02-22 Thread Bill Dunlap
Since the columns in the file are separated by a space character, " ",
add the read.table argument sep=" ".

-Bill

On Mon, Feb 22, 2021 at 2:21 PM Val  wrote:
>
> Hi all, I am trying to read a messy data  but facing  difficulty.  The
> data has several columns separated by blank space(s).  Each column
> value may have different lengths across the rows.   The first
> row(header) has four columns. However, each row may not have the four
> column values.  For instance, the first data row has only the first
> two column values. The fourth data row has the first and last column
> values, the second and the third column values are missing for this
> row..  How do I read this data set correctly? Here is my sample data
> set, output and desired output.   To make it clear to each data point
> I have added the row and column numbers. I cannot use fixed width
> format reading because each row  may have different length for  a
> given column.
>
> dat<-read.table(text="x1  x2  x3 x4
> 1 B22
> 2 C33
> 322 B22  D34
> 4 D44
> 51 D53
> 60 D62",header=T, fill=T,na.strings=c("","NA"))
>
> Output
>   x1  x2 x3 x4
> 1   1 B12  NA
> 2   2C23   NA
> 3 322  B32  D34   NA
> 4   4   D44NA
> 5  51 D53 NA
> 6  60 D62NA
>
>
> Desired output
>x1   x2 x3   x4
> 1   1B22   NA
> 2   2 C33 NA
> 3 322  B32NA  D34
> 4   4  NA  D44
> 5  51D53 NA
> 6  60   D62  NA
>
> Thank you,
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Is it Possible to Create S4 Function Objects?

2021-02-22 Thread /əˈbi/
Oh wow.
Post of the year!
Where's the like button?

Note, I was able to rewrite it without the deprecated args.
(Don't want one of those CRAN emails, in 12 months from now, saying
please change ).

I'll have to come back to this later, to see if I can get the body of
f() to access the slot


On Mon, Feb 22, 2021 at 11:36 AM Hervé Pagès  wrote:
>
> Hi Abby,
>
> Something along the line of:
>
>setClass("S4Function",
>  contains="function",
>  representation(name="character", more_stuff="ANY")
>)
>
> seems to do what you want:
>
>f <- new("S4Function", function(a) a^2, name="square")
>
># 'f' is both an S4 object and a function:
>is.object(f)
># [1] TRUE
>is.function(f)
># [1] TRUE
>
>f@name
># [1] "square"
>f(11)
># [1] 121
>
> Hope this helps,
>
> H.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Read

2021-02-22 Thread Val
Hi all, I am trying to read a messy data  but facing  difficulty.  The
data has several columns separated by blank space(s).  Each column
value may have different lengths across the rows.   The first
row(header) has four columns. However, each row may not have the four
column values.  For instance, the first data row has only the first
two column values. The fourth data row has the first and last column
values, the second and the third column values are missing for this
row..  How do I read this data set correctly? Here is my sample data
set, output and desired output.   To make it clear to each data point
I have added the row and column numbers. I cannot use fixed width
format reading because each row  may have different length for  a
given column.

dat<-read.table(text="x1  x2  x3 x4
1 B22
2 C33
322 B22  D34
4 D44
51 D53
60 D62",header=T, fill=T,na.strings=c("","NA"))

Output
  x1  x2 x3 x4
1   1 B12  NA
2   2C23   NA
3 322  B32  D34   NA
4   4   D44NA
5  51 D53 NA
6  60 D62NA


Desired output
   x1   x2 x3   x4
1   1B22   NA
2   2 C33 NA
3 322  B32NA  D34
4   4  NA  D44
5  51D53 NA
6  60   D62  NA

Thank you,

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] xyplot.zoo trouble with the index when I use microseconds (type POSIXct)

2021-02-22 Thread Laurent Rhelp

yes, good idea, eventually here's what I will do:

time(DF.w) <- as.POSIXlt(time(DF.w))$sec
myticks <- round(pretty(time(DF.w)),6)
mylabels <- as.character(formatC(myticks,format = 
"f",digits=6,width=9,flag=" "))


xyplot(  DF.w
 , xlab = paste0("Seconds from ",format(mystart,"%Y-%m-%d %H:%M"))
 , type = "l"
 , screens = 1
 ,  col = c("red","blue","black")
 ,  scales = list( y= list(relation = "free", abbreviate=TRUE)
  , x = list( at = myticks, labels = mylabels
  , rot = 45, abbreviate = FALSE
  , cex = 0.6)
 )
)

Thank you



Le 22/02/2021 à 19:32, Gabor Grothendieck a écrit :

Also, it might be better to simply use seconds as the time. In that
case both plot and xyplot run without error.

  time(DF.w) <- as.POSIXlt(time(DF.w))$sec
  # now run plot or xyplot as before

On Mon, Feb 22, 2021 at 11:56 AM Gabor Grothendieck
 wrote:

I assume that this is a lattice problem.  Replacing xyplot with plot
and using all the same arguments there is no error.


On Mon, Feb 22, 2021 at 11:26 AM Laurent Rhelp  wrote:

Dear R-Help-List,

 I have to process time series with a sampling frequency of 1 MHz.
I use the POSIXct format for the date-times with microsecond in a zoo
object and the xyplot.zoo function to do the graphs.
As I show in the below example I had a trouble to plot the labels on the
x-axis with an error message. I found a solution but I would like to
know if I miss something.
The link
https://stackoverflow.com/questions/7726034/how-r-formats-posixct-with-fractional-seconds

helped me to understand how to print the POSIXct value to see the
microseconds thanks to the function myformat.POSIXct:

myformat.POSIXct <- function(x, digits=6)
{
x2 <- round(unclass(x), digits)
attributes(x2) <- attributes(x)
x <- as.POSIXlt(x2,origin="1970-01-01",tz="GMT")
x$sec <- round(x$sec, digits)
format.POSIXlt(x, paste("%Y-%m-%d %H:%M:%OS",digits,sep=""),tz="GMT")

}


## The example giving the error message:

library(lattice)
library(zoo)

##
options(digits = 16) # to see all the digits on the screen
options(digits.secs = 6) # to see the microseconds
# mock data
# a sine with a frequency f0 and two others with a delay
Fs <- 1e+6 # sampling frequency 1 MHz
Ts <- 1/Fs
# frequency of the sinus
f0 <- 10
t0 <- 1/f0
time <- seq(0, length = 1000, by = Ts)
A1 <- 1
y1 <- A1 * sin(2*pi*f0*time)
y2 <- 2 * A1 * sin(2*pi*f0*(time+0.02))
y3 <- 3 * A1 * sin(2*pi*f0*(time+0.05))
## creation of a dataframe:
##
DF <- data.frame( time = time, y1 = y1, y2 = y2, y3 = y3)
# Since I want to allow for the datetime POSIXct format on the x-axis
# for the plot I transform my dataframe in a zoo object
#
# say that my acquisition began at "2021-02-08 09:15:50.00"
#
mystart <- as.POSIXct("2021-02-08 09:15:50.00", format = "%Y-%m-%d
%H:%M:%OS",tz="GMT")
mystart
# To see the correct datetime I use the myformat.POSIXct function
myformat.POSIXct(mystart)
##
## using the method seq.POSIXct as following doesn't work:
## mydatetime <- seq( mystart , length = nrow(DF), by = "0.01 sec")
## head( myformat.POSIXct(mydatetime) )
## if I use the following command it works:
mydatetime <- seq( mystart , length = nrow(DF), by = 0.01)
head( myformat.POSIXct(mydatetime) )
## I do the zoo object:
DF.z <- zoo(DF[,-1],order.by = mydatetime)
## We don't see the correct value for the index:
head(DF.z)
# timey1 y2 y3
# 2021-02-08 09:15:50.00 0e+00 0.000e+00
1.902113032590307e+00  3.673819061467132e-16
# 2021-02-08 09:15:50.00 1e-06 5.877852522924730e-01
1.902113032590307e+00 -1.763355756877419e+00
# 2021-02-08 09:15:50.01 2e-06 9.510565162951535e-01
1.175570504584947e+00 -2.853169548885460e+00
# 2021-02-08 09:15:50.03 3e-06 9.510565162951536e-01
1.133099690464601e-15 -2.853169548885460e+00
# 2021-02-08 09:15:50.04 4e-06 5.877852522924736e-01
-1.175570504584946e+00 -1.763355756877420e+00
# 2021-02-08 09:15:50.05 5e-06 5.665498452323003e-16
-1.902113032590306e+00 -3.399299071393802e-15
# If I use myformat.POSIXct I see that the index is correct in the
object DF:
head(myformat.POSIXct(index(DF.z)))
## and when I plot I have an error:
xyplot(   DF.z
, screens = c(1,1,1)
, type = "l"
, col = c("red","blue","black")

)

# Error in prettyDate_TMP(x, ...) : range too small for min.n

# if I process by hand the plot of the labels on the x-axis it works:
#
myend <- tail(mydatetime,1)

myticks <- seq( mystart , to = myend , length = 5)
mylabels <- format(myticks,"%H:%M:%OS")

xyplot(  DF.z
   , screens = c(1,1,1)
   , type = "l"
   , col = c("red","blue","black")
   , scales = list(
   y= list(relation = "free", abbreviate=TRUE),
   x = list( at = myticks, labels = mylabels
 , rot = 45, cex = 0.5)
 )
)
# The microseconds are well ta

Re: [R] xyplot.zoo trouble with the index when I use microseconds (type POSIXct)

2021-02-22 Thread Gabor Grothendieck
Also, it might be better to simply use seconds as the time. In that
case both plot and xyplot run without error.

 time(DF.w) <- as.POSIXlt(time(DF.w))$sec
 # now run plot or xyplot as before

On Mon, Feb 22, 2021 at 11:56 AM Gabor Grothendieck
 wrote:
>
> I assume that this is a lattice problem.  Replacing xyplot with plot
> and using all the same arguments there is no error.
>
>
> On Mon, Feb 22, 2021 at 11:26 AM Laurent Rhelp  wrote:
> >
> > Dear R-Help-List,
> >
> > I have to process time series with a sampling frequency of 1 MHz.
> > I use the POSIXct format for the date-times with microsecond in a zoo
> > object and the xyplot.zoo function to do the graphs.
> > As I show in the below example I had a trouble to plot the labels on the
> > x-axis with an error message. I found a solution but I would like to
> > know if I miss something.
> > The link
> > https://stackoverflow.com/questions/7726034/how-r-formats-posixct-with-fractional-seconds
> >
> > helped me to understand how to print the POSIXct value to see the
> > microseconds thanks to the function myformat.POSIXct:
> >
> > myformat.POSIXct <- function(x, digits=6)
> > {
> >x2 <- round(unclass(x), digits)
> >attributes(x2) <- attributes(x)
> >x <- as.POSIXlt(x2,origin="1970-01-01",tz="GMT")
> >x$sec <- round(x$sec, digits)
> >format.POSIXlt(x, paste("%Y-%m-%d %H:%M:%OS",digits,sep=""),tz="GMT")
> >
> > }
> >
> >
> > ## The example giving the error message:
> >
> > library(lattice)
> > library(zoo)
> >
> > ##
> > options(digits = 16) # to see all the digits on the screen
> > options(digits.secs = 6) # to see the microseconds
> > # mock data
> > # a sine with a frequency f0 and two others with a delay
> > Fs <- 1e+6 # sampling frequency 1 MHz
> > Ts <- 1/Fs
> > # frequency of the sinus
> > f0 <- 10
> > t0 <- 1/f0
> > time <- seq(0, length = 1000, by = Ts)
> > A1 <- 1
> > y1 <- A1 * sin(2*pi*f0*time)
> > y2 <- 2 * A1 * sin(2*pi*f0*(time+0.02))
> > y3 <- 3 * A1 * sin(2*pi*f0*(time+0.05))
> > ## creation of a dataframe:
> > ##
> > DF <- data.frame( time = time, y1 = y1, y2 = y2, y3 = y3)
> > # Since I want to allow for the datetime POSIXct format on the x-axis
> > # for the plot I transform my dataframe in a zoo object
> > #
> > # say that my acquisition began at "2021-02-08 09:15:50.00"
> > #
> > mystart <- as.POSIXct("2021-02-08 09:15:50.00", format = "%Y-%m-%d
> > %H:%M:%OS",tz="GMT")
> > mystart
> > # To see the correct datetime I use the myformat.POSIXct function
> > myformat.POSIXct(mystart)
> > ##
> > ## using the method seq.POSIXct as following doesn't work:
> > ## mydatetime <- seq( mystart , length = nrow(DF), by = "0.01 sec")
> > ## head( myformat.POSIXct(mydatetime) )
> > ## if I use the following command it works:
> > mydatetime <- seq( mystart , length = nrow(DF), by = 0.01)
> > head( myformat.POSIXct(mydatetime) )
> > ## I do the zoo object:
> > DF.z <- zoo(DF[,-1],order.by = mydatetime)
> > ## We don't see the correct value for the index:
> > head(DF.z)
> > # timey1 y2 y3
> > # 2021-02-08 09:15:50.00 0e+00 0.000e+00
> > 1.902113032590307e+00  3.673819061467132e-16
> > # 2021-02-08 09:15:50.00 1e-06 5.877852522924730e-01
> > 1.902113032590307e+00 -1.763355756877419e+00
> > # 2021-02-08 09:15:50.01 2e-06 9.510565162951535e-01
> > 1.175570504584947e+00 -2.853169548885460e+00
> > # 2021-02-08 09:15:50.03 3e-06 9.510565162951536e-01
> > 1.133099690464601e-15 -2.853169548885460e+00
> > # 2021-02-08 09:15:50.04 4e-06 5.877852522924736e-01
> > -1.175570504584946e+00 -1.763355756877420e+00
> > # 2021-02-08 09:15:50.05 5e-06 5.665498452323003e-16
> > -1.902113032590306e+00 -3.399299071393802e-15
> > # If I use myformat.POSIXct I see that the index is correct in the
> > object DF:
> > head(myformat.POSIXct(index(DF.z)))
> > ## and when I plot I have an error:
> > xyplot(   DF.z
> >, screens = c(1,1,1)
> >, type = "l"
> >, col = c("red","blue","black")
> >
> > )
> >
> > # Error in prettyDate_TMP(x, ...) : range too small for min.n
> >
> > # if I process by hand the plot of the labels on the x-axis it works:
> > #
> > myend <- tail(mydatetime,1)
> >
> > myticks <- seq( mystart , to = myend , length = 5)
> > mylabels <- format(myticks,"%H:%M:%OS")
> >
> > xyplot(  DF.z
> >   , screens = c(1,1,1)
> >   , type = "l"
> >   , col = c("red","blue","black")
> >   , scales = list(
> >   y= list(relation = "free", abbreviate=TRUE),
> >   x = list( at = myticks, labels = mylabels
> > , rot = 45, cex = 0.5)
> > )
> > )
> > # The microseconds are well taken into account with the window function
> > # if I want to plot only 100 microseconds but there is of course the same
> > # trouble for the plot
> >
> > myend <- as.POSIXct("2021-02-08 09:15:50.000100", format = "%Y-%m-%d
> > %H:%M:

Re: [R] xyplot.zoo trouble with the index when I use microseconds (type POSIXct)

2021-02-22 Thread Laurent Rhelp

Le 22/02/2021 à 18:32, Gabor Grothendieck a écrit :

P.S. screen= is recycled so screen=1 would be sufficient.


ok thank you. I will write my axis command.

Best Regards



On Mon, Feb 22, 2021 at 12:31 PM Gabor Grothendieck
 wrote:

You can use the xaxt = "n" argument to plot.zoo
to suppress the X axis and then issue
an axis command.  plot.zoo has examples.

On Mon, Feb 22, 2021 at 12:14 PM Laurent Rhelp  wrote:

You are right, if I replace xyplot by plot there is no error message but
the POSIXct format is not taken into account for the labels on the
x-axis. Do I have to write a panel function as it is explained in the
zoo FAQ #8 ?

And is there a possibility to see the correct values of the index (i.e.
with the correct microseconds) when I see the zoo object, in my example,
when I type head(DF.z) for example ?



Le 22/02/2021 à 17:56, Gabor Grothendieck a écrit :

I assume that this is a lattice problem.  Replacing xyplot with plot
and using all the same arguments there is no error.


On Mon, Feb 22, 2021 at 11:26 AM Laurent Rhelp  wrote:

Dear R-Help-List,

  I have to process time series with a sampling frequency of 1 MHz.
I use the POSIXct format for the date-times with microsecond in a zoo
object and the xyplot.zoo function to do the graphs.
As I show in the below example I had a trouble to plot the labels on the
x-axis with an error message. I found a solution but I would like to
know if I miss something.
The link
https://stackoverflow.com/questions/7726034/how-r-formats-posixct-with-fractional-seconds

helped me to understand how to print the POSIXct value to see the
microseconds thanks to the function myformat.POSIXct:

myformat.POSIXct <- function(x, digits=6)
{
 x2 <- round(unclass(x), digits)
 attributes(x2) <- attributes(x)
 x <- as.POSIXlt(x2,origin="1970-01-01",tz="GMT")
 x$sec <- round(x$sec, digits)
 format.POSIXlt(x, paste("%Y-%m-%d %H:%M:%OS",digits,sep=""),tz="GMT")

}


## The example giving the error message:

library(lattice)
library(zoo)

##
options(digits = 16) # to see all the digits on the screen
options(digits.secs = 6) # to see the microseconds
# mock data
# a sine with a frequency f0 and two others with a delay
Fs <- 1e+6 # sampling frequency 1 MHz
Ts <- 1/Fs
# frequency of the sinus
f0 <- 10
t0 <- 1/f0
time <- seq(0, length = 1000, by = Ts)
A1 <- 1
y1 <- A1 * sin(2*pi*f0*time)
y2 <- 2 * A1 * sin(2*pi*f0*(time+0.02))
y3 <- 3 * A1 * sin(2*pi*f0*(time+0.05))
## creation of a dataframe:
##
DF <- data.frame( time = time, y1 = y1, y2 = y2, y3 = y3)
# Since I want to allow for the datetime POSIXct format on the x-axis
# for the plot I transform my dataframe in a zoo object
#
# say that my acquisition began at "2021-02-08 09:15:50.00"
#
mystart <- as.POSIXct("2021-02-08 09:15:50.00", format = "%Y-%m-%d
%H:%M:%OS",tz="GMT")
mystart
# To see the correct datetime I use the myformat.POSIXct function
myformat.POSIXct(mystart)
##
## using the method seq.POSIXct as following doesn't work:
## mydatetime <- seq( mystart , length = nrow(DF), by = "0.01 sec")
## head( myformat.POSIXct(mydatetime) )
## if I use the following command it works:
mydatetime <- seq( mystart , length = nrow(DF), by = 0.01)
head( myformat.POSIXct(mydatetime) )
## I do the zoo object:
DF.z <- zoo(DF[,-1],order.by = mydatetime)
## We don't see the correct value for the index:
head(DF.z)
# timey1 y2 y3
# 2021-02-08 09:15:50.00 0e+00 0.000e+00
1.902113032590307e+00  3.673819061467132e-16
# 2021-02-08 09:15:50.00 1e-06 5.877852522924730e-01
1.902113032590307e+00 -1.763355756877419e+00
# 2021-02-08 09:15:50.01 2e-06 9.510565162951535e-01
1.175570504584947e+00 -2.853169548885460e+00
# 2021-02-08 09:15:50.03 3e-06 9.510565162951536e-01
1.133099690464601e-15 -2.853169548885460e+00
# 2021-02-08 09:15:50.04 4e-06 5.877852522924736e-01
-1.175570504584946e+00 -1.763355756877420e+00
# 2021-02-08 09:15:50.05 5e-06 5.665498452323003e-16
-1.902113032590306e+00 -3.399299071393802e-15
# If I use myformat.POSIXct I see that the index is correct in the
object DF:
head(myformat.POSIXct(index(DF.z)))
## and when I plot I have an error:
xyplot(   DF.z
 , screens = c(1,1,1)
 , type = "l"
 , col = c("red","blue","black")

)

# Error in prettyDate_TMP(x, ...) : range too small for min.n

# if I process by hand the plot of the labels on the x-axis it works:
#
myend <- tail(mydatetime,1)

myticks <- seq( mystart , to = myend , length = 5)
mylabels <- format(myticks,"%H:%M:%OS")

xyplot(  DF.z
, screens = c(1,1,1)
, type = "l"
, col = c("red","blue","black")
, scales = list(
y= list(relation = "free", abbreviate=TRUE),
x = list( at = myticks, labels = mylabels
  , rot = 45, cex = 0.5)
  )
)
# The microseconds are well taken into account with t

Re: [R] xyplot.zoo trouble with the index when I use microseconds (type POSIXct)

2021-02-22 Thread Laurent Rhelp

Le 22/02/2021 à 18:01, Deepayan Sarkar a écrit :

On Mon, Feb 22, 2021 at 9:56 PM Laurent Rhelp  wrote:

Dear R-Help-List,

 I have to process time series with a sampling frequency of 1 MHz.
I use the POSIXct format for the date-times with microsecond in a zoo
object and the xyplot.zoo function to do the graphs.
As I show in the below example I had a trouble to plot the labels on the
x-axis with an error message. I found a solution but I would like to
know if I miss something.
The link
https://stackoverflow.com/questions/7726034/how-r-formats-posixct-with-fractional-seconds

helped me to understand how to print the POSIXct value to see the
microseconds thanks to the function myformat.POSIXct:

myformat.POSIXct <- function(x, digits=6)
{
x2 <- round(unclass(x), digits)
attributes(x2) <- attributes(x)
x <- as.POSIXlt(x2,origin="1970-01-01",tz="GMT")
x$sec <- round(x$sec, digits)
format.POSIXlt(x, paste("%Y-%m-%d %H:%M:%OS",digits,sep=""),tz="GMT")

}


## The example giving the error message:

library(lattice)
library(zoo)

##
options(digits = 16) # to see all the digits on the screen
options(digits.secs = 6) # to see the microseconds
# mock data
# a sine with a frequency f0 and two others with a delay
Fs <- 1e+6 # sampling frequency 1 MHz
Ts <- 1/Fs
# frequency of the sinus
f0 <- 10
t0 <- 1/f0
time <- seq(0, length = 1000, by = Ts)
A1 <- 1
y1 <- A1 * sin(2*pi*f0*time)
y2 <- 2 * A1 * sin(2*pi*f0*(time+0.02))
y3 <- 3 * A1 * sin(2*pi*f0*(time+0.05))
## creation of a dataframe:
##
DF <- data.frame( time = time, y1 = y1, y2 = y2, y3 = y3)
# Since I want to allow for the datetime POSIXct format on the x-axis
# for the plot I transform my dataframe in a zoo object
#
# say that my acquisition began at "2021-02-08 09:15:50.00"
#
mystart <- as.POSIXct("2021-02-08 09:15:50.00", format = "%Y-%m-%d
%H:%M:%OS",tz="GMT")
mystart
# To see the correct datetime I use the myformat.POSIXct function
myformat.POSIXct(mystart)
##
## using the method seq.POSIXct as following doesn't work:
## mydatetime <- seq( mystart , length = nrow(DF), by = "0.01 sec")
## head( myformat.POSIXct(mydatetime) )
## if I use the following command it works:
mydatetime <- seq( mystart , length = nrow(DF), by = 0.01)
head( myformat.POSIXct(mydatetime) )
## I do the zoo object:
DF.z <- zoo(DF[,-1],order.by = mydatetime)
## We don't see the correct value for the index:
head(DF.z)
# timey1 y2 y3
# 2021-02-08 09:15:50.00 0e+00 0.000e+00
1.902113032590307e+00  3.673819061467132e-16
# 2021-02-08 09:15:50.00 1e-06 5.877852522924730e-01
1.902113032590307e+00 -1.763355756877419e+00
# 2021-02-08 09:15:50.01 2e-06 9.510565162951535e-01
1.175570504584947e+00 -2.853169548885460e+00
# 2021-02-08 09:15:50.03 3e-06 9.510565162951536e-01
1.133099690464601e-15 -2.853169548885460e+00
# 2021-02-08 09:15:50.04 4e-06 5.877852522924736e-01
-1.175570504584946e+00 -1.763355756877420e+00
# 2021-02-08 09:15:50.05 5e-06 5.665498452323003e-16
-1.902113032590306e+00 -3.399299071393802e-15
# If I use myformat.POSIXct I see that the index is correct in the
object DF:
head(myformat.POSIXct(index(DF.z)))
## and when I plot I have an error:
xyplot(   DF.z
, screens = c(1,1,1)
, type = "l"
, col = c("red","blue","black")

)

# Error in prettyDate_TMP(x, ...) : range too small for min.n

At least the immediate problem is that

lattice:::prettyDate_TMP(range(mydatetime))
# Error in lattice:::prettyDate_TMP(range(mydatetime)) :
# range too small for min.n

grDevices:::prettyDate(range(mydatetime))
# [1] "2021-02-08 09:15:48 GMT" "2021-02-08 09:15:49 GMT"
# [3] "2021-02-08 09:15:50 GMT" "2021-02-08 09:15:51 GMT"
# [5] "2021-02-08 09:15:52 GMT" "2021-02-08 09:15:53 GMT"

So the version in lattice (which was supposed to be a temporary
stopgap till R 2.12 was released) has not kept up. I will fix.

Does the output above look OK to you?


It is ok for me except the fact that I would like to see on the x-axis 
labels the fractional seconds, at least the milliseconds.




Best,
-Deepayan



# if I process by hand the plot of the labels on the x-axis it works:
#
myend <- tail(mydatetime,1)

myticks <- seq( mystart , to = myend , length = 5)
mylabels <- format(myticks,"%H:%M:%OS")

xyplot(  DF.z
   , screens = c(1,1,1)
   , type = "l"
   , col = c("red","blue","black")
   , scales = list(
   y= list(relation = "free", abbreviate=TRUE),
   x = list( at = myticks, labels = mylabels
 , rot = 45, cex = 0.5)
 )
)
# The microseconds are well taken into account with the window function
# if I want to plot only 100 microseconds but there is of course the same
# trouble for the plot

myend <- as.POSIXct("2021-02-08 09:15:50.000100", format = "%Y-%m-%d
%H:%M:%OS",tz="GMT")
myformat.POSIXct(myend)

DF.w <- window( DF.z ,start = my

Re: [R] xyplot.zoo trouble with the index when I use microseconds (type POSIXct)

2021-02-22 Thread Deepayan Sarkar
On Mon, Feb 22, 2021 at 9:56 PM Laurent Rhelp  wrote:
>
> Dear R-Help-List,
>
> I have to process time series with a sampling frequency of 1 MHz.
> I use the POSIXct format for the date-times with microsecond in a zoo
> object and the xyplot.zoo function to do the graphs.
> As I show in the below example I had a trouble to plot the labels on the
> x-axis with an error message. I found a solution but I would like to
> know if I miss something.
> The link
> https://stackoverflow.com/questions/7726034/how-r-formats-posixct-with-fractional-seconds
>
> helped me to understand how to print the POSIXct value to see the
> microseconds thanks to the function myformat.POSIXct:
>
> myformat.POSIXct <- function(x, digits=6)
> {
>x2 <- round(unclass(x), digits)
>attributes(x2) <- attributes(x)
>x <- as.POSIXlt(x2,origin="1970-01-01",tz="GMT")
>x$sec <- round(x$sec, digits)
>format.POSIXlt(x, paste("%Y-%m-%d %H:%M:%OS",digits,sep=""),tz="GMT")
>
> }
>
>
> ## The example giving the error message:
>
> library(lattice)
> library(zoo)
>
> ##
> options(digits = 16) # to see all the digits on the screen
> options(digits.secs = 6) # to see the microseconds
> # mock data
> # a sine with a frequency f0 and two others with a delay
> Fs <- 1e+6 # sampling frequency 1 MHz
> Ts <- 1/Fs
> # frequency of the sinus
> f0 <- 10
> t0 <- 1/f0
> time <- seq(0, length = 1000, by = Ts)
> A1 <- 1
> y1 <- A1 * sin(2*pi*f0*time)
> y2 <- 2 * A1 * sin(2*pi*f0*(time+0.02))
> y3 <- 3 * A1 * sin(2*pi*f0*(time+0.05))
> ## creation of a dataframe:
> ##
> DF <- data.frame( time = time, y1 = y1, y2 = y2, y3 = y3)
> # Since I want to allow for the datetime POSIXct format on the x-axis
> # for the plot I transform my dataframe in a zoo object
> #
> # say that my acquisition began at "2021-02-08 09:15:50.00"
> #
> mystart <- as.POSIXct("2021-02-08 09:15:50.00", format = "%Y-%m-%d
> %H:%M:%OS",tz="GMT")
> mystart
> # To see the correct datetime I use the myformat.POSIXct function
> myformat.POSIXct(mystart)
> ##
> ## using the method seq.POSIXct as following doesn't work:
> ## mydatetime <- seq( mystart , length = nrow(DF), by = "0.01 sec")
> ## head( myformat.POSIXct(mydatetime) )
> ## if I use the following command it works:
> mydatetime <- seq( mystart , length = nrow(DF), by = 0.01)
> head( myformat.POSIXct(mydatetime) )
> ## I do the zoo object:
> DF.z <- zoo(DF[,-1],order.by = mydatetime)
> ## We don't see the correct value for the index:
> head(DF.z)
> # timey1 y2 y3
> # 2021-02-08 09:15:50.00 0e+00 0.000e+00
> 1.902113032590307e+00  3.673819061467132e-16
> # 2021-02-08 09:15:50.00 1e-06 5.877852522924730e-01
> 1.902113032590307e+00 -1.763355756877419e+00
> # 2021-02-08 09:15:50.01 2e-06 9.510565162951535e-01
> 1.175570504584947e+00 -2.853169548885460e+00
> # 2021-02-08 09:15:50.03 3e-06 9.510565162951536e-01
> 1.133099690464601e-15 -2.853169548885460e+00
> # 2021-02-08 09:15:50.04 4e-06 5.877852522924736e-01
> -1.175570504584946e+00 -1.763355756877420e+00
> # 2021-02-08 09:15:50.05 5e-06 5.665498452323003e-16
> -1.902113032590306e+00 -3.399299071393802e-15
> # If I use myformat.POSIXct I see that the index is correct in the
> object DF:
> head(myformat.POSIXct(index(DF.z)))
> ## and when I plot I have an error:
> xyplot(   DF.z
>, screens = c(1,1,1)
>, type = "l"
>, col = c("red","blue","black")
>
> )
>
> # Error in prettyDate_TMP(x, ...) : range too small for min.n

At least the immediate problem is that

lattice:::prettyDate_TMP(range(mydatetime))
# Error in lattice:::prettyDate_TMP(range(mydatetime)) :
# range too small for min.n

grDevices:::prettyDate(range(mydatetime))
# [1] "2021-02-08 09:15:48 GMT" "2021-02-08 09:15:49 GMT"
# [3] "2021-02-08 09:15:50 GMT" "2021-02-08 09:15:51 GMT"
# [5] "2021-02-08 09:15:52 GMT" "2021-02-08 09:15:53 GMT"

So the version in lattice (which was supposed to be a temporary
stopgap till R 2.12 was released) has not kept up. I will fix.

Does the output above look OK to you?

Best,
-Deepayan


> # if I process by hand the plot of the labels on the x-axis it works:
> #
> myend <- tail(mydatetime,1)
>
> myticks <- seq( mystart , to = myend , length = 5)
> mylabels <- format(myticks,"%H:%M:%OS")
>
> xyplot(  DF.z
>   , screens = c(1,1,1)
>   , type = "l"
>   , col = c("red","blue","black")
>   , scales = list(
>   y= list(relation = "free", abbreviate=TRUE),
>   x = list( at = myticks, labels = mylabels
> , rot = 45, cex = 0.5)
> )
> )
> # The microseconds are well taken into account with the window function
> # if I want to plot only 100 microseconds but there is of course the same
> # trouble for the plot
>
> myend <- as.POSIXct("2021-02-08 09:15:50.000100", format = "%Y-%m-%d
> %H:%M:%OS",tz="GMT")
> myformat.POSIXct(myend)
>
> DF.w <- w

Re: [R] xyplot.zoo trouble with the index when I use microseconds (type POSIXct)

2021-02-22 Thread Gabor Grothendieck
I assume that this is a lattice problem.  Replacing xyplot with plot
and using all the same arguments there is no error.


On Mon, Feb 22, 2021 at 11:26 AM Laurent Rhelp  wrote:
>
> Dear R-Help-List,
>
> I have to process time series with a sampling frequency of 1 MHz.
> I use the POSIXct format for the date-times with microsecond in a zoo
> object and the xyplot.zoo function to do the graphs.
> As I show in the below example I had a trouble to plot the labels on the
> x-axis with an error message. I found a solution but I would like to
> know if I miss something.
> The link
> https://stackoverflow.com/questions/7726034/how-r-formats-posixct-with-fractional-seconds
>
> helped me to understand how to print the POSIXct value to see the
> microseconds thanks to the function myformat.POSIXct:
>
> myformat.POSIXct <- function(x, digits=6)
> {
>x2 <- round(unclass(x), digits)
>attributes(x2) <- attributes(x)
>x <- as.POSIXlt(x2,origin="1970-01-01",tz="GMT")
>x$sec <- round(x$sec, digits)
>format.POSIXlt(x, paste("%Y-%m-%d %H:%M:%OS",digits,sep=""),tz="GMT")
>
> }
>
>
> ## The example giving the error message:
>
> library(lattice)
> library(zoo)
>
> ##
> options(digits = 16) # to see all the digits on the screen
> options(digits.secs = 6) # to see the microseconds
> # mock data
> # a sine with a frequency f0 and two others with a delay
> Fs <- 1e+6 # sampling frequency 1 MHz
> Ts <- 1/Fs
> # frequency of the sinus
> f0 <- 10
> t0 <- 1/f0
> time <- seq(0, length = 1000, by = Ts)
> A1 <- 1
> y1 <- A1 * sin(2*pi*f0*time)
> y2 <- 2 * A1 * sin(2*pi*f0*(time+0.02))
> y3 <- 3 * A1 * sin(2*pi*f0*(time+0.05))
> ## creation of a dataframe:
> ##
> DF <- data.frame( time = time, y1 = y1, y2 = y2, y3 = y3)
> # Since I want to allow for the datetime POSIXct format on the x-axis
> # for the plot I transform my dataframe in a zoo object
> #
> # say that my acquisition began at "2021-02-08 09:15:50.00"
> #
> mystart <- as.POSIXct("2021-02-08 09:15:50.00", format = "%Y-%m-%d
> %H:%M:%OS",tz="GMT")
> mystart
> # To see the correct datetime I use the myformat.POSIXct function
> myformat.POSIXct(mystart)
> ##
> ## using the method seq.POSIXct as following doesn't work:
> ## mydatetime <- seq( mystart , length = nrow(DF), by = "0.01 sec")
> ## head( myformat.POSIXct(mydatetime) )
> ## if I use the following command it works:
> mydatetime <- seq( mystart , length = nrow(DF), by = 0.01)
> head( myformat.POSIXct(mydatetime) )
> ## I do the zoo object:
> DF.z <- zoo(DF[,-1],order.by = mydatetime)
> ## We don't see the correct value for the index:
> head(DF.z)
> # timey1 y2 y3
> # 2021-02-08 09:15:50.00 0e+00 0.000e+00
> 1.902113032590307e+00  3.673819061467132e-16
> # 2021-02-08 09:15:50.00 1e-06 5.877852522924730e-01
> 1.902113032590307e+00 -1.763355756877419e+00
> # 2021-02-08 09:15:50.01 2e-06 9.510565162951535e-01
> 1.175570504584947e+00 -2.853169548885460e+00
> # 2021-02-08 09:15:50.03 3e-06 9.510565162951536e-01
> 1.133099690464601e-15 -2.853169548885460e+00
> # 2021-02-08 09:15:50.04 4e-06 5.877852522924736e-01
> -1.175570504584946e+00 -1.763355756877420e+00
> # 2021-02-08 09:15:50.05 5e-06 5.665498452323003e-16
> -1.902113032590306e+00 -3.399299071393802e-15
> # If I use myformat.POSIXct I see that the index is correct in the
> object DF:
> head(myformat.POSIXct(index(DF.z)))
> ## and when I plot I have an error:
> xyplot(   DF.z
>, screens = c(1,1,1)
>, type = "l"
>, col = c("red","blue","black")
>
> )
>
> # Error in prettyDate_TMP(x, ...) : range too small for min.n
>
> # if I process by hand the plot of the labels on the x-axis it works:
> #
> myend <- tail(mydatetime,1)
>
> myticks <- seq( mystart , to = myend , length = 5)
> mylabels <- format(myticks,"%H:%M:%OS")
>
> xyplot(  DF.z
>   , screens = c(1,1,1)
>   , type = "l"
>   , col = c("red","blue","black")
>   , scales = list(
>   y= list(relation = "free", abbreviate=TRUE),
>   x = list( at = myticks, labels = mylabels
> , rot = 45, cex = 0.5)
> )
> )
> # The microseconds are well taken into account with the window function
> # if I want to plot only 100 microseconds but there is of course the same
> # trouble for the plot
>
> myend <- as.POSIXct("2021-02-08 09:15:50.000100", format = "%Y-%m-%d
> %H:%M:%OS",tz="GMT")
> myformat.POSIXct(myend)
>
> DF.w <- window( DF.z ,start = mystart, end = myend)
>
> myticks <- seq( mystart , to = myend , length = 5)
> mylabels <- format(myticks,"%H:%M:%OS")
>
> xyplot(  DF.w
>   , screens = c(1,1,1)
>   , type = "l"
>   , col = c("red","blue","black")
> )
>
> ## Error in prettyDate_TMP(x, ...) : range too small for min.n
>
> xyplot(  DF.w
>   , screens = c(1,1,1)
>   , type = "l"
>   

Re: [R] strptime, date and conversion of week number into POSIX

2021-02-22 Thread Uwe Ligges

That monday does not exist. FOr the week before:

strptime(paste0("2020-52","-1"),format="%Y-%W-%u")
[1] "2020-12-28"

One week later is no longer in 2020, so there is no 53th week.

Best,
Uwe Ligges





On 22.02.2021 16:15, Patrick Giraudoux wrote:

Sorry to answer to myself, but the format was clearly incorrect in the
previous post. It should read, refering to the 1th day of the week:

strptime(paste0(mydate,"-1"),format="%Y-%W-%u")

It converts better, but with a NA on week 53


strptime(paste0(pays$year_week,"-1"),format="%Y-%W-%u")

   [1] "2020-01-06 CET"  "2020-01-13 CET"  "2020-01-20 CET"  "2020-01-27 CET"
   [5] "2020-02-03 CET"  "2020-02-10 CET"  "2020-02-17 CET"  "2020-02-24 CET"
   [9] "2020-03-02 CET"  "2020-03-09 CET"  "2020-03-16 CET"  "2020-03-23 CET"
[13] "2020-03-30 CEST" "2020-04-06 CEST" "2020-04-13 CEST" "2020-04-20 CEST"
[17] "2020-04-27 CEST" "2020-05-04 CEST" "2020-05-11 CEST" "2020-05-18 CEST"
[21] "2020-05-25 CEST" "2020-06-01 CEST" "2020-06-08 CEST" "2020-06-15 CEST"
[25] "2020-06-22 CEST" "2020-06-29 CEST" "2020-07-06 CEST" "2020-07-13 CEST"
[29] "2020-07-20 CEST" "2020-07-27 CEST" "2020-08-03 CEST" "2020-08-10 CEST"
[33] "2020-08-17 CEST" "2020-08-24 CEST" "2020-08-31 CEST" "2020-09-07 CEST"
[37] "2020-09-14 CEST" "2020-09-21 CEST" "2020-09-28 CEST" "2020-10-05 CEST"
[41] "2020-10-12 CEST" "2020-10-19 CEST" "2020-10-26 CET"  "2020-11-02 CET"
[45] "2020-11-09 CET"  "2020-11-16 CET"  "2020-11-23 CET"  "2020-11-30 CET"
[49] "2020-12-07 CET"  "2020-12-14 CET"  "2020-12-21 CET"  "2020-12-28 CET"
[53] NA"2021-01-04 CET"  "2021-01-11 CET"  "2021-01-18 CET"
[57] "2021-01-25 CET"  "2021-02-01 CET"  "2021-02-08 CET"
Warning message:
In strptime(paste0(pays$year_week, "-1"), format = "%Y-%W-%u") :
(0-based) yday 369 in year 2020 is invalid


Any idea on how to handle this ?




Le 22/02/2021 à 15:26, Patrick Giraudoux a écrit :


Dear all,

I have a trouble trying to convert dates  given in character to POSIX.
The date is expressed as a year then the week number e.g. "2020-01"
(first week of 2020). I thought is can be converted as following:

strptime(mydate,format="%Y-%W")

%W refering to the week of the year as decimal number (00–53) using
Monday as the first day of week (and typically with the first Monday
of the year as day 1 of week 1), as indicated in the doc.

However, I got this result, with the month fixed to 02 (february) and
day 22 (only the year is  converted correctly):

strptime(mydate,format="%Y-%W") [1] "2020-02-22 CET" "2020-02-22 CET"
"2020-02-22 CET" "2020-02-22 CET" [5] "2020-02-22 CET" "2020-02-22
CET" "2020-02-22 CET" "2020-02-22 CET" [9] "2020-02-22 CET"
"2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" [13] "2020-02-22
CET" "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" [17]
"2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET"
[21] "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" "2020-02-22
CET" [25] "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET"
"2020-02-22 CET" [29] "2020-02-22 CET" "2020-02-22 CET" "2020-02-22
CET" "2020-02-22 CET" [33] "2020-02-22 CET" "2020-02-22 CET"
"2020-02-22 CET" "2020-02-22 CET" [37] "2020-02-22 CET" "2020-02-22
CET" "2020-02-22 CET" "2020-02-22 CET" [41] "2020-02-22 CET"
"2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" [45] "2020-02-22
CET" "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" [49]
"2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET"
[53] "2020-02-22 CET" "2021-02-22 CET" "2021-02-22 CET" "2021-02-22
CET" [57] "2021-02-22 CET" "2021-02-22 CET" "2021-02-22 CET"

You'll find below a dump of "mydate" you can copy and paster if you
need a try

Any hint welcome...

Best,

Patrick

mydate <-
c("2020-01", "2020-02", "2020-03", "2020-04", "2020-05", "2020-06",
"2020-07", "2020-08", "2020-09", "2020-10", "2020-11", "2020-12",
"2020-13", "2020-14", "2020-15", "2020-16", "2020-17", "2020-18",
"2020-19", "2020-20", "2020-21", "2020-22", "2020-23", "2020-24",
"2020-25", "2020-26", "2020-27", "2020-28", "2020-29", "2020-30",
"2020-31", "2020-32", "2020-33", "2020-34", "2020-35", "2020-36",
"2020-37", "2020-38", "2020-39", "2020-40", "2020-41", "2020-42",
"2020-43", "2020-44", "2020-45", "2020-46", "2020-47", "2020-48",
"2020-49", "2020-50", "2020-51", "2020-52", "2020-53", "2021-01",
"2021-02", "2021-03", "2021-04", "2021-05", "2021-06")




[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproduc

Re: [R] strptime, date and conversion of week number into POSIX

2021-02-22 Thread Patrick Giraudoux
Thanks Uwe and  Bert,
I got the essential now, and can manage. Date handling stays quite a 
challenge with a variable number of weeks in a year, but I can 
understand why. Means eye-control (or NA detection) of strptime 
conversion stays necessary...
Best,
Patrick


Le 22/02/2021 à 17:09, Uwe Ligges a écrit :
> That monday does not exist. FOr the week before:
>
> strptime(paste0("2020-52","-1"),format="%Y-%W-%u")
> [1] "2020-12-28"
>
> One week later is no longer in 2020, so there is no 53th week.
>
> Best,
> Uwe Ligges
>
>
>
>
>
> On 22.02.2021 16:15, Patrick Giraudoux wrote:
>> Sorry to answer to myself, but the format was clearly incorrect in the
>> previous post. It should read, refering to the 1th day of the week:
>>
>> strptime(paste0(mydate,"-1"),format="%Y-%W-%u")
>>
>> It converts better, but with a NA on week 53
>>
>>> strptime(paste0(pays$year_week,"-1"),format="%Y-%W-%u")
>>    [1] "2020-01-06 CET"  "2020-01-13 CET"  "2020-01-20 CET" 
>> "2020-01-27 CET"
>>    [5] "2020-02-03 CET"  "2020-02-10 CET"  "2020-02-17 CET" 
>> "2020-02-24 CET"
>>    [9] "2020-03-02 CET"  "2020-03-09 CET"  "2020-03-16 CET" 
>> "2020-03-23 CET"
>> [13] "2020-03-30 CEST" "2020-04-06 CEST" "2020-04-13 CEST" 
>> "2020-04-20 CEST"
>> [17] "2020-04-27 CEST" "2020-05-04 CEST" "2020-05-11 CEST" 
>> "2020-05-18 CEST"
>> [21] "2020-05-25 CEST" "2020-06-01 CEST" "2020-06-08 CEST" 
>> "2020-06-15 CEST"
>> [25] "2020-06-22 CEST" "2020-06-29 CEST" "2020-07-06 CEST" 
>> "2020-07-13 CEST"
>> [29] "2020-07-20 CEST" "2020-07-27 CEST" "2020-08-03 CEST" 
>> "2020-08-10 CEST"
>> [33] "2020-08-17 CEST" "2020-08-24 CEST" "2020-08-31 CEST" 
>> "2020-09-07 CEST"
>> [37] "2020-09-14 CEST" "2020-09-21 CEST" "2020-09-28 CEST" 
>> "2020-10-05 CEST"
>> [41] "2020-10-12 CEST" "2020-10-19 CEST" "2020-10-26 CET" "2020-11-02 
>> CET"
>> [45] "2020-11-09 CET"  "2020-11-16 CET"  "2020-11-23 CET" "2020-11-30 
>> CET"
>> [49] "2020-12-07 CET"  "2020-12-14 CET"  "2020-12-21 CET" "2020-12-28 
>> CET"
>> [53] NA    "2021-01-04 CET"  "2021-01-11 CET" "2021-01-18 
>> CET"
>> [57] "2021-01-25 CET"  "2021-02-01 CET"  "2021-02-08 CET"
>> Warning message:
>> In strptime(paste0(pays$year_week, "-1"), format = "%Y-%W-%u") :
>>     (0-based) yday 369 in year 2020 is invalid
>>
>>
>> Any idea on how to handle this ?
>>
>>
>>
>>
>> Le 22/02/2021 à 15:26, Patrick Giraudoux a écrit :
>>>
>>> Dear all,
>>>
>>> I have a trouble trying to convert dates  given in character to POSIX.
>>> The date is expressed as a year then the week number e.g. "2020-01"
>>> (first week of 2020). I thought is can be converted as following:
>>>
>>> strptime(mydate,format="%Y-%W")
>>>
>>> %W refering to the week of the year as decimal number (00–53) using
>>> Monday as the first day of week (and typically with the first Monday
>>> of the year as day 1 of week 1), as indicated in the doc.
>>>
>>> However, I got this result, with the month fixed to 02 (february) and
>>> day 22 (only the year is  converted correctly):
>>>
>>> strptime(mydate,format="%Y-%W") [1] "2020-02-22 CET" "2020-02-22 CET"
>>> "2020-02-22 CET" "2020-02-22 CET" [5] "2020-02-22 CET" "2020-02-22
>>> CET" "2020-02-22 CET" "2020-02-22 CET" [9] "2020-02-22 CET"
>>> "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" [13] "2020-02-22
>>> CET" "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" [17]
>>> "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET"
>>> [21] "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" "2020-02-22
>>> CET" [25] "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET"
>>> "2020-02-22 CET" [29] "2020-02-22 CET" "2020-02-22 CET" "2020-02-22
>>> CET" "2020-02-22 CET" [33] "2020-02-22 CET" "2020-02-22 CET"
>>> "2020-02-22 CET" "2020-02-22 CET" [37] "2020-02-22 CET" "2020-02-22
>>> CET" "2020-02-22 CET" "2020-02-22 CET" [41] "2020-02-22 CET"
>>> "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" [45] "2020-02-22
>>> CET" "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" [49]
>>> "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET"
>>> [53] "2020-02-22 CET" "2021-02-22 CET" "2021-02-22 CET" "2021-02-22
>>> CET" [57] "2021-02-22 CET" "2021-02-22 CET" "2021-02-22 CET"
>>>
>>> You'll find below a dump of "mydate" you can copy and paster if you
>>> need a try
>>>
>>> Any hint welcome...
>>>
>>> Best,
>>>
>>> Patrick
>>>
>>> mydate <-
>>> c("2020-01", "2020-02", "2020-03", "2020-04", "2020-05", "2020-06",
>>> "2020-07", "2020-08", "2020-09", "2020-10", "2020-11", "2020-12",
>>> "2020-13", "2020-14", "2020-15", "2020-16", "2020-17", "2020-18",
>>> "2020-19", "2020-20", "2020-21", "2020-22", "2020-23", "2020-24",
>>> "2020-25", "2020-26", "2020-27", "2020-28", "2020-29", "2020-30",
>>> "2020-31", "2020-32", "2020-33", "2020-34", "2020-35", "2020-36",
>>> "2020-37", "2020-38", "2020-39", "2020-40", "2020-41", "2020-42",
>>> "2020-43", "2020-44", "2020-45", "2020-46", "2020-47", "2020-48",
>>> "2020-49", "2020-50", "2020-51", "2020-52", "2020-53", "2021-01",
>>> "2021-02", "2021-03", "20

[R] xyplot.zoo trouble with the index when I use microseconds (type POSIXct)

2021-02-22 Thread Laurent Rhelp

Dear R-Help-List,

   I have to process time series with a sampling frequency of 1 MHz.
I use the POSIXct format for the date-times with microsecond in a zoo 
object and the xyplot.zoo function to do the graphs.
As I show in the below example I had a trouble to plot the labels on the 
x-axis with an error message. I found a solution but I would like to 
know if I miss something.
The link 
https://stackoverflow.com/questions/7726034/how-r-formats-posixct-with-fractional-seconds 

helped me to understand how to print the POSIXct value to see the 
microseconds thanks to the function myformat.POSIXct:


myformat.POSIXct <- function(x, digits=6)
{
  x2 <- round(unclass(x), digits)
  attributes(x2) <- attributes(x)
  x <- as.POSIXlt(x2,origin="1970-01-01",tz="GMT")
  x$sec <- round(x$sec, digits)
  format.POSIXlt(x, paste("%Y-%m-%d %H:%M:%OS",digits,sep=""),tz="GMT")

}


## The example giving the error message:

library(lattice)
library(zoo)

##
options(digits = 16) # to see all the digits on the screen
options(digits.secs = 6) # to see the microseconds
# mock data
# a sine with a frequency f0 and two others with a delay
Fs <- 1e+6 # sampling frequency 1 MHz
Ts <- 1/Fs
# frequency of the sinus
f0 <- 10
t0 <- 1/f0
time <- seq(0, length = 1000, by = Ts)
A1 <- 1
y1 <- A1 * sin(2*pi*f0*time)
y2 <- 2 * A1 * sin(2*pi*f0*(time+0.02))
y3 <- 3 * A1 * sin(2*pi*f0*(time+0.05))
## creation of a dataframe:
##
DF <- data.frame( time = time, y1 = y1, y2 = y2, y3 = y3)
# Since I want to allow for the datetime POSIXct format on the x-axis
# for the plot I transform my dataframe in a zoo object
#
# say that my acquisition began at "2021-02-08 09:15:50.00"
#
mystart <- as.POSIXct("2021-02-08 09:15:50.00", format = "%Y-%m-%d 
%H:%M:%OS",tz="GMT")

mystart
# To see the correct datetime I use the myformat.POSIXct function
myformat.POSIXct(mystart)
##
## using the method seq.POSIXct as following doesn't work:
## mydatetime <- seq( mystart , length = nrow(DF), by = "0.01 sec")
## head( myformat.POSIXct(mydatetime) )
## if I use the following command it works:
mydatetime <- seq( mystart , length = nrow(DF), by = 0.01)
head( myformat.POSIXct(mydatetime) )
## I do the zoo object:
DF.z <- zoo(DF[,-1],order.by = mydatetime)
## We don't see the correct value for the index:
head(DF.z)
# time    y1 y2 y3
# 2021-02-08 09:15:50.00 0e+00 0.000e+00 
1.902113032590307e+00  3.673819061467132e-16
# 2021-02-08 09:15:50.00 1e-06 5.877852522924730e-01 
1.902113032590307e+00 -1.763355756877419e+00
# 2021-02-08 09:15:50.01 2e-06 9.510565162951535e-01 
1.175570504584947e+00 -2.853169548885460e+00
# 2021-02-08 09:15:50.03 3e-06 9.510565162951536e-01 
1.133099690464601e-15 -2.853169548885460e+00
# 2021-02-08 09:15:50.04 4e-06 5.877852522924736e-01 
-1.175570504584946e+00 -1.763355756877420e+00
# 2021-02-08 09:15:50.05 5e-06 5.665498452323003e-16 
-1.902113032590306e+00 -3.399299071393802e-15
# If I use myformat.POSIXct I see that the index is correct in the 
object DF:

head(myformat.POSIXct(index(DF.z)))
## and when I plot I have an error:
xyplot(   DF.z
  , screens = c(1,1,1)
  , type = "l"
  , col = c("red","blue","black")

)

# Error in prettyDate_TMP(x, ...) : range too small for min.n

# if I process by hand the plot of the labels on the x-axis it works:
#
myend <- tail(mydatetime,1)

myticks <- seq( mystart , to = myend , length = 5)
mylabels <- format(myticks,"%H:%M:%OS")

xyplot(  DF.z
 , screens = c(1,1,1)
 , type = "l"
 , col = c("red","blue","black")
 , scales = list(
 y= list(relation = "free", abbreviate=TRUE),
 x = list( at = myticks, labels = mylabels
   , rot = 45, cex = 0.5)
   )
)
# The microseconds are well taken into account with the window function
# if I want to plot only 100 microseconds but there is of course the same
# trouble for the plot

myend <- as.POSIXct("2021-02-08 09:15:50.000100", format = "%Y-%m-%d 
%H:%M:%OS",tz="GMT")

myformat.POSIXct(myend)

DF.w <- window( DF.z ,start = mystart, end = myend)

myticks <- seq( mystart , to = myend , length = 5)
mylabels <- format(myticks,"%H:%M:%OS")

xyplot(  DF.w
 , screens = c(1,1,1)
 , type = "l"
 , col = c("red","blue","black")
)

## Error in prettyDate_TMP(x, ...) : range too small for min.n

xyplot(  DF.w
 , screens = c(1,1,1)
 , type = "l"
 , col = c("red","blue","black")
 , scales = list(
   y= list(relation = "free", abbreviate=TRUE),
   x = list( at = myticks, labels = mylabels
 , rot = 45, cex = 0.5)
 )
)

May you please tell me if I miss something in the way to use POSIXct
with microseconds in a zoo object ?

Thank you
Laurent






--
L'absence de virus dans ce courrier électronique a été v

Re: [R] strptime, date and conversion of week number into POSIX

2021-02-22 Thread Bert Gunter
I think the relevant info from ?strptime is:

"For strptime the input string need not specify the date completely: it is
assumed that unspecified seconds, minutes or hours are zero, and an
unspecified year, month or day is the current one. (However, if a month is
specified, the day of that month has to be specified by %d or %e since the
current day of the month need not be valid for the specified month.) Some
components may be returned as NA (but an unknown tzone component is
represented by an empty string)."

I think this means that your strings cannot be converted by strptime() as
essential info is missing. Input from those with more date-time expertise
on this point would be welcome, however.

Cheers,
Bert
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, Feb 22, 2021 at 6:27 AM Patrick Giraudoux <
patrick.giraud...@univ-fcomte.fr> wrote:

> Dear all,
>
> I have a trouble trying to convert dates  given in character to POSIX.
> The date is expressed as a year then the week number e.g. "2020-01"
> (first week of 2020). I thought is can be converted as following:
>
> strptime(mydate,format="%Y-%W")
>
> %W refering to the week of the year as decimal number (00–53) using
> Monday as the first day of week (and typically with the first Monday of
> the year as day 1 of week 1), as indicated in the doc.
>
> However, I got this result, with the month fixed to 02 (february) and
> day 22 (only the year is  converted correctly):
>
> strptime(mydate,format="%Y-%W") [1] "2020-02-22 CET" "2020-02-22 CET"
> "2020-02-22 CET" "2020-02-22 CET" [5] "2020-02-22 CET" "2020-02-22 CET"
> "2020-02-22 CET" "2020-02-22 CET" [9] "2020-02-22 CET" "2020-02-22 CET"
> "2020-02-22 CET" "2020-02-22 CET" [13] "2020-02-22 CET" "2020-02-22 CET"
> "2020-02-22 CET" "2020-02-22 CET" [17] "2020-02-22 CET" "2020-02-22 CET"
> "2020-02-22 CET" "2020-02-22 CET" [21] "2020-02-22 CET" "2020-02-22 CET"
> "2020-02-22 CET" "2020-02-22 CET" [25] "2020-02-22 CET" "2020-02-22 CET"
> "2020-02-22 CET" "2020-02-22 CET" [29] "2020-02-22 CET" "2020-02-22 CET"
> "2020-02-22 CET" "2020-02-22 CET" [33] "2020-02-22 CET" "2020-02-22 CET"
> "2020-02-22 CET" "2020-02-22 CET" [37] "2020-02-22 CET" "2020-02-22 CET"
> "2020-02-22 CET" "2020-02-22 CET" [41] "2020-02-22 CET" "2020-02-22 CET"
> "2020-02-22 CET" "2020-02-22 CET" [45] "2020-02-22 CET" "2020-02-22 CET"
> "2020-02-22 CET" "2020-02-22 CET" [49] "2020-02-22 CET" "2020-02-22 CET"
> "2020-02-22 CET" "2020-02-22 CET" [53] "2020-02-22 CET" "2021-02-22 CET"
> "2021-02-22 CET" "2021-02-22 CET" [57] "2021-02-22 CET" "2021-02-22 CET"
> "2021-02-22 CET"
>
> You'll find below a dump of "mydate" you can copy and paster if you need
> a try
>
> Any hint welcome...
>
> Best,
>
> Patrick
>
> mydate <-
> c("2020-01", "2020-02", "2020-03", "2020-04", "2020-05", "2020-06",
> "2020-07", "2020-08", "2020-09", "2020-10", "2020-11", "2020-12",
> "2020-13", "2020-14", "2020-15", "2020-16", "2020-17", "2020-18",
> "2020-19", "2020-20", "2020-21", "2020-22", "2020-23", "2020-24",
> "2020-25", "2020-26", "2020-27", "2020-28", "2020-29", "2020-30",
> "2020-31", "2020-32", "2020-33", "2020-34", "2020-35", "2020-36",
> "2020-37", "2020-38", "2020-39", "2020-40", "2020-41", "2020-42",
> "2020-43", "2020-44", "2020-45", "2020-46", "2020-47", "2020-48",
> "2020-49", "2020-50", "2020-51", "2020-52", "2020-53", "2021-01",
> "2021-02", "2021-03", "2021-04", "2021-05", "2021-06")
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] error in Rstudio

2021-02-22 Thread Duncan Murdoch

On 22/02/2021 10:01 a.m., Κυριάκος Γιαλλουράκης wrote:

Greetings,
I tried to open R-studio(windows 10 pro) but instead of running the app, my
screen opens a window saying 'loadlibrary failed with error 1114: some
preparation routine of a DLL failed'
I deleted both R and R-studio, but when I downloaded them again(both in
latest edition), the same thing appears.

Please help me with my problem,
Best Regards,


What happens if you try to open Rgui or command line R?

Duncan Murdoch

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] error in Rstudio

2021-02-22 Thread Κυριάκος Γιαλλουράκης
Greetings,
I tried to open R-studio(windows 10 pro) but instead of running the app, my
screen opens a window saying 'loadlibrary failed with error 1114: some
preparation routine of a DLL failed'
I deleted both R and R-studio, but when I downloaded them again(both in
latest edition), the same thing appears.

Please help me with my problem,
Best Regards,
Kyriakos

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] strptime, date and conversion of week number into POSIX

2021-02-22 Thread Patrick Giraudoux
Sorry to answer to myself, but the format was clearly incorrect in the 
previous post. It should read, refering to the 1th day of the week:

strptime(paste0(mydate,"-1"),format="%Y-%W-%u")

It converts better, but with a NA on week 53

> strptime(paste0(pays$year_week,"-1"),format="%Y-%W-%u")
  [1] "2020-01-06 CET"  "2020-01-13 CET"  "2020-01-20 CET"  "2020-01-27 CET"
  [5] "2020-02-03 CET"  "2020-02-10 CET"  "2020-02-17 CET"  "2020-02-24 CET"
  [9] "2020-03-02 CET"  "2020-03-09 CET"  "2020-03-16 CET"  "2020-03-23 CET"
[13] "2020-03-30 CEST" "2020-04-06 CEST" "2020-04-13 CEST" "2020-04-20 CEST"
[17] "2020-04-27 CEST" "2020-05-04 CEST" "2020-05-11 CEST" "2020-05-18 CEST"
[21] "2020-05-25 CEST" "2020-06-01 CEST" "2020-06-08 CEST" "2020-06-15 CEST"
[25] "2020-06-22 CEST" "2020-06-29 CEST" "2020-07-06 CEST" "2020-07-13 CEST"
[29] "2020-07-20 CEST" "2020-07-27 CEST" "2020-08-03 CEST" "2020-08-10 CEST"
[33] "2020-08-17 CEST" "2020-08-24 CEST" "2020-08-31 CEST" "2020-09-07 CEST"
[37] "2020-09-14 CEST" "2020-09-21 CEST" "2020-09-28 CEST" "2020-10-05 CEST"
[41] "2020-10-12 CEST" "2020-10-19 CEST" "2020-10-26 CET"  "2020-11-02 CET"
[45] "2020-11-09 CET"  "2020-11-16 CET"  "2020-11-23 CET"  "2020-11-30 CET"
[49] "2020-12-07 CET"  "2020-12-14 CET"  "2020-12-21 CET"  "2020-12-28 CET"
[53] NA"2021-01-04 CET"  "2021-01-11 CET"  "2021-01-18 CET"
[57] "2021-01-25 CET"  "2021-02-01 CET"  "2021-02-08 CET"
Warning message:
In strptime(paste0(pays$year_week, "-1"), format = "%Y-%W-%u") :
   (0-based) yday 369 in year 2020 is invalid


Any idea on how to handle this ?




Le 22/02/2021 à 15:26, Patrick Giraudoux a écrit :
>
> Dear all,
>
> I have a trouble trying to convert dates  given in character to POSIX. 
> The date is expressed as a year then the week number e.g. "2020-01" 
> (first week of 2020). I thought is can be converted as following:
>
> strptime(mydate,format="%Y-%W")
>
> %W refering to the week of the year as decimal number (00–53) using 
> Monday as the first day of week (and typically with the first Monday 
> of the year as day 1 of week 1), as indicated in the doc.
>
> However, I got this result, with the month fixed to 02 (february) and 
> day 22 (only the year is  converted correctly):
>
> strptime(mydate,format="%Y-%W") [1] "2020-02-22 CET" "2020-02-22 CET" 
> "2020-02-22 CET" "2020-02-22 CET" [5] "2020-02-22 CET" "2020-02-22 
> CET" "2020-02-22 CET" "2020-02-22 CET" [9] "2020-02-22 CET" 
> "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" [13] "2020-02-22 
> CET" "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" [17] 
> "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" 
> [21] "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 
> CET" [25] "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" 
> "2020-02-22 CET" [29] "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 
> CET" "2020-02-22 CET" [33] "2020-02-22 CET" "2020-02-22 CET" 
> "2020-02-22 CET" "2020-02-22 CET" [37] "2020-02-22 CET" "2020-02-22 
> CET" "2020-02-22 CET" "2020-02-22 CET" [41] "2020-02-22 CET" 
> "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" [45] "2020-02-22 
> CET" "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" [49] 
> "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" "2020-02-22 CET" 
> [53] "2020-02-22 CET" "2021-02-22 CET" "2021-02-22 CET" "2021-02-22 
> CET" [57] "2021-02-22 CET" "2021-02-22 CET" "2021-02-22 CET"
>
> You'll find below a dump of "mydate" you can copy and paster if you 
> need a try
>
> Any hint welcome...
>
> Best,
>
> Patrick
>
> mydate <-
> c("2020-01", "2020-02", "2020-03", "2020-04", "2020-05", "2020-06",
> "2020-07", "2020-08", "2020-09", "2020-10", "2020-11", "2020-12",
> "2020-13", "2020-14", "2020-15", "2020-16", "2020-17", "2020-18",
> "2020-19", "2020-20", "2020-21", "2020-22", "2020-23", "2020-24",
> "2020-25", "2020-26", "2020-27", "2020-28", "2020-29", "2020-30",
> "2020-31", "2020-32", "2020-33", "2020-34", "2020-35", "2020-36",
> "2020-37", "2020-38", "2020-39", "2020-40", "2020-41", "2020-42",
> "2020-43", "2020-44", "2020-45", "2020-46", "2020-47", "2020-48",
> "2020-49", "2020-50", "2020-51", "2020-52", "2020-53", "2021-01",
> "2021-02", "2021-03", "2021-04", "2021-05", "2021-06")
>


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] strptime, date and conversion of week number into POSIX

2021-02-22 Thread Patrick Giraudoux
Dear all,

I have a trouble trying to convert dates  given in character to POSIX. 
The date is expressed as a year then the week number e.g. "2020-01" 
(first week of 2020). I thought is can be converted as following:

strptime(mydate,format="%Y-%W")

%W refering to the week of the year as decimal number (00–53) using 
Monday as the first day of week (and typically with the first Monday of 
the year as day 1 of week 1), as indicated in the doc.

However, I got this result, with the month fixed to 02 (february) and 
day 22 (only the year is  converted correctly):

strptime(mydate,format="%Y-%W") [1] "2020-02-22 CET" "2020-02-22 CET" 
"2020-02-22 CET" "2020-02-22 CET" [5] "2020-02-22 CET" "2020-02-22 CET" 
"2020-02-22 CET" "2020-02-22 CET" [9] "2020-02-22 CET" "2020-02-22 CET" 
"2020-02-22 CET" "2020-02-22 CET" [13] "2020-02-22 CET" "2020-02-22 CET" 
"2020-02-22 CET" "2020-02-22 CET" [17] "2020-02-22 CET" "2020-02-22 CET" 
"2020-02-22 CET" "2020-02-22 CET" [21] "2020-02-22 CET" "2020-02-22 CET" 
"2020-02-22 CET" "2020-02-22 CET" [25] "2020-02-22 CET" "2020-02-22 CET" 
"2020-02-22 CET" "2020-02-22 CET" [29] "2020-02-22 CET" "2020-02-22 CET" 
"2020-02-22 CET" "2020-02-22 CET" [33] "2020-02-22 CET" "2020-02-22 CET" 
"2020-02-22 CET" "2020-02-22 CET" [37] "2020-02-22 CET" "2020-02-22 CET" 
"2020-02-22 CET" "2020-02-22 CET" [41] "2020-02-22 CET" "2020-02-22 CET" 
"2020-02-22 CET" "2020-02-22 CET" [45] "2020-02-22 CET" "2020-02-22 CET" 
"2020-02-22 CET" "2020-02-22 CET" [49] "2020-02-22 CET" "2020-02-22 CET" 
"2020-02-22 CET" "2020-02-22 CET" [53] "2020-02-22 CET" "2021-02-22 CET" 
"2021-02-22 CET" "2021-02-22 CET" [57] "2021-02-22 CET" "2021-02-22 CET" 
"2021-02-22 CET"

You'll find below a dump of "mydate" you can copy and paster if you need 
a try

Any hint welcome...

Best,

Patrick

mydate <-
c("2020-01", "2020-02", "2020-03", "2020-04", "2020-05", "2020-06",
"2020-07", "2020-08", "2020-09", "2020-10", "2020-11", "2020-12",
"2020-13", "2020-14", "2020-15", "2020-16", "2020-17", "2020-18",
"2020-19", "2020-20", "2020-21", "2020-22", "2020-23", "2020-24",
"2020-25", "2020-26", "2020-27", "2020-28", "2020-29", "2020-30",
"2020-31", "2020-32", "2020-33", "2020-34", "2020-35", "2020-36",
"2020-37", "2020-38", "2020-39", "2020-40", "2020-41", "2020-42",
"2020-43", "2020-44", "2020-45", "2020-46", "2020-47", "2020-48",
"2020-49", "2020-50", "2020-51", "2020-52", "2020-53", "2021-01",
"2021-02", "2021-03", "2021-04", "2021-05", "2021-06")


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.