[R] Integrate functions with loops

A.Brennan A.Brennan at sheffield.ac.uk
Mon Sep 19 12:09:18 CEST 2005


Thanks Sundar
what you suggested worked fine 

> You will see that "x" is a vector and "tt[i]^x" returns a vector of the 
> same length. You are trying to place this vector into "a[i]" which is 
> length 1. Try the following *untested* code instead:
> 
> <untested>
> integrandtotest <- function(x) {
>    sum(sapply(x, function(xi) sum(tt^xi)))
> }

except you are summing twice so it should be.........

integrandtotest <- function(x) {(sapply(x, function(xi) sum(tt^xi)))


Alan Brennan
Director of Health Economics and Decision Science
http://www.shef.ac.uk/scharr/sections/heds
ScHARR
School of Health and Related Research
University of Sheffield
Regent Ct
30 Regent St
Sheffield S1 4DA
Tel:+44 (0)114 2220684
Fax:+44 (0)114 2724095
e-mail:a.brennan at sheffield.ac.uk




More information about the R-help mailing list