Hi,
I have a table with 3 columns but many rows. Some rows are the same on column 1 and 2 but but not on column 3. Since column 3 are numbers, how to collapse the table with rows that have the same col 1 and col2 and average on col 3?
For example, the table is
Symbol Date Price
NFLX 7/28/2015 100
NFLX 7/28/2015 101
AAPL 7/28/2015 150
I would like to make it as two rows:
NFLX 7/28/2015 105
AAPL 7/28/2015 150
How to do that?
Thanks for any help!
Jennifer

 Respuesta aceptada

Sean de Wolski
Sean de Wolski el 24 de Ag. de 2015
T = table({'NFLX';'NFLX';'AAPL'},datetime([2015;2015;2015],[7;7;7],[28;28;28]),[100;101;150] ,'VariableNames',{'Symbol' 'Date' 'Price'})
% Dates have to be made numeric
T.Date = datenum(T.Date)
% Group fun
varfun(@mean,T,'GroupingVariables',{'Symbol','Date'})

2 comentarios

JFz
JFz el 24 de Ag. de 2015
Thanks! You are so quick! Let me try it.
JFz
JFz el 24 de Ag. de 2015
Sean, Thank you so much! It works like a charm!
Jennifer

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Language Fundamentals en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

JFz
el 24 de Ag. de 2015

Comentada:

JFz
el 24 de Ag. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by