I have a data frame with 500 observations, but I am only showing 3 in my example. These are duplicates with different values in different columns (except ID column, which includes which person is duplicated). I am replicating how the data frame is (df) and how it should look like after treatment (df_new). Is this possible ? The data frame is 10 variables, so I am not worried about 'doubling' them. The values in the variables are a,b,c,d,0,''. I however kept them more general in the tables.
df <- data.frame(ID = c('1','1','2', '2', '3','3'),
Year = c('smaller year.1', 'bigger year.1', 'bigger year.2', 'smaller year.2', 'same year.3', 'same year.3'),
V1 = c('a', 'b','c','d','e','f'),
V2 = c('g', 'h', 'i', 'j', 'k', 'l'),
Vn = c('n1', 'n2','n3','n4','n5','n6'))
df_new <- data.frame(ID = c('1','2','3'),
Year_smaller = c('smaller year.1', 'smaller year.2', 'same year.3'),
Year_bigger = c('bigger year.1', 'bigger year.2', 'same year.3'),
V1 = c('a','c','e'),
V1.1 = c('b','d','f'),
V2 = c('g','i','k'),
V2.1 = c('h','j','l'),
Vn = c('n1','n3','n5'),
Vn.1 = c('n2','n4','n6'))