# Test for non-numeric variables

I have a table, testdata, with numeric and non-numeric data.

testData = {{1, 2, 3, no, 5}, {5, 6, 7, 8, 9.1}, {1, y, y, n, n}};


I can locate the positions of numeric data easily

goodloc = Position[testData, _?NumericQ]

(* {{1, 1}, {1, 2}, {1, 3}, {1, 5}, {2, 1}, {2, 2}, {2, 3}, {2, 4}, {2,   5}, {3, 1}} *)


I would like an equally simple means to locate non-numeric variables

I have been able to get this result by using this code

 allPos = Flatten[Table[{i, j}, {i, 3}, {j, 5}], 1];

(* {{1, 4}, {3, 2}, {3, 3}, {3, 4}, {3, 5}} *)


Is there a single expression that will do this?

-
your oneliner might look like Complement[Flatten[MapIndexed[#2 &, testData, {2}], 1], Position[testData, _?NumericQ]] – garej Mar 26 at 21:31

You can simply do:

Position[testData, _?(Not@*NumericQ), {2}, Heads -> False]


{{1, 4}, {3, 2}, {3, 3}, {3, 4}, {3, 5}}

Notice the use of level specification so that you only look inside the sublists and the option Head -> False prevents you from including the position of Heads, since they are non-numeric. An alternative is to use Except as Kglr mentioned in the comments:

Position[testData, Except[_?NumericQ], {2}, Heads -> False]

-
... or Position[testData, Except[_?NumericQ], {2}, Heads -> False] (+1) – kglr Mar 26 at 19:21
@kglr. Thanks, that's a good alternative. – RunnyKine Mar 26 at 19:25
Position[Map[NumericQ, testData, {-1}], False]


{{1, 4}, {3, 2}, {3, 3}, {3, 4}, {3, 5}}

-
or Position[Map[NumericQ, testData, {2}], False] – garej Mar 27 at 6:52
This is just what I was looking for. Thank you – martin keane Mar 27 at 23:18