[R] The Percentile of a User-Defined pdf

Dieter Menne dieter.menne at menne-biomed.de
Sun Jan 2 10:50:19 CET 2011



Nissim Kaufmann wrote:
> 
> 
> J=sapply(xc, function(xc) {integrate(function(x) {
>    sapply(y, function(x) {
>      integrate(function(y) {
>        sapply(x, function(y) 1/(1+x^2+y^2))
>      }, -c, c)$value
>    })
>   }, -c, xc)$value
>  })
> 
> 

Once you are inside the first "{", R only knows about the x it received in
as a parameter (assuming there is no global y). I have not checked the
details of the code (it looks overly complicated), but 

   sapply(x, function(y) {

could work. In theory, keeping function(x) would also work, but I suggest
that you use another variable name in inner nests to avoid confusion (human,
not CPU).

My favorite step in developing nested xapply is to first remove all code and
only put a 

print(str(x))

inside the function, so I can clearly see what is passed in.

Dieter







            
-- 
View this message in context: http://r.789695.n4.nabble.com/The-Percentile-of-a-User-Defined-pdf-tp3170672p3170786.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list