フィルターのクリア

Not able to make dummy variables

1 回表示 (過去 30 日間)
Malene Brautaset
Malene Brautaset 2022 年 3 月 19 日
コメント済み: Voss 2022 年 3 月 25 日
Hello.
We have a problem making dummy variables since our variables has ' ' around them ('M'). We have a column with 'M' and 'F' and have to make dummy variables in order to use it in our regression.
How do we fix this?

回答 (1 件)

Voss
Voss 2022 年 3 月 19 日
編集済み: Voss 2022 年 3 月 19 日
C = readcell('data.csv')
C = 4×6 cell array
{'pcid' } {'year'} {'currency'} {'gender'} {'revenue'} {'netIncome'} {[887700702]} {[2010]} {''NOK'' } {''F'' } {[9837000]} {[ 533000]} {[887704902]} {[2010]} {''NOK'' } {''M'' } {[ 757000]} {[ -224000]} {[887705992]} {[2010]} {''NOK'' } {''M'' } {[6631000]} {[ 681000]}
dummy_gender = strcmp(C(2:end,4),'''M''')
dummy_gender = 3×1 logical array
0 1 1
  2 件のコメント
Malene Brautaset
Malene Brautaset 2022 年 3 月 25 日
Thank you! This worked. But however, we want to keep our dataset in a table; is there a code we can use for the original dataset in a table?
Voss
Voss 2022 年 3 月 25 日
You're welcome!
Sure, here is a table version:
T = readtable('data.csv')
T = 3×6 table
pcid year currency gender revenue netIncome __________ ____ _________ _______ _________ _________ 8.877e+08 2010 {''NOK''} {''F''} 9.837e+06 5.33e+05 8.877e+08 2010 {''NOK''} {''M''} 7.57e+05 -2.24e+05 8.8771e+08 2010 {''NOK''} {''M''} 6.631e+06 6.81e+05
dummy_gender = strcmp(T{:,'gender'},'''M''')
dummy_gender = 3×1 logical array
0 1 1

サインインしてコメントする。

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by