I have the following df, which was obtained from a excel file:
df1 <- data.frame( Colour = c("Green","Red","Blue"),
Code = c("N","U", "U"),
User1 = c("John","Brad","Peter"),
User2 = c("Meg","Meg","John"),
User3= c("", "Lucy", ""))
I need to rearrange it in order to obtain a data frame where all names are listed in the first column (only once) and the colors (and respective codes) appear in the following columns, as shown:
df2 <- data.frame(User=c("John","Brad","Peter","Meg","Lucy"),
Color1 = c("Green","Red","Blue","Green","Red"),
Code1 = c("N","U","U","N","U"),
Color2=c("Blue","","","Red",""),
Code2=c("U","","","U",""))
I´d appreciate some help. Many thanks,