I have a repeated measures data-set that I am working on. The data look like this:
ID=c('X1', 'X1', 'X1', 'X1', 'X2', 'X2', 'X2', 'X3', 'X3', 'X3', 'X3', 'X4', 'X4', 'X4', 'X4', 'X5', 'X5', 'X5', 'X6', 'X6', 'X6', 'X6')
Diag=c('Con', 'Con', 'Con', 'Con', 'Con', 'Con', 'Con', 'AD', 'AD', 'AD', 'AD', 'AD', 'AD', 'AD', 'AD', 'FD', 'FD', 'FD', 'FD', 'FD','FD', 'FD')
Score=c(10, 9, 8, 8, 10, 9, 9, 5, 4, 3, 3, 5, 4, 3, 2, 5, 4, 3, 6, 5, 4, 3)
Time=c(1, 2, 3, 4, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 1, 2, 3, 4)
dat <- data.frame(ID, Time, Diag, Score)
where ID= participant ID, diag=diagnosis, time=repeat assessment, score=score
I want to calculate the z-scores for AD and FD group scores, in relation to 'Con' group scores (the control group) and as per 'Time'. For eg., z-scores for AD and FD groups at Time 2 should be computed in relation to control groups at Time 2 (ignoring for missing variables)
The only way I can think of is splitting the data frame into different 'Times', calculating z-scores and merging the data-frame together but this is quite painful and time-taking (and is giving me NAs sometimes when I attempted to merge the data frame).
Is there a better way of doing this?