Extracting specific data from a list
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
Consider the following list
1., -1, 1.5, -1, 2., 1, 2.5, 1, 3., 1, 3.5, 1, 4., 1, 4.5, 1, 5., 1, 5.5, 1, 6., 1, 6.5, 1, 7., -1, 7.5, -1, 8., -1, 8.5, -1, 9., -1, 9.5, -1, 10., -1
How can I extract only the values after (or before) the second element in the 2-element sublists changes sign, i.e, I would like to obtain as a result
2., 1,7., -1
list-manipulation
add a comment |Â
up vote
2
down vote
favorite
Consider the following list
1., -1, 1.5, -1, 2., 1, 2.5, 1, 3., 1, 3.5, 1, 4., 1, 4.5, 1, 5., 1, 5.5, 1, 6., 1, 6.5, 1, 7., -1, 7.5, -1, 8., -1, 8.5, -1, 9., -1, 9.5, -1, 10., -1
How can I extract only the values after (or before) the second element in the 2-element sublists changes sign, i.e, I would like to obtain as a result
2., 1,7., -1
list-manipulation
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Consider the following list
1., -1, 1.5, -1, 2., 1, 2.5, 1, 3., 1, 3.5, 1, 4., 1, 4.5, 1, 5., 1, 5.5, 1, 6., 1, 6.5, 1, 7., -1, 7.5, -1, 8., -1, 8.5, -1, 9., -1, 9.5, -1, 10., -1
How can I extract only the values after (or before) the second element in the 2-element sublists changes sign, i.e, I would like to obtain as a result
2., 1,7., -1
list-manipulation
Consider the following list
1., -1, 1.5, -1, 2., 1, 2.5, 1, 3., 1, 3.5, 1, 4., 1, 4.5, 1, 5., 1, 5.5, 1, 6., 1, 6.5, 1, 7., -1, 7.5, -1, 8., -1, 8.5, -1, 9., -1, 9.5, -1, 10., -1
How can I extract only the values after (or before) the second element in the 2-element sublists changes sign, i.e, I would like to obtain as a result
2., 1,7., -1
list-manipulation
list-manipulation
asked Aug 19 at 13:32
jarhead
689413
689413
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
5
down vote
accepted
First /@ Rest@SplitBy[list, Sign[#[[2]]] &]
2., 1, 7., -1
or
First /@ Rest@Split[list, Sign[#[[2]]] == Sign[#2[[2]]] &]
2., 1, 7., -1
Also
Pick[list, Developer`ToPackedArray[Unitize[Join[0,
Differences @ UnitStep @ Transpose[list][[2]]]]], 1]
2., 1, 7., -1
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
First /@ Rest@SplitBy[list, Sign[#[[2]]] &]
2., 1, 7., -1
or
First /@ Rest@Split[list, Sign[#[[2]]] == Sign[#2[[2]]] &]
2., 1, 7., -1
Also
Pick[list, Developer`ToPackedArray[Unitize[Join[0,
Differences @ UnitStep @ Transpose[list][[2]]]]], 1]
2., 1, 7., -1
add a comment |Â
up vote
5
down vote
accepted
First /@ Rest@SplitBy[list, Sign[#[[2]]] &]
2., 1, 7., -1
or
First /@ Rest@Split[list, Sign[#[[2]]] == Sign[#2[[2]]] &]
2., 1, 7., -1
Also
Pick[list, Developer`ToPackedArray[Unitize[Join[0,
Differences @ UnitStep @ Transpose[list][[2]]]]], 1]
2., 1, 7., -1
add a comment |Â
up vote
5
down vote
accepted
up vote
5
down vote
accepted
First /@ Rest@SplitBy[list, Sign[#[[2]]] &]
2., 1, 7., -1
or
First /@ Rest@Split[list, Sign[#[[2]]] == Sign[#2[[2]]] &]
2., 1, 7., -1
Also
Pick[list, Developer`ToPackedArray[Unitize[Join[0,
Differences @ UnitStep @ Transpose[list][[2]]]]], 1]
2., 1, 7., -1
First /@ Rest@SplitBy[list, Sign[#[[2]]] &]
2., 1, 7., -1
or
First /@ Rest@Split[list, Sign[#[[2]]] == Sign[#2[[2]]] &]
2., 1, 7., -1
Also
Pick[list, Developer`ToPackedArray[Unitize[Join[0,
Differences @ UnitStep @ Transpose[list][[2]]]]], 1]
2., 1, 7., -1
edited Aug 19 at 13:46
answered Aug 19 at 13:36
kglr
161k8185384
161k8185384
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f180242%2fextracting-specific-data-from-a-list%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password