dataset create categorical variables from existing variable

2 ビュー (過去 30 日間)
jonas
jonas 2013 年 3 月 15 日
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

回答 (1 件)

Tom Lane
Tom Lane 2013 年 3 月 15 日
Start with this and see if it gets you anywhere:
d = dataset;
d.a = (ds=='a')

Community Treasure Hunt

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

Start Hunting!

Translated by