Splitapply and unique returning nonscalar value in the same table?
古いコメントを表示
Hello Matlab Gods,
I'm new to this so I'm gonna post all my code.
data = mycsvfile;
coled = data(:,'ED');
colicu = data(:,'ICU');
ed_patients = unique(data.mrn(table2array(coled) == 1));
ednonicu = unique(data.mrn(table2array(coled) == 1 & table2array(colicu) == 0));
edicu = unique(data.mrn(table2array(coled) == 1 & table2array(colicu) == 1));
% this works no problem:
demographicvarnames = {'age', 'sex', 'race', 'homeless', 'ethnicity','facility'};
ednonicu_data = data(ismember(data.mrn,ednonicu),:);
ed_nonicu_demographicvarnames = ednonicu_data(:, demographicvarnames);
G = findgroups(ednonicu_data.mrn);
all_summary_ed_nonicu_demographicvarnames = struct();
for i = 1:length(demographicvarnames)
varname = demographicvarnames{:, i};
all_summary_ed_nonicu_demographicvarnames.(varname) = splitapply(@unique, ed_nonicu_demographicvarnames(:,varname), G);
end
%this returns the error
ed_nonicu_baseline = {'Current_Smoker','Former_Smoker','Smoking_packyears','IVDU','History__of_receiving_annual_flu_vaccine','A1c','BMI','Heighty','Ejection_Fraction','PFTs_FEV1FVC_Ratio','CD4_count','Viral_Load','Elevated_LDL','Elevated_Triglycerides','Baseline_LFTs_ALT','Baseline_LFTs_AST','Iron_Level','Total_Iron_Binding_Capacity','Serum_Ferritin','Transferrin_Saturation'};
ednonicu_data = data(ismember(data.mrn,ednonicu),:);
ed_nonicu_baseline_data = ednonicu_data(:, ed_nonicu_baseline);
G = findgroups(ednonicu_data.mrn);
all_summary_ed_nonicu_baseline_data = struct();
for i = 1:length(ed_nonicu_baseline)
varname = ed_nonicu_baseline{:, i};
all_summary_ed_nonicu_baseline_data.(varname) = splitapply(@unique, ed_nonicu_baseline_data(:,varname), G);
end
Error using splitapply (line 132)
The function 'unique' returned a non-scalar value when applied to the 1st group of data.
All of the variables are from the same table. there's a mix of categorical/doubles with <undefined> and nan.
This doesn't seem to bother the first bit. Only the second. I can't see a difference between them.
Please help and lemme know if you need further info!
2 件のコメント
Ameer Hamza
2020 年 6 月 22 日
Can you attach the variables used to run this code?
Flynn McGuire
2020 年 6 月 22 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Whos についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!