Creating Dummy variables with new variable names for categorical variables
조회 수: 1 (최근 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!