필터 지우기
필터 지우기

Translate code R to Matlab code

조회 수: 1 (최근 30일)
Camilo  Corredor
Camilo Corredor 2015년 8월 17일
댓글: Camilo Corredor 2015년 8월 17일
Hi all,
I have this R code
Data<-aggregate(Vtec, by=list(Time), FUN = "mean" )
I want to translate this code R to Matlab code. This code groups the Vtec associated with the variable Time and averages. I've read the documentation and I found that I can use a function accumarray but I don't know how to use it
Greetings from Colombia

답변 (1개)

Walter Roberson
Walter Roberson 2015년 8월 17일
If you have the Statistics toolbox then consider using a table and grpstats
Otherwise,
[utime, ~, utimeidx] = unique(Time);
meanTime = accumarray(utimeidx, Vtec(:), [], @mean);
output = [utime, meanTime];
I put the two together in one output so that you would be able to tell which Time value was associated with which meanTime.
  댓글 수: 1
Camilo  Corredor
Camilo Corredor 2015년 8월 17일
Thank you! Awesone your answer!

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

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by