[R] r programming help
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Wed Jun 22 16:03:56 CEST 2005
Mohammad Ehsanul Karim <wildscop at yahoo.com> writes:
> Dear list,
>
> Is there anyway i can make the following formula short
> by r-programming?
>
> CYCLE.n<-c(NA,
> WET[1]*DRY[1],
> WET[1]*DRY[2]+WET[2]*DRY[1],
> WET[1]*DRY[3]+WET[2]*DRY[2]+WET[3]*DRY[1],
....
As far as I can see:
z <- toeplitz(DRY)
z[upper.tri(z)] <- 0
c(NA, z %*% WET)
or convolve() with suitable options, padding, and/or cutting (but
beware, there could be devils in the details). convolve(WET,DRY,
type="o") gives you about twice what you need, I believe.
--
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list