I am very new to R and am having a hard time figuring out 1) how to get my data frame to show up in this thing, 2) how to add leading _0s of varying lengths to subject IDs. I have data that looks something like this
id = c(1, 2, 3, 11, 12, 13, 110, 120, 130)
sex = c(1, 2, 2, 1, 2, 1, 1, 2, 2)
age = c(12, 13, 10, 9, 14, 12, 10, 9, 11)
df = data.frame(id, sex, age)
df
I would like to add leading _0s so that each of the IDs are 3 numbers long. For example, 1 becomes _001, 11 becomes _011 and _110 stays as is.
Any suggestions?? And thanks for your patience...