[R] Odp: Programming: loop versus vector oriented

Jan private jrheinlaender at gmx.de
Thu Sep 16 13:22:05 CEST 2010


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