Replacing values in a table
이전 댓글 표시
I have a table created from a database query using T = select(conn,selectquery); Missing database entries for numeric integer types are read as -2147483648 for long integer types (int32) and -32768 (int16) for short integer types. I would like to replace these with NaN throughout the entire table. If I use I=ismissing(T,[-2147483648 -32768]) I returns logical array with all the table indices where there are missing values as 1=true, in other words, this works. However, if I try to use T = standardizeMissing(T,[-32768 -2147483648]) or any variation, the values are not replaced with NaN as the command would suggest should happen.
댓글 수: 3
dpb
2018년 4월 11일
I've yet to fully parse the input description and behavior of ismissing, standardizeMissing and friends, but it appears to me that the standardizeMissing list as shown in all the examples is a "one-at-a-time" operation for each variable type such that in the list of multiple values is not interpreted as two values in the table to substitute but two types with a value each.
See what happens if use
T = standardizeMissing(T,-32768)
T = standardizeMissing(T,-2147483648)
If those work, I'd revert to using isMissing output as the logical addressing vector and just do the assignment.
If they work also I think it's worthy of a support request asking for clarification on syntax and whether are supposed to be able to do in a single step.
Bruce MacWilliams
2018년 4월 11일
dpb
2018년 4월 11일
OK, I see Peter already identified what was going to be my second thought (that didn't come to me until after the posting, I'll admit)
채택된 답변
추가 답변 (1개)
David Fletcher
2018년 4월 11일
tab =
10×2 table
C1 C2
__ ___________
1 -32768
2 9
3 3
4 2
5 1
6 -2.1475e+09
7 7
8 9
9 1
10 2
standardizeMissing(tab,{-32768,-2147483648},'DataVariables',{'C2'})
ans =
10×2 table
C1 C2
__ ___
1 NaN
2 9
3 3
4 2
5 1
6 NaN
7 7
8 9
9 1
10 2
댓글 수: 2
David Fletcher
2018년 4월 11일
See the answer below - these weren't expressly cast to ints so would have been doubles. I still have a nasty habit of typing what I assume is an int and forgetting that Matlab defaults to a double type.
Bruce MacWilliams
2018년 4월 11일
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!