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 Center および File ExchangeLogical についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by