Message Boards Message Boards

0
|
4867 Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

Select non-numeric items from a list that has some numeric items?

Posted 9 years ago

How do I Select the non-numeric items from a list that is a mixture of numeric and non-numeric items?

list = {0, 0, f, 0, g, 0, 0, h, 0, f, 0, 0, 0, h};
Select[list, NumericQ]
Select[list, ! NumericQ]

This returns

{0, 0, 0, 0, 0, 0, 0, 0, 0}

and

{}

but I want the second returned line to be

{f,g,h,f,h}

Jerry

POSTED BY: Jerry
4 Replies
Posted 9 years ago

Thanks for that as well, Gianluca.

Jerry

POSTED BY: Jerry

With Cases you can avoid pure functions:

Cases[{0, 0, f, 0, g, 0, 0, h, 0, f, 0, 0, 0, h}, Except[_?NumericQ]]
POSTED BY: Gianluca Gorni
Posted 9 years ago

Thanks, Paul. So much to learn....

This works too:

Select[list, ! NumericQ[#] &]

Jerry

POSTED BY: Jerry
Posted 9 years ago

Hi Jerry

This works

Select[list, Not[NumericQ[#]] &]

Paul.

POSTED BY: Paul Cleary
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract