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.
댓글 수: 0
채택된 답변
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 Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!