Skip to main content
Added missing brackets
Source Link
eldo
  • 83.1k
  • 6
  • 72
  • 202
lis1 = {{{a1, b1, c1, d1, e1}, {a2, b2, c2, d2, e2}}, {{a3, b3, c3, 
    d3, e3}, {a4, b4, c4, d4, e4}}};

MapAt[Nothing, {All, All, {2, 4}}] @ lis1

ReplaceAt[_ :> Nothing, {All, All, {2, 4}}] @ lis1

Both give the expected result:

{{{a1, c1, e1}, {a2, c2, e2}}, {{a3, c3, e3}, {a4, c4, e4}}}

ReplaceAt was introduced in V 13.1 and has the advantage that we can use the usual Condition syntax. Example:

ReplaceAt[lis1, x_ /; SymbolName[x] != "b1" :> Nothing, {All, All, {2, 4}}]

{{{a1, b1, c1, e1}, {a2, c2, e2}}, {{a3, c3, e3}, {a4, c4, e4}}}

lis1 = {{a1, b1, c1, d1, e1}, {a2, b2, c2, d2, e2}}, {{a3, b3, c3, 
    d3, e3}, {a4, b4, c4, d4, e4}};

MapAt[Nothing, {All, All, {2, 4}}] @ lis1

ReplaceAt[_ :> Nothing, {All, All, {2, 4}}] @ lis1

Both give the expected result:

{{{a1, c1, e1}, {a2, c2, e2}}, {{a3, c3, e3}, {a4, c4, e4}}}

ReplaceAt was introduced in V 13.1 and has the advantage that we can use the usual Condition syntax. Example:

ReplaceAt[lis1, x_ /; SymbolName[x] != "b1" :> Nothing, {All, All, {2, 4}}]

{{{a1, b1, c1, e1}, {a2, c2, e2}}, {{a3, c3, e3}, {a4, c4, e4}}}

lis1 = {{{a1, b1, c1, d1, e1}, {a2, b2, c2, d2, e2}}, {{a3, b3, c3, 
    d3, e3}, {a4, b4, c4, d4, e4}}};

MapAt[Nothing, {All, All, {2, 4}}] @ lis1

ReplaceAt[_ :> Nothing, {All, All, {2, 4}}] @ lis1

Both give the expected result:

{{{a1, c1, e1}, {a2, c2, e2}}, {{a3, c3, e3}, {a4, c4, e4}}}

ReplaceAt was introduced in V 13.1 and has the advantage that we can use the usual Condition syntax. Example:

ReplaceAt[lis1, x_ /; SymbolName[x] != "b1" :> Nothing, {All, All, {2, 4}}]

{{{a1, b1, c1, e1}, {a2, c2, e2}}, {{a3, c3, e3}, {a4, c4, e4}}}

Source Link
eldo
  • 83.1k
  • 6
  • 72
  • 202

lis1 = {{a1, b1, c1, d1, e1}, {a2, b2, c2, d2, e2}}, {{a3, b3, c3, 
    d3, e3}, {a4, b4, c4, d4, e4}};

MapAt[Nothing, {All, All, {2, 4}}] @ lis1

ReplaceAt[_ :> Nothing, {All, All, {2, 4}}] @ lis1

Both give the expected result:

{{{a1, c1, e1}, {a2, c2, e2}}, {{a3, c3, e3}, {a4, c4, e4}}}

ReplaceAt was introduced in V 13.1 and has the advantage that we can use the usual Condition syntax. Example:

ReplaceAt[lis1, x_ /; SymbolName[x] != "b1" :> Nothing, {All, All, {2, 4}}]

{{{a1, b1, c1, e1}, {a2, c2, e2}}, {{a3, c3, e3}, {a4, c4, e4}}}