On 4 Aug 2006 at 10:23, Lorenzo Isella wrote:
Date sent: Fri, 4 Aug 2006 10:23:06 +0200 From: "Lorenzo Isella" <[EMAIL PROTECTED]> To: r-help@stat.math.ethz.ch Subject: [R] Integration and Loop in R > Dear All, > I have seldom needed to use loops in R, but now I need to code a loop > with a stride different from one. In the R manual I downloaded I have > the example: > xc <- split(x, ind) > yc <- split(y, ind) > for (i in > 1:length(yc)) { > plot(xc[[i]], yc[[i]]); > abline(lsfit(xc[[i]], yc[[i]])) > } > but in my case I'd like to add a condition so that i varies by 4 from You can make i vary as you wish. e.g. steps <- seq(1,40,4) for (i in steps) ...... > one go to the following one. I cannot figure out the right syntax, can > anyone help here? Another thing (which could possibly solve my > problem): I had a look at integrate command in R. It seems to require > an object defined as a function to carry out the integration. What if > I simply have a list of data values? How can I coerce them into a > function recognized by R? Furthermore, are there R routines to carry > out the integration on a non-equally spaced 1D grid? Best Regards Try to look at splinefun or approxfun. HTH Petr > > Lorenzo > > ______________________________________________ > 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 and provide commented, > minimal, self-contained, reproducible code. Petr Pikal [EMAIL PROTECTED] ______________________________________________ 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 and provide commented, minimal, self-contained, reproducible code.