How do I use drop to drop the second element from all these sublists? [duplicate]
$begingroup$
This question already has an answer here:
Correct way to remove matrix columns?
3 answers
How to use “Drop” function to drop matrix' rows and columns in an arbitrary way?
2 answers
{{1, 2}, {2, 3}, {5, 4}}
I tried to do this:
Drop[#, {2}] & @@ {{1, 2}, {2, 3}, {5, 4}}
but it gave
{1}
but what I want is
{{1},{2},{5}}
list-manipulation
$endgroup$
marked as duplicate by Lukas Lang, José Antonio Díaz Navas, Henrik Schumacher, Mr.Wizard♦
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 9 at 0:56
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
$begingroup$
This question already has an answer here:
Correct way to remove matrix columns?
3 answers
How to use “Drop” function to drop matrix' rows and columns in an arbitrary way?
2 answers
{{1, 2}, {2, 3}, {5, 4}}
I tried to do this:
Drop[#, {2}] & @@ {{1, 2}, {2, 3}, {5, 4}}
but it gave
{1}
but what I want is
{{1},{2},{5}}
list-manipulation
$endgroup$
marked as duplicate by Lukas Lang, José Antonio Díaz Navas, Henrik Schumacher, Mr.Wizard♦
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 9 at 0:56
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
3
$begingroup$
UseMap
(/@
) instead ofApply
(@@
).Drop[#, {2}] & @@ {{1, 2}, {2, 3}, {5, 4}}
is essentially equivalent toDrop[{1, 2}, {2, 3}, {5, 4}, {2}]
, which is clearly not what you want
$endgroup$
– Lukas Lang
Jan 8 at 12:19
2
$begingroup$
I'd like to add to the answers here that the correct function for dropping a single element isDelete
, notDrop
.Drop
is the opposite ofTake
.
$endgroup$
– Sjoerd Smit
Jan 8 at 14:06
$begingroup$
Welcome to Mathematica.SE user62264! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign!
$endgroup$
– Chris K
Jan 8 at 14:40
add a comment |
$begingroup$
This question already has an answer here:
Correct way to remove matrix columns?
3 answers
How to use “Drop” function to drop matrix' rows and columns in an arbitrary way?
2 answers
{{1, 2}, {2, 3}, {5, 4}}
I tried to do this:
Drop[#, {2}] & @@ {{1, 2}, {2, 3}, {5, 4}}
but it gave
{1}
but what I want is
{{1},{2},{5}}
list-manipulation
$endgroup$
This question already has an answer here:
Correct way to remove matrix columns?
3 answers
How to use “Drop” function to drop matrix' rows and columns in an arbitrary way?
2 answers
{{1, 2}, {2, 3}, {5, 4}}
I tried to do this:
Drop[#, {2}] & @@ {{1, 2}, {2, 3}, {5, 4}}
but it gave
{1}
but what I want is
{{1},{2},{5}}
This question already has an answer here:
Correct way to remove matrix columns?
3 answers
How to use “Drop” function to drop matrix' rows and columns in an arbitrary way?
2 answers
list-manipulation
list-manipulation
edited Jan 8 at 14:24
Glorfindel
2191311
2191311
asked Jan 8 at 12:10
user62264user62264
211
211
marked as duplicate by Lukas Lang, José Antonio Díaz Navas, Henrik Schumacher, Mr.Wizard♦
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 9 at 0:56
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Lukas Lang, José Antonio Díaz Navas, Henrik Schumacher, Mr.Wizard♦
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 9 at 0:56
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
3
$begingroup$
UseMap
(/@
) instead ofApply
(@@
).Drop[#, {2}] & @@ {{1, 2}, {2, 3}, {5, 4}}
is essentially equivalent toDrop[{1, 2}, {2, 3}, {5, 4}, {2}]
, which is clearly not what you want
$endgroup$
– Lukas Lang
Jan 8 at 12:19
2
$begingroup$
I'd like to add to the answers here that the correct function for dropping a single element isDelete
, notDrop
.Drop
is the opposite ofTake
.
$endgroup$
– Sjoerd Smit
Jan 8 at 14:06
$begingroup$
Welcome to Mathematica.SE user62264! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign!
$endgroup$
– Chris K
Jan 8 at 14:40
add a comment |
3
$begingroup$
UseMap
(/@
) instead ofApply
(@@
).Drop[#, {2}] & @@ {{1, 2}, {2, 3}, {5, 4}}
is essentially equivalent toDrop[{1, 2}, {2, 3}, {5, 4}, {2}]
, which is clearly not what you want
$endgroup$
– Lukas Lang
Jan 8 at 12:19
2
$begingroup$
I'd like to add to the answers here that the correct function for dropping a single element isDelete
, notDrop
.Drop
is the opposite ofTake
.
$endgroup$
– Sjoerd Smit
Jan 8 at 14:06
$begingroup$
Welcome to Mathematica.SE user62264! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign!
$endgroup$
– Chris K
Jan 8 at 14:40
3
3
$begingroup$
Use
Map
(/@
) instead of Apply
(@@
). Drop[#, {2}] & @@ {{1, 2}, {2, 3}, {5, 4}}
is essentially equivalent to Drop[{1, 2}, {2, 3}, {5, 4}, {2}]
, which is clearly not what you want$endgroup$
– Lukas Lang
Jan 8 at 12:19
$begingroup$
Use
Map
(/@
) instead of Apply
(@@
). Drop[#, {2}] & @@ {{1, 2}, {2, 3}, {5, 4}}
is essentially equivalent to Drop[{1, 2}, {2, 3}, {5, 4}, {2}]
, which is clearly not what you want$endgroup$
– Lukas Lang
Jan 8 at 12:19
2
2
$begingroup$
I'd like to add to the answers here that the correct function for dropping a single element is
Delete
, not Drop
. Drop
is the opposite of Take
.$endgroup$
– Sjoerd Smit
Jan 8 at 14:06
$begingroup$
I'd like to add to the answers here that the correct function for dropping a single element is
Delete
, not Drop
. Drop
is the opposite of Take
.$endgroup$
– Sjoerd Smit
Jan 8 at 14:06
$begingroup$
Welcome to Mathematica.SE user62264! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign!
$endgroup$
– Chris K
Jan 8 at 14:40
$begingroup$
Welcome to Mathematica.SE user62264! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign!
$endgroup$
– Chris K
Jan 8 at 14:40
add a comment |
3 Answers
3
active
oldest
votes
$begingroup$
lst = {{1, 2}, {2, 3}, {5, 4}};
Drop[lst, None, {2}]
{{1}, {2}, {5}}
$endgroup$
add a comment |
$begingroup$
Your result is the first column of a matrix. If list={{1, 2}, {2, 3}, {5, 4}}
,
res=list[[All, 1]]
If you need the brackets around each element, Partition[res, 1]
If your lists are of unequal length, the solution from Lukas Lang is fine. I include for completeness.
Drop[#, {2}] & /@ {{1, 2}, {2, 3}, {5, 4}}
$endgroup$
add a comment |
$begingroup$
Also,
Drop[{{1, 2}, {2, 3}, {5, 4}}, None, -1]
$endgroup$
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
lst = {{1, 2}, {2, 3}, {5, 4}};
Drop[lst, None, {2}]
{{1}, {2}, {5}}
$endgroup$
add a comment |
$begingroup$
lst = {{1, 2}, {2, 3}, {5, 4}};
Drop[lst, None, {2}]
{{1}, {2}, {5}}
$endgroup$
add a comment |
$begingroup$
lst = {{1, 2}, {2, 3}, {5, 4}};
Drop[lst, None, {2}]
{{1}, {2}, {5}}
$endgroup$
lst = {{1, 2}, {2, 3}, {5, 4}};
Drop[lst, None, {2}]
{{1}, {2}, {5}}
answered Jan 8 at 12:34
kglrkglr
180k9200413
180k9200413
add a comment |
add a comment |
$begingroup$
Your result is the first column of a matrix. If list={{1, 2}, {2, 3}, {5, 4}}
,
res=list[[All, 1]]
If you need the brackets around each element, Partition[res, 1]
If your lists are of unequal length, the solution from Lukas Lang is fine. I include for completeness.
Drop[#, {2}] & /@ {{1, 2}, {2, 3}, {5, 4}}
$endgroup$
add a comment |
$begingroup$
Your result is the first column of a matrix. If list={{1, 2}, {2, 3}, {5, 4}}
,
res=list[[All, 1]]
If you need the brackets around each element, Partition[res, 1]
If your lists are of unequal length, the solution from Lukas Lang is fine. I include for completeness.
Drop[#, {2}] & /@ {{1, 2}, {2, 3}, {5, 4}}
$endgroup$
add a comment |
$begingroup$
Your result is the first column of a matrix. If list={{1, 2}, {2, 3}, {5, 4}}
,
res=list[[All, 1]]
If you need the brackets around each element, Partition[res, 1]
If your lists are of unequal length, the solution from Lukas Lang is fine. I include for completeness.
Drop[#, {2}] & /@ {{1, 2}, {2, 3}, {5, 4}}
$endgroup$
Your result is the first column of a matrix. If list={{1, 2}, {2, 3}, {5, 4}}
,
res=list[[All, 1]]
If you need the brackets around each element, Partition[res, 1]
If your lists are of unequal length, the solution from Lukas Lang is fine. I include for completeness.
Drop[#, {2}] & /@ {{1, 2}, {2, 3}, {5, 4}}
answered Jan 8 at 12:24
TitusTitus
645417
645417
add a comment |
add a comment |
$begingroup$
Also,
Drop[{{1, 2}, {2, 3}, {5, 4}}, None, -1]
$endgroup$
add a comment |
$begingroup$
Also,
Drop[{{1, 2}, {2, 3}, {5, 4}}, None, -1]
$endgroup$
add a comment |
$begingroup$
Also,
Drop[{{1, 2}, {2, 3}, {5, 4}}, None, -1]
$endgroup$
Also,
Drop[{{1, 2}, {2, 3}, {5, 4}}, None, -1]
answered Jan 8 at 19:52
m_goldbergm_goldberg
85.1k872196
85.1k872196
add a comment |
add a comment |
3
$begingroup$
Use
Map
(/@
) instead ofApply
(@@
).Drop[#, {2}] & @@ {{1, 2}, {2, 3}, {5, 4}}
is essentially equivalent toDrop[{1, 2}, {2, 3}, {5, 4}, {2}]
, which is clearly not what you want$endgroup$
– Lukas Lang
Jan 8 at 12:19
2
$begingroup$
I'd like to add to the answers here that the correct function for dropping a single element is
Delete
, notDrop
.Drop
is the opposite ofTake
.$endgroup$
– Sjoerd Smit
Jan 8 at 14:06
$begingroup$
Welcome to Mathematica.SE user62264! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign!
$endgroup$
– Chris K
Jan 8 at 14:40