Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have this list:

a = {{{0, 0}, {1, 7}, {2, 0}, {3, 2}, {4, 7}}, {{0, 0}, {1, 0}, {2, 1}, {3, 2}, {4, 7}}}

and I'd like to transform it to this:

a = {{{0, 0}, {1, 7}, {2, Na}, {3, 2}, {4, 7}}, {{0, 0}, {1, Na}, {2, 1}, {3, 2}, {4, 7}}}

ie I'd like to replace every 0 by Na except in the first sub-sub-list of each sub-list.

All I can come up with is:

Part[#, 2 ;; All, All] & /@ a  /. 0 -> Na

and it works I get

{{{1, 7}, {2, Na}, {3, 2}, {4, 7}}, {{1, Na}, {2, 1}, {3, 2}, {4, 7}}}

but the modification is not attributed to a.

How can I do that?

share|improve this question
    
a = Part[#, 2 ;; All, All] & /@ a /. 0 -> Na or perhaps you intended to modify the original copy of a ? –  image_doctor Jan 8 '13 at 12:10
    
yes I need to modify the original copy of a your solution below works thanks! –  su1 Jan 8 '13 at 12:58

2 Answers 2

This will work if all your first elements of the sub-lists are of the form {0,0}

a = a /. {{x_?Positive, 0} :> {x, Na}};
a

{{{0, 0}, {1, 7}, {2, Na}, {3, 2}, {4, 7}}, {{0, 0}, {1, Na}, {2, 1}, {3, 2}, {4, 7}}}

share|improve this answer

Another quick possibility

a=a/. {n_, r:{_Integer,_Integer}...} :> Join[{n},{ r} /. 0->Na]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.