Message Boards Message Boards

0
|
2858 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

How do I convert a list of lists suitable for the Classify function?

Posted 10 years ago

I have a structure like data = {{A,1,2,3,4},{A,3,2,6,9},{B,102,201,544,123},{B,300,422,122},{A,44,1,89,7}, etc}, where the classes A and B contain a number of fields. I want to use this in the Classify function but this needs a structure of the form: {{1,2,3,4}->"A",{3,2,6,9}->"A",{102,201,544,123}->"B", etc}. I thought Association would be the way to go but can't figure out how.

POSTED BY: bjc
2 Replies

Hi,

one simple and direct way is:

Rule[Rest[#], ToString @ First[#]] & /@ data

I hope that helps, cheers!

Henrik

POSTED BY: Henrik Schachner
Posted 10 years ago
POSTED BY: bjc
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