How to number rows of a table by group

1 visualización (últimos 30 días)
Thimo Marcin
Thimo Marcin el 17 de Oct. de 2018
Comentada: jonas el 17 de Oct. de 2018
I have a table with 2-3 rows per subject(PATID). Now, I would like to add a column which indicate if it is the first, second or third training of a patient (as shown in the figure). There must be a simple way, but I cant figure it out.
Thanks for your help
  1 comentario
jonas
jonas el 17 de Oct. de 2018
It should be fairly simple. You should upload some data.

Iniciar sesión para comentar.

Respuesta aceptada

jonas
jonas el 17 de Oct. de 2018
Editada: jonas el 17 de Oct. de 2018
Can try something like this:
PATID = [1 1 3 3 3 5 9 9 12]'
T = table(PATID)
out = varfun(@(x)1:length(x),T,'InputVariables','PATID','GroupingVariables','PATID','OutputFormat','cell')
out = [out{:}]'
Just put out in a new column.
  2 comentarios
Thimo Marcin
Thimo Marcin el 17 de Oct. de 2018
Thank you! This worked. Kind regards
jonas
jonas el 17 de Oct. de 2018
My pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by