Hi there - I'm looking for a method to append 2 columns of a data frame under a new name and also retain some information from original column headings in a new factor column. For example, starting with the following data frame
df <- data.frame(colA = c("a","a","b","b"),
id_rep1_num = c(1,2,3,4),
id_rep2_num = c(5,6,7,8))
And then combine the 2 columns into single column under a new name and retaining the "rep1" and "rep2" in a new column (ie a brand new column title "rep" that retains the original "1" and "2", so the desired data frame would be
desired <- data.frame(colA = c("a","a","b","b","a","a","b","b"),
rep = c(1,1,1,1,2,2,2,2),
new_name = c(1,2,3,4,5,6,7,8))