Letter to numerb: Create a new 'if' variable to change 'Y' and 'N' to 1 and 0
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I would like to create a new variable and change those 'N's and 'Y's to 0 (N) and 1 (Y).
Does someone know an easy way to solve the problem?
Best regards
Max
0 Kommentare
Antworten (1)
dpb
am 14 Aug. 2022
>> categorical({'Y';'N';'Y'},{'N';'Y'},{'0';'1'})
ans =
3×1 categorical array
1
0
1
>> matches({'Y';'N';'Y'},'Y')
ans =
3×1 logical array
1
0
1
>> categorical(matches({'Y';'N';'Y'},'Y'))
ans =
3×1 categorical array
true
false
true
>>
2 Kommentare
dpb
am 14 Aug. 2022
Bearbeitet: dpb
am 14 Aug. 2022
What does that mean, pray tell? What is "it" and what are you trying to accomplish?
Above is three slightly different approaches to converting a string variable Y/N to a logical one...
BTW, there's no data in the attached spreadsheet that shows anything that appears to be at all related to the question asked...
Siehe auch
Kategorien
Mehr zu Descriptive Statistics finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!