Find values in a table with multiple data types and set them to NA or NaN

1 次查看(过去 30 天)
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.

采纳的回答

Peter Perkins
Peter Perkins 2019-4-10
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

标签

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by