Author |
Topic  |
|
tbarrou
France
36 Posts |
Posted - 09/22/2011 : 1:56:55 PM
|
Origin Ver. and Service Release (Select Help-->About Origin): 8.5.1 SR2 Operating System:XP SP3
Hello, I try to replace missing data in a column by the last valid measurement by using the Set Column Value (otherwise FFT wont work...). I m using the conditional operator like this:
(r1=="--")?r2[(i-1)]:r1; r2 is the target column, r1 the source and are defined in the before formula script panel.
I get a exact copy of r1 in r2, including "--" ! How can I simply refer to the value of the previous row ? what is the name of the index variable? is it a way get the index of row that is being processed ?
I tried several things but I surrender. simple operation are sometimes very hard to get...
thanks for your help |
|
Hideo Fujii
USA
1582 Posts |
Posted - 09/22/2011 : 2:31:39 PM
|
Hi tbarrou,
You can use 0/0 instead of "--". The former gives you the internal missing value (NANUM in Origin C), and the later is just a text string. (You can find the topic of Missing Value in LabTalk help.)
--Hideo Fujii OriginLab |
Edited by - Hideo Fujii on 09/22/2011 2:34:47 PM |
 |
|
tbarrou
France
36 Posts |
Posted - 09/22/2011 : 2:42:57 PM
|
The "--"is not a problem at all. next time I will use 0/0 but it was not my question.
My question is : how can I copy the value of the previous cell (a valid one) to replace the missing data ? I thought that using range r1[i-1] will work in labtalk, but obviously it doesn't.
Thanks for your help.
|
 |
|
couturier
France
291 Posts |
Posted - 09/22/2011 : 3:31:05 PM
|
Try the following, in script window:
range aa=1, bb=2; // replace with appropriate column number bb=aa; for (int ii=1; ii<=aa.nrows; ii++) { if (aa[ii]==0/0) {aa[ii]=aa[ii-1];}; };
But I can't understand why your command doesn't work. I've further tried range aa=1, bb=2; for (int ii=1; ii<=aa.nrows; ii++) { bb[ii]=aa[ii]==0/0?aa[ii-1]:aa[ii]; };
but it doesn't work neither, so maybe someone at Originlab can explain ...
|
 |
|
Hideo Fujii
USA
1582 Posts |
Posted - 09/22/2011 : 3:33:23 PM
|
Oh sorry, tbarrou,
Your indexing of a range like r2[(i-1)] is correct. So, you need to use the same syntax to r1. For example,
r1[i]==0/0?r2[(i-1)]:r1[i]
One cavity maybe when r1[1] is a missing value. But, anyway does it work for you?
--Hideo Fujii OriginLab |
 |
|
DataConv
Germany
60 Posts |
Posted - 09/23/2011 : 01:39:33 AM
|
For missing values its better to use the isna() function (see Labtalk help) rather than a comparision like (xy==nanum). Example: range r1=!1;r1=isna(r1)?2:1; When working with the indexing, it is better to use a loop structure. In your case I would suggest:
loop (ii,2,r1.nrows){if isna(r1[ii]) {r1[ii]=r2[ii-1]};}; You only need to handle the case of the first line separately, since there is no previous value in r2 defined... |
 |
|
tbarrou
France
36 Posts |
Posted - 09/23/2011 : 04:31:38 AM
|
I have tried (in Set Column Value): - (r1[i]=="--")?r2[(i-1)]:r1[i]; it does not work. (values are copied, but missing values also and are not replaced by the previous numeric value) - (r1[i]==0/0)?r2[(i-1)]:r1[i]; it does not work. - I started from index=2 to avoid the first line. doesn't change anything. - isna(r1[i])?r2[(i-1)]:r1[i]; does not work.
The script proposed by M(me) Couturier worked well. I could replace few missing values in 1e6 values...
The issue seems related to indexing in SetColumnValue window.
Thanks to all.
|
 |
|
Hideo Fujii
USA
1582 Posts |
Posted - 09/23/2011 : 10:12:36 AM
|
Hi tbarrou,
I am puzzling why isna(r1[i])?r2[(i-1)]:r1[i] in Set Col Values didn't work. As far as using a simple sample, it worked on my machine.
I would like to know what happened. Could you send us the Origin file which contains the data and the Set Col Values formula for the source column? (press "Send File to Tech support" at the top of this page, and choose "Technical Support" for question regarding...)
Thanks!
--Hideo Fujii OriginLab |
 |
|
Hideo Fujii
USA
1582 Posts |
Posted - 09/26/2011 : 2:39:54 PM
|
Hi tbarrou,
Thank you very much for sending me the sample file, and I have confirm the problem you reported. Weird enough, though your isna(r1[i])?r2[(i-1)]:r1[i]
didn't work, just removing parentheses( ) in the index [ ]:
isna(r1[i])?r2[i-1]:r1[i]
worked. Maybe Origin has confused the syntax (headless function??) Could you please check my alternative above? Meanwhile I will report this problem to our developers.
--Hideo Fujii OriginLab
|
 |
|
tbarrou
France
36 Posts |
Posted - 09/27/2011 : 12:14:46 PM
|
Hi Hideo,
I have tested your solution, removing the parentheses, and it works. I made some other tests : With parentheses, it works on two rows after a valid value (replace two missing values) and the values after are NA ("--") again.. it is weird :-) (I haven't checked all rows...)
I tried again r1[i]=="--" instead of isna(), and this time it doesn't work...
Thanks
|
 |
|
couturier
France
291 Posts |
Posted - 09/28/2011 : 06:25:20 AM
|
quote: I tried again r1[i]=="--" instead of isna(), and this time it doesn't work...
this is because "--" is a string and r1[1] is a number, so you can't compare them.
You should use: r1[i]$=="--" --> here you compare 2 strings or r1[i]==-- --> here you compare 2 numbers (-- being nanum) |
 |
|
|
Topic  |
|