0

I have a dataset of repeated measurements (hb) for patients (record_id) over several days. I have included an example below

record_id Day hb
1 0 122
1 1 90
1 2 71
1 3 71
2 0 139
2 1 130
2 2 119
2 3 106
3 0 89
3 1 126
3 2 127
3 3 110
4 0 90
4 1 86
4 2 82
4 3 78
5 0 118
5 1 108
5 2 95
5 3 94

I wish to find out the minimum value for "hb" for each patient:
#nadir Hb by patient

x1 <- aggregate(hb~record_id, data=df, FUN=function(df) c(min=min(df), count=length(df)))
summary(x1)

Would anyone be kind enough to show me how I could plot a histogram of these minimum values? Thank you very much for your time, Annemarie

Annemarie
  • 123
  • 1
  • 8
  • you can use this library(dplyr); df %>% group_by(record_id) %>% summarise(min = min(hb)) please look at this question that we answered for max http://stackoverflow.com/questions/36620240/find-max-values-of-a-column-in-a-time-series-dataset/36620406#36620406 –  Apr 14 '16 at 11:21
  • Like this?: `hist(tapply(df$hb, df$record_id, min))` – DatamineR Apr 14 '16 at 11:22
  • Brilliant, that is embarrassingly simple! Thank you so much for your help. – Annemarie Apr 14 '16 at 12:22
  • @Annemarie Please provide the whole dataset – DatamineR Apr 14 '16 at 13:08
  • @DatamineR I hadn't put in na.rm=TRUE. It's working well now, thanks – Annemarie Apr 14 '16 at 13:25
  • @Learner Thank you. When I use your code, I can only get the minimum hb for the whole dataset (ie 78), rather than for each record_id. Is there something fundamental I'm doing wrong? Thanks – Annemarie Apr 15 '16 at 12:41

0 Answers0