Find values in a table with multiple data types and set them to NA or NaN
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Centauri Jolene
le 10 Avr 2019
Commenté : Centauri Jolene
le 11 Avr 2019
I have a table (which I've called 'T' in this question) that is approx 105 x 10, with columns 2 & 3 containing strings, and all the rest containing numbers.
In columns 5 through 10 (which only contain numbers), I have some values of 999 interspered in the data that I want to set to NA or NaN.
How can I do this?
I've tried:
idx = T{:,5:10} == 999;
T{idx} = NaN;
T(ismissing(T,{999})) = NaN;
T{T==999}=NaN;
T(T{:,5:10}==999,:) = NaN;
Thank you.
0 commentaires
Réponse acceptée
Peter Perkins
le 10 Avr 2019
I think standardizeMissing is the way to go here. It's "straight-forward" to do it explicitly
>> t = table(["a";"b";"c"],[1;999;3],[999;5;999])
t =
3×3 table
Var1 Var2 Var3
____ ____ ____
"a" 1 999
"b" 999 5
"c" 3 999
>> idx = t{:,2:3} == 999
idx =
3×2 logical array
0 1
1 0
0 1
>> t{:,2:3}(idx) = NaN
t =
3×3 table
Var1 Var2 Var3
____ ____ ____
"a" 1 NaN
"b" NaN 5
"c" 3 NaN
but it takes a little thought to get your head around all of what's going on there. Which is why standardizeMissing exists.
>> t = table(["a";"b";"c"],[1;999;3],[999;5;999]);
>> standardizeMissing(t,999)
ans =
3×3 table
Var1 Var2 Var3
____ ____ ____
"a" 1 NaN
"b" NaN 5
"c" 3 NaN
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Tables dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!