How to display dummy values in oracle query [duplicate] - oracle

This question already has answers here:
generate duplicate rows in Select statement in Oracle
(2 answers)
Closed 9 days ago.
I have a student table in my oracle database with only two records for studentid 1002 for the month of march.
enter image description here
The two records are on date 14-Mar-11 and 20-Mar-11 as shown in the image.
I want to display dummy fake values on dates where their is no record in the table starting from 01-Mar-11 to 31-Mar-11.
My query should show dummy values and the actual values for this specific student and this specific month.
I need a SQL query for my oracle table to check row where their is no data and fill for each month as shown in the image.
enter image description here
My SQL query should show results for each student his old values and new values on row where their is no transaction.

Here's one option; it uses calendar for each student in source table, whose dates range from first day of the first month to the last day of the last month in date span. It is then outer joined to source table to produce final result.
Old/new value is fetched randomly.
Sample data:
SQL> with
2 student (studentid, datum, oldvalue, newvalue) as
3 (select 1112, date '2011-03-14', 50, 30 from dual union all
4 select 1112, date '2011-03-20', 30, 10 from dual union all
5 select 2345, date '2011-03-13', 10, 20 from dual
6 ),
Query begins here:
7 calendar (studentid, datum) as
8 (select studentid,
9 trunc(mindat, 'mm') + column_value - 1
10 from (select studentid,
11 min(datum) mindat,
12 max(datum) maxdat
13 from student
14 group by studentid
15 ) cross join table(cast(multiset
16 (select level from dual
17 connect by level <= last_day(maxdat) - trunc(mindat, 'mm') + 1
18 ) as sys.odcinumberlist))
19 )
20 select c.studentid,
21 c.datum,
22 nvl(s.oldvalue, round(dbms_random.value(1, 100))) oldvalue,
23 nvl(s.newvalue, round(dbms_random.value(1, 100))) newvalue
24 from calendar c left join student s on s.datum = c.datum
25 order by c.studentid, c.datum;
Result:
STUDENTID DATUM OLDVALUE NEWVALUE
---------- --------- ---------- ----------
1112 01-MAR-11 49 42
1112 02-MAR-11 21 26
1112 03-MAR-11 66 13
1112 04-MAR-11 72 73
1112 05-MAR-11 88 55
1112 06-MAR-11 36 32
1112 07-MAR-11 21 16
1112 08-MAR-11 98 53
1112 09-MAR-11 30 44
1112 10-MAR-11 15 77
1112 11-MAR-11 93 88
1112 12-MAR-11 65 45
1112 13-MAR-11 10 20 --> from source table
1112 14-MAR-11 50 30
1112 15-MAR-11 77 36
1112 16-MAR-11 78 85
1112 17-MAR-11 82 94
1112 18-MAR-11 22 32
1112 19-MAR-11 54 79
1112 20-MAR-11 30 10 --> from source table
1112 21-MAR-11 20 97
1112 22-MAR-11 11 98
1112 23-MAR-11 43 38
1112 24-MAR-11 68 86
1112 25-MAR-11 70 43
1112 26-MAR-11 98 35
1112 27-MAR-11 26 93
1112 28-MAR-11 56 27
1112 29-MAR-11 12 88
1112 30-MAR-11 78 43
1112 31-MAR-11 47 50
2345 01-MAR-11 59 70
2345 02-MAR-11 49 57
2345 03-MAR-11 63 75
2345 04-MAR-11 94 79
2345 05-MAR-11 2 49
2345 06-MAR-11 41 24
2345 07-MAR-11 75 36
2345 08-MAR-11 26 33
2345 09-MAR-11 31 48
2345 10-MAR-11 12 66
2345 11-MAR-11 88 3
2345 12-MAR-11 29 35
2345 13-MAR-11 10 20 --> from source table
2345 14-MAR-11 50 30
2345 15-MAR-11 75 2
2345 16-MAR-11 30 39
2345 17-MAR-11 19 68
2345 18-MAR-11 54 73
2345 19-MAR-11 73 37
2345 20-MAR-11 30 10
2345 21-MAR-11 35 10
2345 22-MAR-11 66 73
2345 23-MAR-11 71 52
2345 24-MAR-11 27 86
2345 25-MAR-11 73 22
2345 26-MAR-11 54 67
2345 27-MAR-11 46 75
2345 28-MAR-11 84 70
2345 29-MAR-11 63 31
2345 30-MAR-11 56 38
2345 31-MAR-11 76 24
62 rows selected.
SQL>

Related

Equidistant Points in a Matrix

I have a matrix of floating point values. Relative to a given origin (x and y index, point "0"), I would like to obtain the indices of equidistant points, starting with the nearest points ("1") and up to a specific number ("12" in this animated example):
The distance is the slant range between a point and point 0. For example, point "4" has the distance sqrt(2^2+1^2) = sqrt(5) = 2.24.
Does anyone know a corresponding algorithm to obtain these indices in an effective way?
Rephrasing the question, you want to enumerate the points by increasing euclidean distance to the center.
Here are two answers on https://math.stackexchange.com to this problem how-to-enumerate-2d-integer-coordinates-ordered-by-euclidean-distance and algorithm-for-enumerating-grid-points-by-distance-from-given-point
Basically:
use symmetry to consider only point with 0 <= x <= y;
note that for a given x points will be enumerated with increasing y;
use a priority queue to keep the next candidate for each vertical line.
With n the last index you generate, the time complexity will be O(n log n) and the space complexity O(sqrt(n)).
NB: to avoid floating point computation, consider the squared distance, which doesn't change the order of your points.
Here some python code implementing this idea:
import heapq
def yield_all_quadrant(x, y):
s = set([(x, y), (-x, y), (x, -y), (-x, -y),
(y, x), (-y, x), (y, -x), (-y, -x)])
for u, v in sorted(s):
yield u, v
def indices(X, Y):
q = [(0, 0, 0)]
d_current = 0
index = 0
while True:
d, x, y = heapq.heappop(q)
if d > d_current:
index += 1
d_current = d
for u, v in yield_all_quadrant(x, y):
yield (X + u,Y + v), index
if not y:
heapq.heappush(q, (d + 2*x + 1, (x+1), 0))
if y < x:
heapq.heappush(q, (d + 2*y + 1, x, y+1))
and used for example in a small function to fill a grid
import itertools
def fill_grid(size, center):
grid = [[0]*size for _ in range(size)]
def clip(e):
coord, index = e
return all(0 <= c < size for c in coord)
for (x,y), i in itertools.islice(filter(clip, indices(*center)), 0, size**2):
grid[x][y] = i
return grid
and the result
print('\n'.join(' '.join('%2d'%i for i in gi) for gi in fill_grid(20, (8,8))))
54 48 43 39 35 33 31 30 29 30 31 33 35 39 43 48 54 59 67 74
48 42 38 34 30 27 26 24 23 24 26 27 30 34 38 42 48 55 62 69
43 38 32 28 25 22 20 19 18 19 20 22 25 28 32 38 43 50 56 64
39 34 28 24 21 17 15 14 13 14 15 17 21 24 28 34 39 46 53 60
35 30 25 21 16 13 12 10 9 10 12 13 16 21 25 30 35 41 49 57
33 27 22 17 13 11 8 7 6 7 8 11 13 17 22 27 33 40 47 55
31 26 20 15 12 8 5 4 3 4 5 8 12 15 20 26 31 38 45 53
30 24 19 14 10 7 4 2 1 2 4 7 10 14 19 24 30 37 44 52
29 23 18 13 9 6 3 1 0 1 3 6 9 13 18 23 29 36 43 51
30 24 19 14 10 7 4 2 1 2 4 7 10 14 19 24 30 37 44 52
31 26 20 15 12 8 5 4 3 4 5 8 12 15 20 26 31 38 45 53
33 27 22 17 13 11 8 7 6 7 8 11 13 17 22 27 33 40 47 55
35 30 25 21 16 13 12 10 9 10 12 13 16 21 25 30 35 41 49 57
39 34 28 24 21 17 15 14 13 14 15 17 21 24 28 34 39 46 53 60
43 38 32 28 25 22 20 19 18 19 20 22 25 28 32 38 43 50 56 64
48 42 38 34 30 27 26 24 23 24 26 27 30 34 38 42 48 55 62 69
54 48 43 39 35 33 31 30 29 30 31 33 35 39 43 48 54 59 67 74
59 55 50 46 41 40 38 37 36 37 38 40 41 46 50 55 59 66 73 80
67 62 56 53 49 47 45 44 43 44 45 47 49 53 56 62 67 73 79 85
74 69 64 60 57 55 53 52 51 52 53 55 57 60 64 69 74 80 85 93

Ranking of nodes provides unranked result

I have the following graphviz input:
digraph para
{
node [shape=record];
rankdir=BT;
0 [label=<0<SUB>0,0</SUB>>];
1 [label=<1<SUB>1,1</SUB>>];
2 [label=<2<SUB>0,2</SUB>>];
3 [label=<2<SUB>1,1</SUB>>];
4 [label=<2<SUB>2,0</SUB>>];
5 [label=<3<SUB>1,3</SUB>>];
6 [label=<3<SUB>2,2</SUB>>];
7 [label=<3<SUB>3,1</SUB>>];
8 [label=<4<SUB>0,4</SUB>>];
9 [label=<4<SUB>1,3</SUB>>];
10 [label=<4<SUB>2,2</SUB>>];
11 [label=<4<SUB>3,1</SUB>>];
12 [label=<4<SUB>4,0</SUB>>];
13 [label=<5<SUB>1,5</SUB>>];
14 [label=<5<SUB>2,4</SUB>>];
15 [label=<5<SUB>3,3</SUB>>];
16 [label=<5<SUB>4,2</SUB>>];
17 [label=<5<SUB>5,1</SUB>>];
18 [label=<6<SUB>0,6</SUB>>];
19 [label=<6<SUB>1,5</SUB>>];
20 [label=<6<SUB>2,4</SUB>>];
21 [label=<6<SUB>3,3</SUB>>];
22 [label=<6<SUB>4,2</SUB>>];
23 [label=<6<SUB>5,1</SUB>>];
24 [label=<6<SUB>6,0</SUB>>];
25 [label=<7<SUB>1,7</SUB>>];
26 [label=<7<SUB>2,6</SUB>>];
27 [label=<7<SUB>3,5</SUB>>];
28 [label=<7<SUB>4,4</SUB>>];
29 [label=<7<SUB>5,3</SUB>>];
30 [label=<7<SUB>6,2</SUB>>];
31 [label=<7<SUB>7,1</SUB>>];
32 [label=<8<SUB>0,8</SUB>>];
33 [label=<8<SUB>1,7</SUB>>];
34 [label=<8<SUB>2,6</SUB>>];
35 [label=<8<SUB>3,5</SUB>>];
36 [label=<8<SUB>4,4</SUB>>];
37 [label=<8<SUB>5,3</SUB>>];
38 [label=<8<SUB>6,2</SUB>>];
39 [label=<8<SUB>7,1</SUB>>];
40 [label=<10<SUB>1,9</SUB>>];
41 [label=<7<SUB>7,1</SUB>>];
42 [label=<8<SUB>8,0</SUB>>];
43 [label=<5<SUB>4,1</SUB>>];
44 [label=<8<SUB>3,6</SUB>>];
45 [label=<8<SUB>5,4</SUB>>];
46 [label=<8<SUB>7,2</SUB>>];
47 [label=<1<SUB>1,1</SUB>>];
48 [label=<2<SUB>2,0</SUB>>];
49 [label=<3<SUB>1,3</SUB>>];
50 [label=<3<SUB>2,2</SUB>>];
51 [label=<3<SUB>3,1</SUB>>];
52 [label=<4<SUB>4,0</SUB>>];
53 [label=<6<SUB>1,5</SUB>>];
54 [label=<6<SUB>2,4</SUB>>];
55 [label=<7<SUB>3,5</SUB>>];
56 [label=<7<SUB>6,2</SUB>>];
57 [label=<7<SUB>7,1</SUB>>];
58 [label=<8<SUB>0,8</SUB>>];
59 [label=<8<SUB>3,5</SUB>>];
60 [label=<9<SUB>4,6</SUB>>];
61 [label=<1<SUB>0,1</SUB>>];
62 [label=<4<SUB>1,4</SUB>>];
63 [label=<5<SUB>2,3</SUB>>];
64 [label=<6<SUB>2,5</SUB>>];
65 [label=<6<SUB>6,1</SUB>>];
66 [label=<7<SUB>2,5</SUB>>];
67 [label=<7<SUB>3,4</SUB>>];
68 [label=<7<SUB>6,1</SUB>>];
69 [label=<7<SUB>7,0</SUB>>];
70 [label=<8<SUB>3,6</SUB>>];
71 [label=<8<SUB>4,5</SUB>>];
72 [label=<9<SUB>3,6</SUB>>];
73 [label=<5<SUB>1,5</SUB>>];
74 [label=<5<SUB>3,3</SUB>>];
75 [label=<6<SUB>4,2</SUB>>];
76 [label=<6<SUB>5,1</SUB>>];
77 [label=<7<SUB>4,4</SUB>>];
78 [label=<8<SUB>0,8</SUB>>];
{rank=same 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40}
{rank=same 41 42}
{rank=same 43 44 45 46}
{rank=same 47 48 49 50 51 52 53 54 55 56 57 58 59 60}
{rank=same 61 62 63 64 65 66 67 68 69 70 71 72}
{rank=same 73 74 75 76 77 78}
4->5;
10->13;
24->29;
17->22;
12->15;
25->20;
39->46;
30->76;
36->59;
4->47;
27->58;
27->44;
29->75;
37->56;
30->71;
18->43;
7->50;
35->78;
8->49;
38->57;
21->54;
20->53;
9->50;
6->49;
4->61;
14->43;
24->41;
29->70;
10->51;
20->73;
15->52;
31->69;
31->69;
35->70;
22->74;
16->64;
23->67;
29->45;
33->67;
30->68;
24->65;
12->63;
5->48;
40->60;
9->62;
25->54;
4->49;
40->72;
37->60;
22->55;
18->63;
24->76;
34->59;
3->48;
0->47;
19->54;
32->55;
27->67;
37->72;
31->46;
22->66;
5->50;
32->66;
2->49;
29->77;
0->61;
26->55;
18->53;
35->77;
15->54;
11->52;
28->59;
1->48;
29->56;
37->69;
31->42;
18->73;
30->57;
20->74;
25->58;
25->44;
8->43;
18->64;
4->51;
13->52;
34->71;
27->75;
27->78;
28->76;
}
where I am trying to rank the nodes as follows:
{rank=same 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40}
{rank=same 41 42}
{rank=same 43 44 45 46}
{rank=same 47 48 49 50 51 52 53 54 55 56 57 58 59 60}
{rank=same 61 62 63 64 65 66 67 68 69 70 71 72}
{rank=same 73 74 75 76 77 78}
However, it seems to me that only the first rank is assigned properly (for nodes 0,1,2,...,40). Could you please help me what the problem is with the ranking of the other groups? Why won't they be separated from each other?
rank=same can only force same rank for those nodes listed together, there is no guarantee that two rank=same gets different rank.
Also it seems like the hierarchy in you graph does not goes well with chosen subgraphs
Try replace your ranking with clusters and/or node coloring to analyze where the problem is. e.g.:
subgraph cluster1 {0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40}
subgraph cluster2 {41 42}
subgraph cluster3 {43 44 45 46}
subgraph cluster4 {47 48 49 50 51 52 53 54 55 56 57 58 59 60}
subgraph cluster5 {61 62 63 64 65 66 67 68 69 70 71 72}
subgraph cluster6 {73 74 75 76 77 78}
or
{0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40}
node[style=filled]
{node[fillcolor=red] 41 42}
{node[fillcolor=blue] 43 44 45 46}
{node[fillcolor=salmon] 47 48 49 50 51 52 53 54 55 56 57 58 59 60}
{node[fillcolor=pink] 61 62 63 64 65 66 67 68 69 70 71 72}
{node[fillcolor=green] 73 74 75 76 77 78}

In sorting quicksort if there are more than 2 same numbers..How can we sort?

If there are more than two same elements in Quicksort and pivot is also the same number...How can we sort it?
Eg: 23,19,45,21,90,5,93,45,31,45
In this array consider 45
Using Hoare like partition scheme, 45 as pivot, start with
0 1 2 3 4 5 6 7 8 9 indices
23 19 45 21 90 5 93 45 31 45 data
scan from left for >= pivot, scan from right for <= pivot
ll rr
23 19 45 21 90 5 93 45 31 45
23 19 45 21 90 5 93 45 31 45 swap (both are 45, so no change)
ll rr
23 19 45 21 90 5 93 45 31 45
23 19 45 21 31 5 93 45 90 45 swap
ll rr
23 19 45 21 31 5 93 45 90 45
23 19 45 21 31 5 45 93 90 45 swap
rr ll
23 19 45 21 31 5 45 93 90 45 rr and ll crossed, rr = 6
The next two calls will be quicksort(0,6), quicksort(7, 9)
How can we sort quicksort(7,9) ?
0 1 2 3 4 5 6 7 8 9 indices
93 90 45 again assume pivot is 45
ll rr
93 90 45
45 90 93 swap
rr ll
45 90 93 rr and ll crossed, rr = 7
The next two calls will be quicksort(7,7), quicksort(8, 9)

Aren't teragen "rows" supposed to end with newline (\r\n)?

I was trying to assist with a (deleted) question, here at SO, about how to define an Hive external table over data generated by teragen.
According to the teragen code's comments, each 100 bytes of data (=row) should end with \r \n, however, It seems that it ends with 4 characters with hex values of cc dd ee ff
The full demo is down below.
Any thoughts?
Thanks
/** * Generate the official terasort input data set. * The user
specifies the number of rows and the output directory and this *
class runs a map/reduce program to generate the data. * The format of
the data is: * * (10 bytes key) (10 bytes rowid) (78 bytes
filler) \r \n * The keys are random characters from the set ' '
.. '~'. * The rowid is the right justified row id as a int. *
The filler consists of 7 runs of 10 characters from 'A' to 'Z'. *
* *
https://github.com/facebookarchive/hadoop-20/blob/master/src/examples/org/apache/hadoop/examples/terasort/TeraGen.java
Using teragen to generate 7 records
hadoop jar /usr/jars/hadoop-examples.jar teragen 7 /user/hive/warehouse/teragen
As expected, we get files with total data volume of 700 bytes
hdfs dfs -ls /user/hive/warehouse/teragen
Found 3 items
-rw-r--r-- 1 cloudera supergroup 0 2017-03-03 22:38 /user/hive/warehouse/teragen/_SUCCESS
-rw-r--r-- 1 cloudera supergroup 400 2017-03-03 22:38 /user/hive/warehouse/teragen/part-m-00000
-rw-r--r-- 1 cloudera supergroup 300 2017-03-03 22:38 /user/hive/warehouse/teragen/part-m-00001
Moving the files to local directory and checking the HEX values.
hdfs dfs -get /user/hive/warehouse/teragen/part-m-00001
od -v -Anone -w20 -tx1
At this point I was expecting to see 0a 0d (\r\n) as the last 2 characters of each 100 bytes, but instead I see ee ff.
There are no newline at the end of the "rows".
5c 90 ab 38 ae 52 89 62 15 d7 00 11 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 34 88 99 aa bb 41 41 41 41 42 42 42 42 42 42 42 42
32 32 32 32 34 34 34 34 34 34 34 34 39 39 39 39 35 35 35 35
42 42 42 42 31 31 31 31 38 38 38 38 44 44 44 44 cc dd ee ff <--
72 dc 0c a5 1e 33 3f 32 4b 7a 00 11 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 35 88 99 aa bb 38 38 38 38 33 33 33 33 42 42 42 42
38 38 38 38 38 38 38 38 34 34 34 34 37 37 37 37 32 32 32 32
37 37 37 37 39 39 39 39 30 30 30 30 32 32 32 32 cc dd ee ff <--
10 43 1a f6 a0 d8 47 b8 c5 5f 00 11 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 36 88 99 aa bb 39 39 39 39 37 37 37 37 34 34 34 34
41 41 41 41 37 37 37 37 45 45 45 45 44 44 44 44 41 41 41 41
41 41 41 41 39 39 39 39 38 38 38 38 42 42 42 42 cc dd ee ff <--
I'm not sure that the output of your terasort is relative to that TeraGen which you are referencing in your link. If you open the terasort content from some other source you'll be able to see:
Generate the official GraySort input data set. The user specifies the number of rows and the output directory and this class runs a map/reduce program to generate the data. The format of the data is:
(10 bytes key) (constant 2 bytes) (32 bytes rowid) (constant 4 bytes) (48 bytes filler) (constant 4 bytes)
The rowid is the right justified row id as a hex number.
Following this description I compare it with your first link:
5c 90 ab 38 ae 52 89 62 15 d7 - 10 bytes key
00 11 - constant 2 bytes
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 34 - 32 bytes rowid
88 99 aa bb - constant 4 bytes
41 41 41 41 42 42 42 42 42 42 42 42 32 32 32 32 34 34 34 34 34 34 34 34 39 39 39 39 35 35 35 35 42 42 42 42 31 31 31 31 38 38 38 38 44 44 44 44 - 8 bytes filler
cc dd ee ff - constant 4 bytes
So it is not the newline but just a constant 4 bytes produced by generator for every record.

data.frame to spatial polygone data frame

I have this data.frame
data <- read.table(text="Id x y valecolo valecono
1 1 12.18255221 29.406365240 4 990
2 2 9.05893970 20.923087170 4 1090
3 3 1.11192442 2.460411416 0 420
4 4 15.51290096 27.185287490 16 1320
5 5 20.41913438 32.166268590 13 1050
6 6 12.75939095 17.552435030 60 1010
7 7 28.06853355 30.839057830 12 1030
8 8 6.96288868 7.177616682 33 1010
9 9 30.60527190 20.792242110 23 640
10 10 12.07646283 7.658266843 19 810
11 11 10.42878294 5.520913954 0 700
12 12 23.61674977 11.111217320 0 838
13 13 27.16148898 12.259423750 11 1330
14 14 28.00931750 6.258448426 20 777
15 15 20.79999922 -0.000877298 4 630
16 16 21.59999968 -0.005502197 38 830
17 17 19.46122172 -1.229166015 7 740
18 18 28.20370719 -6.305622777 12 660
19 19 29.94840042 -7.192584050 0 1030
20 20 29.28601258 -12.133404940 10 870
21 21 5.88104817 -3.608777319 0 1050
22 22 30.37845976 -26.784308510 0 900
23 23 13.68270042 -12.451253320 0 300
24 24 26.01871530 -26.024342420 22 1330
25 25 20.17735764 -20.829648070 21 1190
26 26 5.04404016 -5.550464740 7 1030
27 27 17.98312114 -26.468988540 0 1200
28 28 8.50660753 -12.957145840 9 850
29 29 10.79633248 -18.938827100 36 1200
30 30 13.36599497 -28.413203870 7 1240
31 31 10.77987946 -28.531459810 0 350
32 32 8.35194396 -24.410755680 28 910
33 33 1.55014408 -12.302725060 10 980
34 34 -0.00388992 -17.899999200 12 1120
35 35 -2.82062504 -16.155620130 12 450
36 36 -4.75903628 -22.962014490 20 920
37 37 -6.07839546 -15.339592840 28 840
38 38 -11.32647798 -24.068047630 0 665
39 39 -11.88138209 -24.245262620 12 1180
40 40 -14.06823800 -25.587589260 36 350
41 41 -10.92180227 -18.461223360 7 1180
42 42 -12.48843186 -20.377660600 0 400
43 43 -18.63696964 -27.415068190 18 1220
44 44 -16.73351789 -23.807549250 0 500
45 45 -22.49024869 -29.944803740 7 1040
46 46 -22.66130064 -27.391018580 0 500
47 47 -15.26565038 -17.866446720 16 1060
48 48 -24.20192852 -23.451155780 0 600
49 49 -21.39663774 -20.089958090 0 750
50 50 -12.33344998 -9.875526199 16 980
51 51 -30.94772590 -22.478895910 0 790
52 52 -24.85783868 -15.225318840 25 720
53 53 -2.44485324 -1.145728097 54 970
54 54 -24.67985433 -7.169018707 4 500
55 55 -30.82457650 -7.398346555 4 750
56 56 -23.56898920 -5.265475270 4 760
57 57 -3.91708603 -0.810208045 0 350
58 58 -26.86563675 -4.251776497 0 440
59 59 -26.64738877 -1.675324623 8 450
60 60 -8.79897138 -0.134558536 11 830
61 61 -21.78250663 1.716077388 0 920
62 62 -28.98396759 6.007465815 24 980
63 63 -34.61607994 8.311853049 8 500
64 64 -25.63850107 7.453677191 15 880
65 65 -22.98762116 11.266290120 11 830
66 66 -33.48522130 19.100848030 0 350
67 67 -25.53096486 16.777135830 21 740
68 68 -18.95412327 15.681238150 0 300
69 69 -8.94874230 8.144324435 0 500
70 70 -10.91433241 10.579099310 4 750
71 71 -13.44807236 14.327310800 0 1090
72 72 -16.24086139 20.940019610 0 500
73 73 -17.51162097 24.111886810 0 940
74 74 -12.47496424 18.363422910 0 1020
75 75 -17.76118016 27.990410510 0 660
76 76 -5.54534556 9.730834410 0 850
77 77 -11.30971858 29.934766840 0 950
78 78 -10.38743785 27.493148220 0 740
79 79 -8.61491396 25.166312360 0 950
80 80 -3.40550077 14.197273530 0 710
81 81 -0.77957621 3.770246702 0 750
82 82 -3.01234325 21.186924550 0 1200
83 83 -2.05241931 32.685624900 0 1200
84 84 -2.26900366 36.128820600 0 970
85 85 0.82954518 5.790885396 0 850
86 86 22.08151130 19.671119440 19 870
87 87 12.60107972 23.864904860 0 1260
88 88 9.78406607 26.163968270 0 600
89 89 11.69995152 33.091322170 0 1090
90 90 20.64705880 -16.439632140 0 840
91 91 24.68314851 -21.314655730 0 1561
92 92 30.33133300 -27.235396100 0 1117
93 93 -26.24691654 -22.405635470 0 1040
94 94 -21.68016500 -24.458519270 10 1000
95 95 -1.57455856 -30.874986140 0 500
96 96 -29.75642086 -5.610894981 0 350
97 97 -3.66771076 26.448084810 0 900
98 98 -26.54457307 29.824419350 0 1050
99 99 -17.90426678 18.751297440 0 200
100 100 10.22894253 -6.274450952 0 880")
And I would like to create a visualization with the polygons of thiessen, then colorize the polygons according to their "valecono" value.
I tried this:
> library(deldir)
> z <- deldir(x,y,rw=c(-34.51608,30.7052719,-30.774986,36.2288206))
> w <- tile.list(z)
> plot(w, fillcol=data$valecono, close=TRUE)
Which seems weird to me, and I'm not sure how R attributed these colors.
Do you have any other suggestions for this case?
I also tried to convert my data.frame in SpatialPolygonsDataFrame, what I did not manage. I tried to convert my data.frame into SpatialPointsDataFrame, which was not a problem, but was not very useful, because I did not find how to convert it then to a SpatialPointsDataFrame.
spdf <- SpatialPointsDataFrame(coords = coords, data = data,
proj4string = CRS("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0"))
I try all this because I think that with a SpatialPointsDataFrame, it would be easier to have this visualization of polygons with colors according to the valecono of the points.
You can do
library(dismo)
coordinates(data) <- ~x + y
v <- voronoi(data)
spplot(v, "valecolo")
With base plot
s <- (floor(sort(v$valecono)/400) + 1)
plot(v, col=rainbow(60)[v$valecolo+1])
points(data, cex=s/2, col=gray((1:4)/4)[s])

Resources