Re: [R] Integration and Loop in R

From: Petr Pikal <petr.pikal_at_precheza.cz>
Date: Fri 04 Aug 2006 - 18:50:24 EST

On 4 Aug 2006 at 10:23, Lorenzo Isella wrote:

Date sent:      	Fri, 4 Aug 2006 10:23:06 +0200
From:           	"Lorenzo Isella" <lorenzo.isella@gmail.com>
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
petr.pikal@precheza.cz



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. Received on Fri Aug 04 18:54:39 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 04 Aug 2006 - 20:18:54 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.