Skip to content

Instantly share code, notes, and snippets.

@MJacobs1985
Created November 9, 2022 16:10
Show Gist options
  • Save MJacobs1985/ed4c940b91585d4baf6ffb9cdbdd71c1 to your computer and use it in GitHub Desktop.
Save MJacobs1985/ed4c940b91585d4baf6ffb9cdbdd71c1 to your computer and use it in GitHub Desktop.
str(bpi_combined)
bpi_combined2<-bpi_combined
bpi_combined2<-ddply(bpi_combined2,.(Patientnr),.drop=FALSE,transform,baselinechange=value-value[1])
bpi_combined3<-bpi_combined
bpi_combined3<-ddply(bpi_combined3,.(Patientnr),.drop=FALSE,transform,change=value-lag(value))
bpi_combined$bpi_baselinechange<-bpi_combined2$baselinechange
bpi_combined$bpi_change<-bpi_combined3$change
bpi_combined$bpi_baselinechange[bpi_combined$time==0]<-NA
bpi_combined$bpi_change[bpi_combined$time==0]<-NA
str(bpi_combined)
# Check visually if worked
g1<-ggplot(bpi_combined) + geom_bar(aes(as.factor(time), bpi_baselinechange), position = "dodge", stat = "summary", fun.y = "mean") +facet_wrap(~variable,scales = "free") + theme_bw()
g2<-ggplot(bpi_combined) + geom_bar(aes(as.factor(time), bpi_change), position = "dodge", stat = "summary", fun.y = "mean") +facet_wrap(~variable, scales = "free") + theme_bw()
grid.arrange(g1,g2,ncol=2, top="BPI Changes ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment