How to number rows of a table by group

조회 수: 1 (최근 30일)
Thimo Marcin
Thimo Marcin 2018년 10월 17일
댓글: jonas 2018년 10월 17일
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
jonas
jonas 2018년 10월 17일
It should be fairly simple. You should upload some data.

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

채택된 답변

jonas
jonas 2018년 10월 17일
편집: jonas 2018년 10월 17일
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
Thimo Marcin
Thimo Marcin 2018년 10월 17일
Thank you! This worked. Kind regards
jonas
jonas 2018년 10월 17일
My pleasure!

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by