Error using matlab.internal.math.checkDataVariables Invalid grouping variables.
이전 댓글 표시
kindly help me solve this issue
load("stormData");
summaryRegionCosts = groupsummary(stormData, "stormData.Region",['min','max','median','mean'] , "stormData.Total_Cost")
stormDataPos = stormData.Total_cost> 0
summaryRegionPosCosts = groupsummary(stormData, "stormData.Region", ['min','max','median','mean'],"stormData.stormDataPos")

댓글 수: 1
Juan Carlos Hernandez
2023년 2월 18일
Hi,
Here is your problem solved:
load("stormData");
summaryRegionCosts=groupsummary(stormData,"Region",["min","median","mean","max"],"Total_Cost")
stormDataPos=stormData(stormData.Total_Cost>=1,:)
summaryRegionPosCosts=groupsummary(stormDataPos,"Region",{"min","median","mean","max"},"Total_Cost")
답변 (1개)
Steven Lord
2022년 8월 20일
0 개 추천
The second input for the groupsummary function as you're calling it should be the name of a variable in your table. "stormData.Region" isn't the name of a variable, it's an expression that would extract a variable in the table. Try using just "Region" in your call instead.
댓글 수: 15
Umair Ejaz
2022년 8월 20일
Umair Ejaz
2022년 8월 20일
Umair Ejaz
2022년 8월 20일
Walter Roberson
2022년 8월 21일
"To specify multiple computations at a time, list the options in a cell array, such as {'mean','median'} or {myFun1,myFun2}."
You did not use a cell array.
Umair Ejaz
2022년 8월 21일
Umair Ejaz
2022년 8월 21일
Simon Chan
2022년 8월 21일
Could you show us what is the output of the following code?
stormData.Properties.VariableNames
Umair Ejaz
2022년 8월 21일
Umair Ejaz
2022년 8월 21일
Walter Roberson
2022년 8월 22일
Do not use a cell array of string objects. Use either a cell array of character vectors or else a string vector.
That is, {'this', 'that'} or ["this", "that"] but not {"this", "that"}
Steven Lord
2022년 8월 22일
Your table doesn't have a variable named Region. For that second input in your call to groupsummary you need to use one of those 13 names in the output above. SuperRegion seems closest to Region.
Walter Roberson
2022년 8월 22일
"Region" is present if you look back to the table output in the original Question.
It does not appear in the list here because the list here truncated, with only 8 variable names visible on the list before the right hand margin, but the column count shows the second line picks up at 12. So 3 variables are missing, and the original table shows that Region is right before SuperRegion.
Umair Ejaz
2022년 8월 22일
Umair Ejaz
2022년 8월 22일
Walter Roberson
2022년 8월 23일
You are attempting to pass in a logical mask stormDatapos as the 4th parameter to groupsummary, with the first parameter being a table
When you use 4 parameters to groupsummary and the first one is a table, the permitted syntaxes are
G = groupsummary(T,GROUPVARS,GROUPBINS,METHOD)
G = groupsummary(T,GROUPVARS,METHOD,DATAVARS)
Your {'min', 'max', 'median', 'mean'} or ["min", "max", "median", "mean"] is not grouping bins, so the first of the two possibilities does not apply.
Your logical vector is not a data variable name within the table, so the second of the two possibilities does not appy.
If you want to summarize only for a subset of a table, you need to construct the subset first and summarize on it. For example,
sdss = stormData(stormDataPos, :);
summaryRegionPostCosts = groupsummary(sdss, "Region", ["min", "max", "median", "mean"])
In practice you will probably need to add a list of variables to apply the summary to, as it is not clear that taking mean() of your categorical SuperRegion is meaningful.
카테고리
도움말 센터 및 File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


