I have data frame contain around 900 columns and I want to combine the content of every 3 columns in one column I tried to do a loop but I'm not good at it, can you please help me?
the data frame look like this :
df_out <- data.frame(
"name" = c("1", "2", "3", "4", "5", "6", "7", "8"),
"col1"=rep("B",times= 8),
"col2"=rep("A",times= 8),
"col3"=rep("G",times= 8),
"col4"=rep("C",times= 8),
"col5"=rep("C",times=8),
"col6"=rep("B",times= 8),
"col7"=rep("A",times= 8),
"col8"=rep("G",times= 8),
"col9"=rep("C",times= 8),
"col10"=rep("C",times=8),
"col11"=rep("B",times= 8),
"col12"=rep("A",times= 8),
"col13"=rep("G",times= 8),
"col14"=rep("C",times= 8),
"col15"=rep("C",times=8)
)
df_out
So the final results should be like this:
df_out2 <- data.frame(
"name" = c("1", "2", "3", "4", "5", "6", "7", "8"),
"col1"=rep("BAG",times= 8),
"col2"=rep("CCB",times= 8),
"col3"=rep("AGC",times= 8),
"col4"=rep("CBA",times= 8),
"col5"=rep("GCC",times=8))
df_out2
Any help is appreciated. Also, Can you please recommend any book or good website to learn loops in R? Thank you