I have a complicated data structure and I would like to create a monthly dataset. The following code is how to construct columns. It is an ugly form. What kind of strategy can be used to simplify the code?
df2$emp_01 = df$month1_emplvl[which(df$qtr == 1)]
df2$emp_02 = df$month2_emplvl[which(df$qtr == 1)]
df2$emp_03 = df$month3_emplvl[which(df$qtr == 1)]
df2$emp_04 = df$month1_emplvl[which(df$qtr == 2)]
df2$emp_05 = df$month2_emplvl[which(df$qtr == 2)]
df2$emp_06 = df$month3_emplvl[which(df$qtr == 2)]
df2$emp_07 = df$month1_emplvl[which(df$qtr == 3)]
df2$emp_08 = df$month2_emplvl[which(df$qtr == 3)]
df2$emp_09 = df$month3_emplvl[which(df$qtr == 3)]
df2$emp_10 = df$month1_emplvl[which(df$qtr == 4)]
df2$emp_11 = df$month2_emplvl[which(df$qtr == 4)]
df2$emp_12 = df$month3_emplvl[which(df$qtr == 4)]
dput(head(df2)). That will show us your columns. I assume that you have a collection df1, df2, df3...? Do they all have the same columns?