Re: [R] r programming help

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Thu 23 Jun 2005 - 00:03:56 EST

Mohammad Ehsanul Karim <wildscop@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@biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Thu Jun 23 00:10:40 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:56 EST