grpstats for several variables

조회 수: 7 (최근 30일)
Ongun Palaoglu
Ongun Palaoglu 2019년 9월 8일
댓글: Ongun Palaoglu 2019년 9월 12일
Hello everybody,
i have values for Sodium, creatinine and many more variables for patients. I need to calculate mean median values of them. Should i use everytime mean(ds.Sodium) or is there a easier way to do that ? i ve been trying to use grpstats function i couldnt make it work. if someone would explain me i would be very happy. thank you
  댓글 수: 2
Adam Danz
Adam Danz 2019년 9월 8일
What problems are you having? There are lots of examples in documentation which is the first place to go for help.
Adam Danz
Adam Danz 2019년 9월 9일
Ongun Palaoglu's answer moved here as a comment.
True,
DSSTATS = grpstats(DS,GROUPVARS,WHICHSTATS) .
stat1 = grpstats(ds, {'Sodyum' , 'AST'} , {'mean' , 'median'}) i did this, for my dataset ds, {variables} , {what i want to calculate'means'}

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Danz
Adam Danz 2019년 9월 9일
편집: Adam Danz 2019년 9월 9일
Have a look at the list of statistics that are accepted as character vectors. Note that 'median' is not one of the options.
Instead, you'll need to use a function handle to list 'median' as a stat.
stat1 = grpstats(ds, {'Sodyum', 'AST'} , {'mean', @median});
That fixes any syntax issues. If problesm persist, please describe the problem in detail and share the result of the following line (assuming ds is a table which appears to be the case).
head(ds) % if ds is a table
  댓글 수: 6
Adam Danz
Adam Danz 2019년 9월 11일
Ongun, please spend some time reading through the documentation. I provided a link to the grpstats() function. Often times it help looking at the examples too. Look for an example in the grpstats page that matches your inputs.
In this line
stat1 = grpstats(T, {'Sodyum', 'AST'} , {'mean', @median},'DataVars',{'ALT'})
you are computing the mean and median ALT for each "Sodym" and "AST" group -combination. Those group combinations are the row names in the table output.
Ongun Palaoglu
Ongun Palaoglu 2019년 9월 12일
okay thank you=)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by