## Column value is based dominate element of topic vector

Community Trekker

Joined:

Mar 4, 2017

I've used the text analysis tool and saved off a topic vector to my dataset.  This shows up as 10 new columns labeled Topic1 through Topic10.  I want a new column called "dominant topic" which is labeled topic 1-10 based based on which of the previous 10 columns had the largest value.  What's the easiest way to do this?  I suppose I could write a large formula, but I'm hoping someone knows an easier way.

1 ACCEPTED SOLUTION

Accepted Solutions

Super User

Joined:

Jun 22, 2012

Solution

Here is a formula that will do what you want

If( Row() == 1,
varList = {"Topic1", "Topic2", "Topic3", "Topic4", "Topic5", "Topic6",
"Topic7", "Topic8", "Topic9", "Topic10"}
);
valueList = {};
For( i = 1, i <= N Items( varList ), i++,
Insert Into( valueList, As Column( varList[i] ) )
);
TheTopic = "Topic" || Char( Contains( valueList, Max( valueList ) ) );
TheTopic;
Jim
2 REPLIES

Super User

Joined:

Jun 22, 2012

Solution

Here is a formula that will do what you want

If( Row() == 1,
varList = {"Topic1", "Topic2", "Topic3", "Topic4", "Topic5", "Topic6",
"Topic7", "Topic8", "Topic9", "Topic10"}
);
valueList = {};
For( i = 1, i <= N Items( varList ), i++,
Insert Into( valueList, As Column( varList[i] ) )
);
TheTopic = "Topic" || Char( Contains( valueList, Max( valueList ) ) );
TheTopic;
Jim

Community Trekker

Joined:

Mar 4, 2017

Wow! That's very cool code. I didn't even know that functionality existed, but that totally worked. I'm now going to use this as a template for other things as well. Thank you very much. You've not only help me with this problem, but you've opened up a new world of jmp functionality to me.