# How to do a Check for every element in the list?

I know how to do a Check for the list in general:

lst = {"0/0", "1/25", "1/36", "1/49"}

Quiet[Check[StringReplace[lst, "0/0" -> Missing["Unavailable"]] // ToExpression, _, ToExpression::notstrbox], ToExpression::notstrbox]


But I need to to the check that for each element, so to have a result like:

{Missing["Unavailable"], 1/25, 1/36, 1/49}


Any idea? Thanks!

• Why not simply lst /. {"0/0" :> Missing["Unavailable"]} ? Commented Apr 15, 2015 at 13:46
• How about myfun[x_] := If[x == "0/0", Missing["Unavailable"], ToExpression[x]] Commented Apr 15, 2015 at 13:51
• @Mr.Wizard I need to do ToExpression after Commented Apr 15, 2015 at 13:53
• @Mr.Wizard I think he wants numerical out puts as 1/25 instead of "1/25". In your case, the replacement rule only replaces the "0/0" case, but does not convert the strings to numerical values? Commented Apr 15, 2015 at 13:53
• Sorry, I missed that part. Reopened. Commented Apr 15, 2015 at 13:54

myfun[x_] := If[x == "0/0", Missing["Unavailable"], ToExpression[x]]
Map[myfun, lst]


{Missing["Unavailable"], 1/25, 1/36, 1/49}

Possibly you would be pleased with an alternative approach:

lst = {"0/0", "1/25", "1/36", "1/49"};

Quiet @ ToExpression @ lst /. Indeterminate -> Missing["Unavailable"]

{Missing["Unavailable"], 1/25, 1/36, 1/49}

lst = {"0/0", "1/25", "1/36", "1/49"};


Temporarily change the definition of Indeterminate to Missing["NotAvailable"]:

Block[{Indeterminate = Missing["NotAvailable"]}, Quiet@ToExpression@lst]


{Missing["NotAvailable"], 1/25, 1/36, 1/49}