I am trying to figure out a code that would allow me create a column that counts the number of unique observations each subject in my data set has. These observations would be distinguishable by a study ID and a date. I then want the column to contain a number that is the same number repeated for a given study subject that gives the total observations. For example, columns 1 and 2 below are an example of what I have and Col3 is what I would want to generate:
Col1 | Col2 | Col3 |
Subject1 | 23jan2019 | 2 |
Subject1 | 15sept2018 | 2 |
Subject1 | 3may2017 | 3 |
Subject2 | 2mar2019 | 3 |
Subject2 | 15sept2018 | 3 |
Subject3 | 2jun2019 | 4 |
Subject3 | 2jun2019 | 4 |
Subject3 | 5july2018 | 4 |
Subject3 | 7jan2018 | 4 |
Subject3 | 6oct2017 | 4 |
Subject4 | 7feb2019 | 1 |
Column 3 is what I would want that says how many unique data points that subject has. Because subject 3 has two data points on the same day they only have 4 unique points reflected in col3.
Thank you in advance!
0 Response to creating a count column for unique observations for given study subjects
Post a Comment