standardizeMissing not working on all table columns

2 ビュー (過去 30 日間)
Centauri Jolene
Centauri Jolene 2019 年 4 月 29 日
コメント済み: Centauri Jolene 2019 年 5 月 8 日
I have a table which contains some columns of numbers, some columns of cells which contain multiple numbers, and some columns of strings.
I've attached a .mat file with a section of this table.
I've set certain values to 999, which I later want to change to NaN using the function 'standardizeMissing'. However, this function appears to work for all columsn except for one (column 15, called 'sheepCOM_transport').
This column appears to be a cell containing either 999 or an array of two values.
How can I replace the values of 999 with NaN in this column? Can standardizeMissing work with this column?
I've tried:
T = standardizeMissing(T.sheepCOM_transport, {999});
and
Tc = T.sheepCOM_transport;
Tc = cell2table(Tc);
Tc = standardizeMissing(Tc, 999);
T.sheepCOM_transport = Tc;
But these solutions dont seem to work.

採用された回答

Peter Perkins
Peter Perkins 2019 年 5 月 3 日
standardizeMissing isn't designed to dig into arbitrary cell arrays. If "valid" values in that cell array are always two-element row vectors, then I'm gonna suggest that you turn those cell arrays into two-column matrices. I think in the long run you'll be happier.
>> c = {1:2; 999; 3:4; 999}
c =
4×1 cell array
{1×2 double}
{[ 999]}
{1×2 double}
{[ 999]}
>> missing = cellfun(@(x) isequal(x,999),c)
missing =
4×1 logical array
0
1
0
1
>> c(missing) = {[NaN NaN]}
c =
4×1 cell array
{1×2 double}
{1×2 double}
{1×2 double}
{1×2 double}
>> c = vertcat(c{:})
c =
1 2
NaN NaN
3 4
NaN NaN
OTOH, if the entries can be vectors of different sizes, then you are right to stick with a cell array.
  1 件のコメント
Centauri Jolene
Centauri Jolene 2019 年 5 月 8 日
This is a better answer, since it results in a data format that is easier to work with in the long run. Thank you Peter.

サインインしてコメントする。

その他の回答 (1 件)

KSSV
KSSV 2019 年 4 月 29 日
L = cellfun(@length,T.sheepCOM_transport) ;
T.sheepCOM_transport(L==1) = {NaN} ;

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by