Gather multiple columns with tidyr [duplicate]
This question already has an answer here: Gather multiple sets of columns [duplicate] 5 answers Reshaping multiple sets of measurement columns (wide format) into single columns (long format) 7 answers I have a shopping cart data, which look like the sample dataframe below: sample_df<-data.frame( clientid=1:10, ProductA=c("chair","table","plate","plate","table","chair","table","plate","chair","chair"), QuantityA=c(1,2,1,1,1,1,2,3,1,2), ProductB=c("table","doll","shoes","","door","","computer","computer","","plate"), QuantityB=c(3,1,2,"",2,"",1,1,"",1) ) #sample data frame clientid ProductA