[R] Integration and Loop in R
Lorenzo Isella
lorenzo.isella at gmail.com
Fri Aug 4 10:23:06 CEST 2006
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
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
Lorenzo
More information about the R-help
mailing list