BookmarkSubscribe
Choose Language Hide Translation Bar
Highlighted
terapin
Community Trekker

Subset a list using various conditions

I have a list of daily moving averages computed from 5-minute data.  Although I'm able to successfully create this list, I can't seem to figure out how to locate in thelist when certain conditions are met and to then create a new data table containing the :Date when these conditions are met.  The following code grabs the dates corresponding to each record in the ma_list, not just those corresponding the the specified condition. Is it possible to create "complex" evaluation criteria when working with lists, and if so, what might that JSL code look like?  Any suggestions would be greatly appreciated. 

 

 

ma_list = [46.6, 51.6, 50.8, 52.8, 58.4, 57.6, 62.2, 62.2, 66.6, 63.8, 59.6, 55.6, 57.2, 57.8,
57.4, 59.8, 65.4, 62, 54.6, 51.8, 50, 45.2, 44.2, 42.2, 45.8, 47.8, 52.4, 55.6, 57,
44.4, 34, 20.2, 9.4, 0.4, 0, 0, 0, 0, 0, 4.4, 11, 18, 25.4, 32.4, 36.6, 38.2, 40.2,
44.6, 44, 41.4, 39, 38.4, 33, 33.8, 39.2, 40.4, 37.8, 37.6, 36.4, 31, 30,
30.3333333333333]

// Locate dates when data shifted from 0 to a positive value
// NOTE: :Date refers to existing column name in data table ma_list was extracted from.
ma_date_list = {};

For( i = 2, i <= N Items( ma_list ), i++,
If ( ma_list[i] > 0 & ma_list[i-1] == 0,
// then
ma_date_list = :Date[ma_row_list]
)
);

 

0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions

Re: Subset a list using various conditions

See if this approach helps:

ma_list = [46.6, 51.6, 50.8, 52.8, 58.4, 57.6, 62.2, 62.2, 66.6, 63.8, 59.6, 55.6, 57.2, 57.8,
57.4, 59.8, 65.4, 62, 54.6, 51.8, 50, 45.2, 44.2, 42.2, 45.8, 47.8, 52.4, 55.6, 57,
44.4, 34, 20.2, 9.4, 0.4, 0, 0, 0, 0, 0, 4.4, 11, 18, 25.4, 32.4, 36.6, 38.2, 40.2,
44.6, 44, 41.4, 39, 38.4, 33, 33.8, 39.2, 40.4, 37.8, 37.6, 36.4, 31, 30,
30.3333333333333];

// create parallel vector lagged by 1
lagged data = ma_list[2::NRow(ma_list)];

// remove the last observation
data = ma_list[1::NRow(ma_list)-1];

// find the positive differences
positives = Loc( (lagged data - data) > 0 & (data == 0) );

// go get 'em
ma_date_list = :Date[positives];
Learn it once, use it forever!
4 REPLIES 4

Re: Subset a list using various conditions

See if this approach helps:

ma_list = [46.6, 51.6, 50.8, 52.8, 58.4, 57.6, 62.2, 62.2, 66.6, 63.8, 59.6, 55.6, 57.2, 57.8,
57.4, 59.8, 65.4, 62, 54.6, 51.8, 50, 45.2, 44.2, 42.2, 45.8, 47.8, 52.4, 55.6, 57,
44.4, 34, 20.2, 9.4, 0.4, 0, 0, 0, 0, 0, 4.4, 11, 18, 25.4, 32.4, 36.6, 38.2, 40.2,
44.6, 44, 41.4, 39, 38.4, 33, 33.8, 39.2, 40.4, 37.8, 37.6, 36.4, 31, 30,
30.3333333333333];

// create parallel vector lagged by 1
lagged data = ma_list[2::NRow(ma_list)];

// remove the last observation
data = ma_list[1::NRow(ma_list)-1];

// find the positive differences
positives = Loc( (lagged data - data) > 0 & (data == 0) );

// go get 'em
ma_date_list = :Date[positives];
Learn it once, use it forever!
terapin
Community Trekker

Re: Subset a list using various conditions

Thanks Mark for the suggestion,

 

I was hoping we could do some complex forward and backward evaluations of the matrix, but I now see that's not quite possible.  Your suggestion certainly helps get the evaluation I needed while also showing me how to go about this type of thing in the future.  Thanks.

0 Kudos

Re: Subset a list using various conditions

What do you mean by "forward and backward evaluation?" Anything is possible in a JMP script!

Learn it once, use it forever!
0 Kudos
terapin
Community Trekker

Re: Subset a list using various conditions

Mark, 

Something like the following

ma_date_list = {};

For( i = 2, i <= N Items( ma_list ), i++,
If ( ma_list[i] > 0 & ma_list[i-1] == 0 & ma_list[i-2] == 0 & ma_list[i-3] == 0,
// then
ma_date_list = :Date[ma_row_list]
)
);

 

0 Kudos