Want to write a Mapper that takes numeric data and will provide column sum for each column and row sum for each individual row through mapper and reduce, below is the code that gives column sum for each cloumn and I want code for row sum

1 view (last 30 days)
I am getting error for row sum for each data series which in turn takes place through addition of all columns of that data series. Please look at below given code and help me.
ds = datastore('C:\Users\Rahul Joshi\Desktop\MedicalReportsdatabase1.csv', 'TreatAsMissing', 'NA'); ds.SelectedVariableNames = {'ID','BLOODGLUCOSEFASTING','BLOODGLUCOSEPP','CHOLESTROL','TRIGLYCERIDES'}; preview(ds); subset = [];
while hasdata(ds) t = read(ds); end result = mapreduce(ds, @R4Mapper, @R4Reducer); readall(result);
function R4Mapper (data, ~, intermValsIter) [ID, ~, ~] = unique(data.ID, 'stable');
for i = 1:numel(ID) maxID = sum(data{ID,:}); %% when I use maxID = sum(data{:,:}); I am getting sum of five columns but when I used above code it throws error Row index exceeds table dimensions.
Error in mapreduce (line 98) outds = execMapReduce(mrcer, ds, mapfun, reducefun, parsedStruct);
Error in R4 (line 12) result = mapreduce(ds, @R4Mapper, @R4Reducer); ------- function R4Reducer(~, intermValsIter, outKVStore) maxID = 0; while hasnext(intermValsIter) maxID = max(maxID, getnext(intermValsIter)); end add(outKVStore, 'ID', maxID); end Please help
add(intermValsIter,'ID',maxID); end

Answers (0)

Community Treasure Hunt

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

Start Hunting!