[R] Odp: Programming: loop versus vector oriented

Petr PIKAL petr.pikal at precheza.cz
Fri Sep 17 08:19:54 CEST 2010


Hi Jan

but I think this is how your code really works. Did you try it?

Regards
Petr

Jan private <jrheinlaender at gmx.de> napsal dne 16.09.2010 13:22:05:

> Hello Petr,
> 
> > If you want to get results of your function for a vector of reynolds 
and 
> > dk you can use function outer and probably get rid of for cycle in the 

> > function.
> > 
> > outer(c(100, 530,2410), c(10, 150,200),lambda_wall)
> >           [,1]       [,2]       [,3]
> > [1,] 0.6400000 0.64000000 0.64000000
> > [2,] 0.1207547 0.12075472 0.12075472
> > [3,] 0.1081338 0.04515774 0.04515774
> 
> that gives me an array as an answer (and does more calculations than
> necessary, in this case 9 instead of 3). The result should be a vector.
> 
> The function should work on the nth elements of the two input vectors
> and put the result into the nth element of the output vector. So it
> would work like c <- a + b, only instead of '+' there are more complex
> calculations.
> 
> Best regards,
>    Jan
> 
> 
> 
>



More information about the R-help mailing list