Borrar filtros
Borrar filtros

Letter to numerb: Create a new 'if' variable to change 'Y' and 'N' to 1 and 0

1 visualización (últimos 30 días)
Max
Max el 14 de Ag. de 2022
Editada: dpb el 14 de Ag. de 2022
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

Respuestas (1)

dpb
dpb el 14 de Ag. de 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 comentarios
Max
Max el 14 de Ag. de 2022
I´m not able to use it in my editor..
dpb
dpb el 14 de Ag. de 2022
Editada: dpb el 14 de Ag. de 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...

Iniciar sesión para comentar.

Categorías

Más información sobre Descriptive Statistics en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by