0
$\begingroup$

I have table with numeric values like

-1       0       1
0,7     0,19    0,11
0,06    0,15    0,79
0,17    0,18    0,65
0,15    0,48    0,37
0,04    0,28    0,58
0,57    0,02    0,41
0,17    0,69    0,14  

Suppose values are the probability of occurence of the specific class, hence, in first row the -1 class is likely to occur while other two won't.

Each row has one major number in one column (that basically indicates what class is likely to occur. -1 for first row, 1 for second, 1 for third etc.). What I want to get is get one single number normalized across row and approximated to the column header. Like, the higher the number in column the closer it to column header.

Basically, if major number is in the first column, there must be negative number closer to -1, in second - closer to +1, in last - closer to 0.

Example of resulted column:

 -1      0       1        result
0,7     0,19    0,11       -0.68
0,06    0,15    0,79        0.75
0,17    0,18    0,65        0.58
0,15    0,48    0,37        0.25
0,04    0,28    0,58        0.42
0,57    0,02    0,41       -0.41
0,17    0,69    0,14        0.15

I tried to do row-wise normalization but it obviously does not approximates the number to the column header.

$\endgroup$
0
$\begingroup$

Looks like you might want a weighted mean, the column names are the values, the probabilities are the weights.

df=read.table(text="
-1       0       1
0,7     0,19    0,11
0,06    0,15    0,79
0,17    0,18    0,65
0,15    0,48    0,37
0,04    0,28    0,58
0,57    0,02    0,41
0,17    0,69    0,14",h=T,dec=",")

apply(df,1,function(x){
  weighted.mean(c(-1,0,1),x)
})

[1] -0.59  0.73  0.48  0.22  0.60 -0.16 -0.03
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.