I have a huge dataset ( > 2.5 Million). A small subset looks like this (code reproducible)
temp <- data.frame(list(col1 = c("424", "560", "557"),
col2 = c("276", "427", "V46"),
col3 = c("780", "V45", "584"),
col4 = c("276", "V45", "995"),
col5 = c("428", "799", "427")))
> temp
col1 col2 col3 col4 col5
1 424 276 780 276 428
2 560 427 V45 V45 799
3 557 V46 584 995 427
I am trying to remove duplicates per row, and shifting values left, using this code
library(plyr)
temp <- apply(temp,1,function(x) unique(unlist(x)))
temp <- ldply(temp, rbind)
> temp
1 2 3 4 5
1 424 276 780 428 <NA>
2 560 427 V45 799 <NA>
3 557 V46 584 995 427
I am successfull in doing this, however when I extend the above code to my original huge dataset, I am facing performance issues.
because I am using apply, the code takes lot of time to execute
Can I improve this?