dataset create categorical variables from existing variable
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Tom Lane
2013-3-15
Start with this and see if it gets you anywhere:
d = dataset;
d.a = (ds=='a')
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!