evaluation of exploration values

Tue 22 July 2014
English: Map of the area around the village of...

Evaluation of occupation type over a grid (Photo credit: Wikipedia)

For some application, it is usefull to evaluate some physical value over a grid. For each dimension of the grid, the order of magnitude to use is not obvious.Watch movie online The Transporter Refueled (2015)

grid evaluation

the function expand.grid() is suited

a <- expand.grid(c(1:10), 2*c(0:4)+1)
b <- apply(a, 1, function(x){x[1] + 1/2 * x[2]})

the result is:

> cbind(a, b)
   Var1 Var2    b
1     1    1  1.5
2     2    1  2.5
3     3    1  3.5
4     4    1  4.5
5     5    1  5.5
6     6    1  6.5
7     7    1  7.5
8     8    1  8.5
9     9    1  9.5
10   10    1 10.5
11    1    3  2.5
12    2    3  3.5
13    3    3  4.5
14    4    3  5.5
15    5    3  6.5
16    6    3  7.5
17    7    3  8.5
18    8    3  9.5
19    9    3 10.5
20   10    3 11.5
21    1    5  3.5
22    2    5  4.5
23    3    5  5.5
24    4    5  6.5
25    5    5  7.5
26    6    5  8.5
27    7    5  9.5
28    8    5 10.5
29    9    5 11.5
30   10    5 12.5
31    1    7  4.5
32    2    7  5.5
33    3    7  6.5
34    4    7  7.5
35    5    7  8.5
36    6    7  9.5
37    7    7 10.5
38    8    7 11.5
39    9    7 12.5
40   10    7 13.5
41    1    9  5.5
42    2    9  6.5
43    3    9  7.5
44    4    9  8.5
45    5    9  9.5
46    6    9 10.5
47    7    9 11.5
48    8    9 12.5
49    9    9 13.5
50   10    9 14.5

order of magnitude exploration

This part is straightforward. It consists in computing the values to give to the expand.grid() function using expand.grid():

var1 <- apply(expand.grid(c(1,2,5), c(-1:3)), 1, function(x){x[1]* 10^(x[2])})

Note: if you want to draw this lines, abline() is suited

Related articles

Category: tools Tagged: Programming R Regular grid how to programming

Page 1 of 1