cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Discovery is online this week, April 16 and 18. Join us for these exciting interactive sessions.
Choose Language Hide Translation Bar
terapin
Level VI

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]
)
);

 

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];

View solution in original post

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];
terapin
Level VI

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.

Re: Subset a list using various conditions

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

terapin
Level VI

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]
)
);