Necesito escribir un script para encontrar todas las filas de la tabla con valor> 50 y devolver 10 filas justo después de esas filas. ¿Alguien podría ayudarme con este script por favor? ¡Gracias!
Sin ningún conocimiento de los datos que tiene aquí, hay una opción con la que puede comenzar (busca valores superiores a 120, no 50).
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
r = As List(dt << Get Rows Where(:weight > 120));
rs = {};
max_rows = N Rows(dt);
For Each({cur_r}, r,
Insert Into(rs, Index(cur_r + 1, Min(max_rows, cur_r + 10)));
);
show(r);
show(rs);
// r = {2, 4, 7, 18, 30, 37, 39, 40};
// rs = {[2 3 4 5 6 7 8 9 10 11], [4 5 6 7 8 9 10 11 12 13], [7 8 9 10 11 12 13 14 15 16], [18 19 20 21 22 23 24 25 26 27], [30 31 32 33 34 35 36 37 38 39], [37 38 39 40], [39 40], [40]};
</CODE></P></LINGO-BODY><LINGO-SUB id="lingo-sub-754828" slang="en-US" mode="CREATE">Re: buscar todas las filas con valor>50 y las 10 filas siguientes</LINGO-SUB><LINGO-BODY id="lingo-body-754828" slang="en-US" mode="CREATE"><P>Aquí hay tres opciones diferentes, es posible que capturen filas incorrectas debido a errores uno por uno.</P>
<PRE><CODE class=" language-jsl">// Option1
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
// https://leetcode.com/problems/merge-intervals/solutions/3161191/solution/
merge_intervals = function({intervals}, {Default Local},
// Assumes array is sorted by first index
stack = {};
For Each({interval}, intervals,
If(N Items(stack) == 0 | stack[N Items(stack)][2] < interval[1],
Insert Into(stack, Eval List({interval}));
,
stack[N Items(stack)][2] = max(stack[N Items(stack)][2], interval[2]);
);
);
return(stack);
);
r_start = (dt << Get Rows Where(:weight > 120)) + 1;
r_end = r_start + 10;
toohigh = Loc(r_start > N Rows(dt));
r_start[toohigh] = N Rows(dt);
toohigh = Loc(r_end > N Rows(dt));
r_end[toohigh] = N Rows(dt);
rs = As List(r_start || r_end);
res = merge_intervals(rs);
// Option2
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
r_start = dt << Get Rows Where(:weight > 120);
res2 = dt << get rows where(Any(Row() > r_start & Row() <= r_start + 10));
// Option3
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
r = As List(dt << Get Rows Where(:weight > 120));
rs = {};
max_rows = N Rows(dt);
For Each({cur_r}, r,
Insert Into(rs, As List(Index(Min(max_rows, cur_r + 1), Min(max_rows, cur_r + 10))));
);
Seleccione el mensaje << Seleccione Filas() a la tabla de datos.
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
r_start = dt << Get Rows Where(:weight > 120);
res2 = dt << get rows where(Any(Row() > r_start & Row() <= r_start + 10));
dt << Select Rows(res2);Para convertir las filas seleccionadas en una nueva tabla de datos, solo es necesario utilizar la plataforma de subconjunto.
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
r_start = dt << Get Rows Where(:weight > 120);
res2 = dt << get rows where(Any(Row() > r_start & Row() <= r_start + 10));
dt << Select Rows(res2);
dtSub = dt << subset( selected rows(1), selected columns(0));¡Muchas gracias! ¿Cómo puedo convertir rs (todas las filas seleccionadas) en una nueva tabla de datos?