Creating Dummy variables with new variable names for categorical variables
3 ビュー (過去 30 日間)
古いコメントを表示
I have a dataset with 8 categorical variables "Var1" "Var2"....."Var8"
Each categorical variable has different unique values. I want to create dummy variables for each of the "Var#" variable in this table and these new dummy variables need to be renamed as "Var1_1", "Var1_2" and "Var1_3", assuming Var1 has 3 unique values.
In the Matlab central, there was a post that created a function called "dummytable", but that function did not do what I expected.
I have attached the table in this request. Table name is "AllDataCategorical.mat"
2 件のコメント
Stephen23
2021 年 4 月 29 日
S = load('AllDataCategorical.mat');
T = S.AllData_Categorical
Please show what the expected output looks like.
回答 (1 件)
Jan
2021 年 4 月 29 日
"Var1, Var2, ..." is a bad programming style, because hiding indices in the names of the variables makes it hard, to access them later. Appending a send index like in Var1_1 makes it worse.
Use arrays instead: Var(1), Var(2), ... or maybe cells Var{1}, Var{2}, ... Then it is easy to process the data in loops.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Categorical Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!