# How to delete Missing["NotAvailable"] from list of rules? [duplicate]

Considering we have a list of rules:

{ First-> {a-> "aaaa", b-> "bbbb"}, Second-> {c-> "cccc", d-> "dddd", e-> Missing["NotAvailable"], f-> Missing["NotAvailable"] }}


How can I bring this to be:

{ First-> {a-> "aaaa", b-> "bbbb"}, Second-> {c-> "cccc", d-> "dddd" }}


Thanks.

list =
{First -> {a -> "aaaa", b -> "bbbb"}, Second -> {c -> "cccc", d -> "dddd"e -> Missing["NotAvailable"], f -> Missing["NotAvailable"]}}

DeleteCases[list, Rule[_, _Missing], Infinity]


{First -> {a -> "aaaa", b -> "bbbb"}, Second -> {c -> "cccc", d -> "dddd"}}

you can use DeleteMissing also

l = {First -> {a -> "aaaa", b -> "bbbb"},
Second -> {c -> "cccc", d -> "dddd", e -> Missing["NotAvailable"],
f -> Missing["NotAvailable"]}};

Normal@DeleteMissing[Association@l, Infinity]
(*{First -> {a -> "aaaa", b -> "bbbb"},Second -> {c -> "cccc", d -> "dddd"}}*)


Here is another alternative using UpValues:

Block[{Missing},
Missing /: _ -> Missing["NotAvailable"] := Sequence[];
{First -> {a -> "aaaa", b -> "bbbb"},
Second -> {c -> "cccc", d -> "dddd", e -> Missing["NotAvailable"],
f -> Missing["NotAvailable"]}}
]
(*
{First -> {a -> "aaaa", b -> "bbbb"}, Second -> {c -> "cccc", d -> "dddd"}}
*)

• That looks familiar Apr 8, 2015 at 16:26
• @Mr.Wizard really? I never would have guessed. Apr 8, 2015 at 17:15
• @Mr.Wizard Truthfully, I'm enamored with mma's homoiconicity and I think it should be demonstrated at every opportunity. Apr 8, 2015 at 17:26
• It is nice but beware of packed arrays. Apr 8, 2015 at 17:32
• @Mr.Wizard packed arrays can be special, along with most things that are AtomQ. Apr 8, 2015 at 17:34

Less elegant than DeleteCases, however an alternative:

exp = {First -> {a -> "aaaa", b -> "bbbb"},
Second -> {c -> "cccc", d -> "dddd", e -> Missing["NotAvailable"],
f -> Missing["NotAvailable"]}}

Delete[exp, Position[exp, _ -> _Missing]]


Or

 Delete[exp, Drop[#, -1] & /@ Position[exp, _Missing]]

(*{First -> {a -> "aaaa", b -> "bbbb"}, Second -> {c -> "cccc", d -> "dddd"}}*)