duplicates - Delete duplicated records within row in a df in R -


i rid of duplicated records in each row of df:

df <- data.frame(a=c(1,3,5), b =c(1,2,4), c=c(2,3,7))    x1 x2 x3 1  1  1  2 2  3  2  3 3  5  4  7 

i want this:

  x1 x2 x3 1  1 na  2 2  3  2 na 3  5  4  7 

now, can achieve using apply:

data.frame(t(apply(df,1, function(row) ifelse(!duplicated(row), row, na)))) 

but seems unlikely there isn't more compact (and perhaps efficient) way of achieving this.

am missing command or package here?


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -