How to compute weighted average

6 ビュー (過去 30 日間)
gcicceri
gcicceri 2021 年 5 月 10 日
回答済み: KSSV 2021 年 5 月 10 日
Hi guys,
I need to understand how to perform a weighted average with the following example.
I have three columns in the following example table:
id m f
'a' 54 50
'b' 40 60
'c' 30 70
The question is: how do I create a third column (named wa), which computes the weighted average (m = 40%) + (f = 60%) and transfer it to this third column?
In this example my final table will be:
id m f wa
'a' 54 50 51.6
'b' 40 60 52
'c' 30 70 54
Thanks in advance.

採用された回答

KSSV
KSSV 2021 年 5 月 10 日
A = [54 50 ; 40 60 ; 30 70] ;
A(:,3) = 0.4*A(:,1)+0.6*A(:,2)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by