[R] question about window and inserting value

Gabor Grothendieck
Tue, 22 Jun 2004 11:08:57 -0000

Try this:


"window<-" <-
function(x,start=stats::start(x),end=stats::end(x),value) {
	x[match(window(time(x),start=start,end=end),time(x))] <- value
	x
}

window(x.ts, start=c(2000,3), end=c(2000,3)) <- 10




Laura Holt <lauraholt_983 <at> hotmail.com> writes:

:
: Hi again R People:
:
: I have the following time series:
: >x.ts
:        Jan   Feb   Mar   Apr   May   Jun   Jul   Aug   Sep
: 2000  0.95  0.66  0.83  0.66 -1.45 -1.25  0.33  1.03 -0.48
: 2001  2.55  1.21 -1.10 -0.63  0.01 -2.20 -0.51  1.12  1.11
: 2002 -1.37  0.55 -0.63 -0.56  0.92 -1.73  0.59  0.77  0.30
: 2003  0.55 -0.01 -0.54  2.27 -1.29 -0.23  0.09 -0.50 -0.61
:        Oct   Nov   Dec
: 2000  0.84 -1.35  1.51
: 2001 -1.68  0.32 -0.97
: 2002 -1.74 -1.30  1.61
: 2003  0.25  0.66 -0.05
: >#For the March 2001 value:
: >window(x.ts,start=c(2001,3),end=c(2001,3))
:       Mar
: 2001 -1.1
: >#Fine
: >window(x.ts,start=c(2001,3),end=c(2001,3)) <- 10
: Error: couldn't find function "window<-"
: >#Doesn't work
: >
:
: Is there a good way to insert the value into the March 2001 location,
: please?
: other than:
: x.ts[15] <- 10
:
: Thanks in advance!
:
: R Version 1.9.0  for Windows
:
: Sincerely,
: Laura Holt
: mailto: lauraholt_983 <at> hotmail.com
:
: ______________________________________________
: R-help <at> stat.math.ethz.ch mailing list
: https://www.stat.math.ethz.ch/mailman/listinfo/r-help
: PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html