0

I have a dataframe df with X, Y and Z. I would like my Y and Z value to continue in the column X by row. How do I achieve that? Thanks.

dput(df) > 
structure(list(X = c("2", "4", "6", "8", "10"), Y = c("5", "10", 
"15", "20", "25"), Z = c("2", "3", "5", "7", "11")), row.names = c(NA, 
-5L), class = c("tbl_df", "tbl", "data.frame"))


 df>
 X     Y     Z    
 2     5     2    
 4     10    3    
 6     15    5    
 8     20    7    
 10    25    11 

My desired out put is as follow:

 df1 >
 X         
 2       
 4       
 6      
 8       
 10 
 5
 10
 15
 20
 25
 2 
 3
 5
 7
 11
   
kaix
  • 305
  • 3
  • 10

1 Answers1

0

Edit

Well, let's use a for loop then

for(i in 2:ncol(df)){

   newdf <- rbind(as_tibble(df[,1]), as_tibble(df[,i]))

}

FrsLry
  • 348
  • 4
  • 19