フィルターのクリア

How to divide a dataset into two subsamples?

1 回表示 (過去 30 日間)
IvyR
IvyR 2023 年 2 月 14 日
編集済み: Antonios Dougalis 2023 年 2 月 14 日
Hello,
Im trying to partition a datset into two subsamples. Unfortunately, I'm struggling to code it.
How do I divide a datset into two subsamples, one corresponding to those Losses that involved a LAWYER (=1) and the other to those in which a LAWYER was not involved (=2).
1 Lawyer LOSS
1 1 612
2 2 453
3 1 188
4 2 811
5 1 695
6 2 215
7 1 684
8 1 354
9 1 743
10 2 246
I tried to write the code in Matlab like this;
%Claims that a Lawyer is involved (=1)
LOSS_1=LOSS;
LOSS_1=LOSS(ATTORNEY(:,2)==1)
When I try to run it, I keep getting errors. What is the correct way of coding this. Thank you.

回答 (2 件)

Antonios Dougalis
Antonios Dougalis 2023 年 2 月 14 日
編集済み: Antonios Dougalis 2023 年 2 月 14 日
% Suppose that you have an array A with two columns (lawyer, loss)
A = [ [1;2;1;2;1;2;1;1;1;2], [612;453;188;811;695;215;684;354;743;246] ];
lawyer1 = find(A(:,1)==1); % indexes of the rows that are 1 corresponding to lawyer 1
lawyer2 = find(A(:,1)==2); % indexes of the rows that are 2 corresponding to lawyer 2
% use the indexes to extract the losses for each lawyer from the second
% column of A
loss_lawyer1 = A(lawyer1,2);
loss_lawyer2 = A(lawyer2,2);

Cameron
Cameron 2023 年 2 月 14 日
Try deleting this line
LOSS_1=LOSS;
If that doesn't work, paste your data for LOSS and ATTORNEY.

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by