Hi,
I have a trouble transform a column into a table within a short time.
Set i /1*365/; (day)
Set j /1*288/; (5-min in a day)
Set k /1*105120/; (5-min in a year)
I have a data parameter column DataColumn(k) and I would like to transform DataColumn(k) into DataTable(i, j).
for example, k=1 means day 1 and 0:05. and k=2 means day 1 and 0:10.
Also, k=289 means day 1 and 0:05, and so on.
Here is what I try:
loop(k,
temp_day = trunc((ord(k) - 1)/card(j)) + 1;
* get quotient of k divided by 288
temp_min = mod(ord(k), card(j));
* get remainder of k divided by 288
if(temp_min = 0, temp_min = card(j);
DataTable(i, j)$(ord(i) = temp_day and ord(j) = temp_min) = DataColumn(k);
);
But it takes so much time, for me it takes 10 minutes to fully complete the codes.
Is there any efficient way to transform?
Best,
Efficient way to transform column into table
Re: Efficient way to transform column into table
Hi,
The following should do the trick.
This takes 0.1 seconds on my machine.
The Many-to-many-mapping section in the documentation explains how the matching operator ":" works;
I hope this helps!
Fred
The following should do the trick.
Code: Select all
set i /d1*d365/
j /m1*m288/
k /1*105120/
map(i,j,k) / #i.#j:#k /
;
Parameter DataColumn(k), DataTable(i,j);
DataColumn(k) = uniform (0,1);
DataTable(i,j) = sum(map(i,j,k), DataColumn(k));
The Many-to-many-mapping section in the documentation explains how the matching operator ":" works;
I hope this helps!
Fred
-
- User
- Posts: 15
- Joined: 4 years ago
Re: Efficient way to transform column into table
Thanks Fred! It really helped me a lot.
I'll try to understand the method and operators.
Jake