[R] Problem with apply list to function: numerical expression has 4 elements: only the first used

Narua maria.mi8 at gmx.de
Sun May 24 15:30:13 CEST 2015

Dear kd,
thanks for your fast reply :-D
hm, I thougth, F is normally the abbrevation, but in R FALSE represents
Anyway, your function works.

I had actually a little more complicate functions (put I posted in the forum
first an easier example):
> F(5,3)
[1] 0.4946433
> F(5,5)
[1] 1
therefore, 0.4946433 is the distribution of b=3 with a=5 Elements.

FInv<-function(s,a,b) if(isTRUE(all.equal(F(a,b),s, tolerance=0.00001)))
cat("F(",s,",",a,",",b,") equals s; ") else cat("F(",a,",",b,") does not
equal to s; ")
FInv is the reverse function. you put a probability in the function and
recieve the distribution b of a special a.
I wanted to have a function FInv' to pass on s for all a and all b to
FInv(s,a,b) in order to find out, which probability fits to which a and b.

And I couln't pass on a and b so easily, I got the error: "In 1:i :
numerical expression has 4 elements: only the first used "
I think, the reason is, that R expects a number, but receives a list, and
that produces the error.

I tried 
> FooInv<-function(s) foreach(i=1:10)%do%sapply(x,FInv,s=s,k=i) and that
> works:
> FooInv(0.4946433)
F(s = 0.4946433 ,m = 5 ,k = 3 ) equals s; [[1]]

Foreach is a for-loop, and sapply matches FInv for every element of the list

But now another problem occured:
Obviously R gets anywhere a NULL-pointer, because the full output is:
F(s = 0.4946433 ,m = 5 ,k = 3 ) equals s; [[1]]




in every loop.

Do you know how I can get rid of the NULL-outputs?

if this problem is solved, I have all I need in order to calculate the
distribution and its inverse function :-)

Thanks in advance,

View this message in context: http://r.789695.n4.nabble.com/Problem-with-apply-list-to-function-numerical-expression-has-4-elements-only-the-first-used-tp4707588p4707611.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list