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 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!