Turning categories into double

3 ビュー (過去 30 日間)
Nona
Nona 2021 年 11 月 3 日
コメント済み: Nona 2021 年 11 月 3 日
Hi,
I have a table with categorical type variables. The categories are all numeric though and I would like to turn them into such to be able to perform calculations on them. When I use the function "double", it does turn the categories into numeric values but changes the name of the category and instead numbers the categories consecutively (1,2,3,4,5 etc.). Is it possible to turn the category names into numeric type?
The type is category because it is a questionnaire for which the answers were written in different ways. So to not loose any data during the import, I imported everything as categories, cleaned the data and now want to use them as numbers again.
Any help is appreciated! :)

採用された回答

Scott MacKenzie
Scott MacKenzie 2021 年 11 月 3 日
Let's assume T.Var1 is a categorical column in your table, as you describe it. To convert this to a column of double values, retaining their values, use
T.Var1 = str2double(string(T.Var1));
  1 件のコメント
Nona
Nona 2021 年 11 月 3 日
Thanks!

サインインしてコメントする。

その他の回答 (1 件)

Chunru
Chunru 2021 年 11 月 3 日
x = categorical([1 1 2 4 4 7 7])
x = 1×7 categorical array
1 1 2 4 4 7 7
double(x)
ans = 1×7
1 1 2 3 3 4 4
double(string(x))
ans = 1×7
1 1 2 4 4 7 7

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by