JSL Compare value in row to the next row.Hello,
I am trying to use "FOR" and "IF" to create a condition column.
I have this table and I want the "Con" column to indicate if the age in the row after is lower then the current row. if yes "1" if not "0"
| Name | Age | Con |
| David | 23 | 0 |
| Bari | 26 | 1 |
| James | 12 | 0 |
| Lora | 14 | 0 |
This is what I have: (doesn't work)
dt<< New Column( "Con", Formula( For( i = 1,i <= N Row( dt ), i++, If(:Age[i] >= :Age[i+1] , "0", "1", ))));
Your help will be appreciated.
Design of ExperimentsMass CustomizationQuality and Process EngineeringRe: JSL Compare value in row to the next row.Here is two ways to do this (Row() and Lag():
Names Default To Here(1);
dt = New Table("Untitled",
Add Rows(4),
Compress File When Saved(1),
New Column("Name", Character, "Nominal", Set Values({"David", "Bari", "James", "Lora"})),
New Column("Age", Numeric, "Continuous", Format("Best", 12), Set Values([23, 26, 12, 14])),
New Column("Con", Numeric, "Continuous", Format("Best", 12), Set Values([0, 1, 0, 0]))
);
dt << New Column("Younger than Next_Row", Character, "Nominal",
Formula(If(:Age > :Age[Row() + 1], "Yes", "No")));
dt << New Column("Younger than Next_Lag", Character, "Nominal",
Formula(If(:Age > Lag(:Age, -1), "Yes", "No"))
);Re: JSL Compare value in row to the next row.Thanks, this could work but it will mark as "Yes" the row 3 (James) and i am trying to mark row 2 (Bari) with a "Yes"
Any other solution?
Re: JSL Compare value in row to the next row.Is this what you are after?
New Table( "Ages",
Add Rows( 4 ),
New Column( "Age",
Numeric,
"Ordinal",
Format( "Best", 12 ),
Set Values( [23, 26, 12, 14] )
),
New Column( "Younger than Previous",
Numeric,
"Nominal",
Format( "Best", 12 ),
Formula( If( :Age < Lag( :Age, 1 ), 1, 0 ) ),
Value Labels( {0 = "No", 1 = "Yes"} ),
Use Value Labels( 1 ),
Set Display Width( 125 )
)
)