Skip to content

Instantly share code, notes, and snippets.

@t-student
Last active October 14, 2015 05:56
Show Gist options
  • Save t-student/763ef2525367a9aca7b7 to your computer and use it in GitHub Desktop.
Save t-student/763ef2525367a9aca7b7 to your computer and use it in GitHub Desktop.
library(reshape2)
# existing data df.tmp like:
# ldl.begin group end.ldl.1 end.ldl.2 end.ldl.3 end.ldl.4
# 1 <=3.4 ctl 0.6923077 0.30769231 0.00000000 0.00000000
# 2 3.4-4.1 ctl 0.2622951 0.49180328 0.21311475 0.03278689
# 3 4.1-4.9 ctl 0.0000000 0.28571429 0.57142857 0.14285714
# convert to long
melt(df.tmp, id.vars=c("ldl.begin", "group"))
# looks like:
# ldl.begin group variable value
# 1 <=3.4 ctl end.ldl.1 0.69230769
# 2 3.4-4.1 ctl end.ldl.1 0.26229508
# 3 4.1-4.9 ctl end.ldl.1 0.00000000
# 4 >4.9 ctl end.ldl.1 0.00000000
# 5 <=3.4 trt end.ldl.1 0.77777778
# etc ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment