0

I am new to matlab. I have a categorical input predictor(X) and the set of past results (Y, binary). I would like to convert it to numeric variable in the following method. For each category calculate the average of Y and replace the value with the average. for example:

  X    Y    X'
  1    1    1
  2    0    0
  3    1    0.5
  1    1    1
  2    0    0
  3    0    0.5

Please help.

Shai
  • 111,146
  • 38
  • 238
  • 371
Ron
  • 1

1 Answers1

0

you are looking for accumarray with mean function with Y as vals and X as subs

Xprime = accumarray( X, Y, [], @mean );
Xprime = Xptime( X );
Shai
  • 111,146
  • 38
  • 238
  • 371