Subscribe Bookmark RSS Feed

if missing, then fill in with previous value for multiple columns

dfmoore

Community Trekker

Joined:

Aug 29, 2012

I'm having trouble getting this logic correct and I'm not sure where I'm going wrong. I want to have a script where, if the operator name is row i is the same as the operator name in row (i-1), then if the measurement value in row i is missing, fill it in with the measurement value in row (i-1). I have several measurement values, so I'm searching across columns for any column with "Meas" in the name.

So far, I have the script below, but it just isn't working and I'm not sure why..

(also, I'm new to the forum. How do I get the code to maintain the formatting when I copy it in?)

dt = current data table();

for (j=1, j<= ncols(dt),j++,

    colname = Column ( j ) << getname();

    If( Contains( colname, "Meas") > 0,

        for (i = 2, i <= nrows(dt), i++,

            if(Column("OperatorName") == Column("OperatorName")[i-1],

                if (column(j) == isMissing(),

                    column(j) = column(j)[i-1]; // set equal to row above

                );

            );

        );

    );

);

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

The only error I can find is how Is Missing() is used. Think of it as a function rather than a value.

If( Is Missing( Column( j )[i] ),...

2 REPLIES
Solution

The only error I can find is how Is Missing() is used. Think of it as a function rather than a value.

If( Is Missing( Column( j )[i] ),...

dfmoore

Community Trekker

Joined:

Aug 29, 2012

<< head slap >>

Duh...

Thanks!

Daniel