Message Boards Message Boards

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

Map rankings to particular values

Posted 11 years ago
Hello,

I am new to the community.  I am a financial hobbyist(used to be professional) that likes to get into creating models and testing ideas.
I have been working hard  on learning Mathematica.

I am trying to see if I can accomplish the following:
I have a list of rankings a={3,2,1,4}
I want to map the rankings to particular values for example, 1-> .05, 2-> .1 etc.

I spent a bunch of time learning about Association and Keys only to find out that they are in the new upcoming version. So while promising, they are of no use to me now.

Is there a way in the current version to get this remapping done?

Thanks in advance,

Mario
POSTED BY: Mario Montoya
5 Replies
Formatting suggestions are in

   http://community.wolfram.com/groups/-/m/t/151347

(Well, they are not exactly suggestions.)
POSTED BY: Bruce Miller
Posted 11 years ago
Got it.  Thanks!

Much better than the nested If's.

Mario
POSTED BY: Mario Montoya
Posted 11 years ago
r[x_] := Which[
  x == 1, .02,
  x == 2, .03,
  x == 3, .05,
  x == 4, .1,
  x == 5, .15,
  x == 6, .25];
weights = Table[r /@ size[], {i, 1, days}];
Using the little <> near the right end of the second row of "buttons" when posting will sometimes help you format code, sometimes not.

If you are absolutely sure your x will only have positive adjacent integer values then something like this might work.
r[x_]:=(.02,.03,.05,.1,.15,.25}[[x]];
weights=Table[r/@size[],{i,1,days}];
but that is dangerous and questionable practice
POSTED BY: Bill Simpson
Posted 11 years ago
Thanks for the reply.  I just made it do what I wanted but it is not a very elegant solution.  Hopefully, it will be clear what I want from my solution.
r[x_]:=If[x==1,.02,If[x==2,.03,If[x==3,.05,If[x==4,.1,If[x==5,.15,If[x==6,.25,If[x==7]]]]]];
weights=Table[r /@ size[[i]],{i,1,days}];[/i]

so now my "weights" have transformed from integers "x" (the input to the function r) into a list with numbers corresponding to values of x.  So when x is 2, my function returns 0.03 


Ugh, the formatting is terrible.  I don't know how to copy the way it looks in notebook (as I have seen others).  Sorry.
POSTED BY: Mario Montoya
Posted 11 years ago
You have one input called rankings which is a list of integers, that is clear. It isn't clear what form your second input is in, it isn't clear how this form relates to ranking, it isn't clear what form you want to put this into and it isn't clear what you want to do with the result. If you could provide a blindingly clear complete example with just enough supporting explanation that someone who doesn't know anything about what you know would be able to produce exactly what you are looking for on the first try then that would be really helpful.
POSTED BY: Bill Simpson
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