How to create an attribute with the difference

hugomsouto
hugomsouto New Altair Community Member
edited November 2024 in Community Q&A
Hi, everyone.

I am stucked. I need to create an attribute with the difference betweem a value from another attribute of the same row and the value of that same attribute from the row just above.

In Excel, it would be like, on the colum "=[@[lanData_time]]-A(numer of the row just above)". Anyone could help me?

Thanks!
Tagged:

Welcome!

It looks like you're new here. Sign in or register to get started.

Best Answer

  • tftemme
    tftemme New Altair Community Member
    Answer ✓
    Hi @hugomsouto

    I am not completely sure, but do you want to create the differentation of an Attribute: a_i - a_i-1. Try out the Differentiate operator from the time series operators. Deselect 'overwrite attributes' to create a new attribute containing the differentiated values.

    Best regards,
    Fabian

Answers

  • jacobcybulski
    jacobcybulski New Altair Community Member
    edited June 2019
    OK, here is not a very elegant solution. Let's say we want to find the difference between people's ages (Age attribute). I have create an attribute to collect differences (AgeDiff) and they are undefined. Set a macro (such as PrevAge) with the initial value of the attribute of interest (Age), here is zero. Then loop over your examples.
    At each iteration:

    Extract the value of the attribute of interest into macro CurrAge, calculate difference between  CurrAge and PrevAge and save it in AgeDiff macro, then set the value of the attribute AgeDiff in the example pointed to by the loop index to the value of macro AgeDiff, finally set the macro PrevAge to CurrAge.

    Done:

    Jacob (see the example attached as RMP)
  • jacobcybulski
    jacobcybulski New Altair Community Member
    This one is probably even less elegant and definitely not as efficient.



    You duplicate you input, add a dummy example to the copy, merge them both placing the values of the preceding attribute with the next, calculate the difference, get rid of extra example at the end (somehow) and select only the attributes of interest (because of duplicated attributes).

    Jacob

  • Telcontar120
    Telcontar120 New Altair Community Member
    Have you tried the Lag operator from the Time Series group of operators?

  • jacobcybulski
    jacobcybulski New Altair Community Member
    Great idea @Telcontar120 in which case we do not need to make this awkward duplication and merging of out of sync example sets.
  • tftemme
    tftemme New Altair Community Member
    Answer ✓
    Hi @hugomsouto

    I am not completely sure, but do you want to create the differentation of an Attribute: a_i - a_i-1. Try out the Differentiate operator from the time series operators. Deselect 'overwrite attributes' to create a new attribute containing the differentiated values.

    Best regards,
    Fabian
  • hugomsouto
    hugomsouto New Altair Community Member
    I saw the solution and forgot to thank you, @tftemme, that was exactaly what I needed. So fast an easy, only took a previous sorting.

    Thanks @Telcontar120, you were almost on target. Thank you @jacobcybulski for all the efforts!

Welcome!

It looks like you're new here. Sign in or register to get started.

Welcome!

It looks like you're new here. Sign in or register to get started.