I want view the variables of interest (height,weight and BP) according to their visits in a horizontal manner.
This is the original dataset:
attempt = data.frame( ID = c(rep("S1",3),rep("S2",3)),
visit = rep(seq(1:3),2),
height = c(154,155,156,150,152,158),
weight = c(54,56,57,60,62,70),
BP = c(140,120,160,170,180,190))
original data
I tried the reshape command below but the output looks strange.
data2 <- reshape(attempt, timevar="visit", idvar="ID", direction="wide")
after reshape command
Any ideas on why my output does not show? Thanks
My desired output for the column heading is:
ID height.1 height.2 height.3 weight.1 weight.2 weight.3 BP.1 BP.2 BP.3
I want each ID's height, weight and BP to be sorted based on their visits in horizontal columns.