Thank you for the quick follow up, Duncan. Unfortunately extend=TRUE is called internally in various instances such as when replacing parts of the time-series with window<-.ts Consider the following examples of time series with ugly values: x = 1:22 foo = ts(x, start = 1.5, end = 106.5, frequency = 0.2) # a ts of 525 cycles bar = ts(x, start = 2.5, end = 107.5, frequency = 0.2) # a ts of 525 cycles starting 5 cycles later than foo qux = ts(x, start = 2.5, end = 102.5, frequency = 0.2) # a ts of 500 cycles starting 5 cycles later than foo
# extraction works fine window(foo, start = 20, end = 30) # works fine window(bar, start = 20, end = 30) # works fine window(qux, start = 20, end = 30) # works fine # assignment fails in different ways for bar and qux window(foo, start = 20, end = 30) <- NA # works fine window(bar, start = 20, end = 30) <- NA # ERROR: "invalid time series parameters specified" window(qux, start = 20, end = 30) <- NA # ERROR: "times to be replaced do not match" If extraction works fine, there's no reason why replacing the values should fail. I don't have an account on bugs.r-project.org yet. I'd be available to do the report if I'm assigned one. Best, Johann On Thu, 5 Dec 2019 at 17:46, Duncan Murdoch <murdoch.dun...@gmail.com> wrote: > On 05/12/2019 11:00 a.m., Johann R. Kleinbub wrote: > > It's been three months without an answer, is it ok to thread bump? > > Would someone provide a pointer? > > I agree it's a bug, and agree with your analysis. You should report it > on bugs.r-project.org. (If you don't have an account there, let us > know, and either someone will give you one, or someone will report it > for you.) > > As a workaround, I don't see it happening with extend=FALSE, but of > course that might not suit your needs in general. > > Duncan Murdoch > > > > > > > Thank you for your consideration, > > Johann > > > > > > On Mon, 16 Sep 2019 at 15:53, Johann R. Kleinbub < > johann.klein...@gmail.com> > > wrote: > >> > >> I am developing a package to analyse physiological time-series and I > > thought that the most reliable and robust solution was to base it on the > > native stats::ts class. In my domain it is common to express series > > frequencies as samples-per-second. So ts(..., frequency=10) would mean a > > signal sampled 10 times every second, and ts(..., frequency = 1) a signal > > sampled every second. Following this logic, a few slower signals are > > sampled every 5 seconds (or more), resulting in a frequency of e.g. 0.2 > >> Nowhere in the documentation is stated that the frequency must be an > > integer value, but using fractional values gives inconsistent results. > >> For instance, in this example, foo and bar are identical, just with > > start-end values shifted by 1. Yet when extracting an arbitrary window, > the > > 'bar' series gives error. > >> > >> x = 1:22 > >> foo = ts(x, start = 1.5, end = 106.5, frequency = 0.2) > >> bar = ts(x, start = 2.5, end = 107.5, frequency = 0.2) > >> > >> window(foo, start = 20, end = 30, extend=TRUE) > >> > >> # Time Series: > >> # Start = 20 > >> # End = 25 > >> # Frequency = 0.2 > >> # [1] 5 6 > >> > >> window(bar, start = 20, end = 30, extend=TRUE) > >> > >> # Error in attr(y, "tsp") <- c(ystart, yend, xfreq) : > >> # invalid time series parameters specified > >> > >> The reason is in the rounding procedures for ystart and yend at the end > > of the stats::window function. For the 'foo' series the ystart and yend > > values are calculated as: c(20, 25), whereas for the 'bar' series, they > > become c(20, 30) although the window should be of the very same size in > > both cases. (A further discussion on the example is at: > > https://stackoverflow.com/questions/57928054 ) > >> Should I report a bug or am I misunderstanding something? > >> > >> -- > >> Johann R. Kleinbub, PhD > >> University of Padova > >> FISPPA Dep. - Section of Applied Psychology > >> Cell: +39 3495986373 > > > > > > > > -- > > Johann R. Kleinbub, PhD > > University of Padova > > FISPPA Dep. - Section of Applied Psychology > > Cell: +39 3495986373 > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-devel@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-devel > > > > -- Johann R. Kleinbub, PhD University of Padova FISPPA Dep. - Section of Applied Psychology Cell: +39 3495986373 [[alternative HTML version deleted]] ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel