Message Boards Message Boards

0
|
2860 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
Posted 10 years ago

Henrik, thanks. Not tried it yet, the morning after I posted I was in an accident and fractured my hip. Just got back to my PC. Once I can concentrate a bit better I will have a go at it and let you know how I get on.

POSTED BY: bjc

Hi,

one simple and direct way is:

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

I hope that helps, cheers!

Henrik

POSTED BY: Henrik Schachner
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