dataset create categorical variables from existing variable
2 views (last 30 days)
Show older comments
Hi I have a dataset containing a column(variable) of strings. From this strings I want to ad new variables of the uniqe string and create a categorical variable of it. Here is an example of what I want to do: ds=['a';'b';'c';'a';'a';'b';'c']. Final result I want is a dataset with a,b and c as added categorical variables to the dataset and as observations assign the values 0 and 1. So The categorical variabel a in the dataset should be a new column in ds a [1;0;0;0;1;1;0;0], b [0;1;0;0;0;0;1;0], c [0;0;1;0;0;0;0;1].
Please help
0 Comments
Answers (1)
Tom Lane
on 15 Mar 2013
Start with this and see if it gets you anywhere:
d = dataset;
d.a = (ds=='a')
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!