I have data with ID and multiple columns. I want to convert this data into a long type. And I want to remove duplicates. I want to apply his process on data with 1 Million rows is there any efficient method?
            Asked
            
        
        
            Active
            
        
            Viewed 3,176 times
        
    -2
            
            
        - 
                    1Have you looked at https://stackoverflow.com/questions/2185252/reshaping-data-frame-from-wide-to-long-format? – Peter Apr 15 '20 at 07:28
- 
                    1Please don't add images of the data, add a reproducible example using `dput`. Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269). – Ronak Shah Apr 15 '20 at 07:43
2 Answers
1
            You cna use reshape2::melt (or the enhanced melt method on data.table objects):
reshape2::melt(df, id.vars = "cust_id")
You can also use tidyr::pivot_longer:
library(dplyr)
library(tidyr)
df %>%
 pivot_longer(-cust_id)
 
    
    
        linog
        
- 5,786
- 3
- 14
- 28
1
            
            
        melt(dataframe, measure.vars = c("trans","Alt1","Alt2"), variable.name = "variable_names" , value.name = "value")
 
    
    
        ps_st
        
- 33
- 6


