> I have a file data.txt as follows:
> 
> Name_1,A,B,C
> Name_2,E,F
> Name_3,I,J,I,K,L,M
> 
> My query is how can I keep only the unique elements in each row? For
> example: I want the row 3 to be Name_3,I,J,K,L,M
> 
> Please note I don't want the 2nd I to appear.
> 
> How can I do this?
Use unique() on each row and pad with NA?

Example:
uniq10 <- function(x, L=10) {
        u <- unique(x)
        c(u, rep(NA, L-length(u)) )
}

as.data.frame(  t( apply(tmp, 1, uniq10)  )  )

assuming tmp is the name of your initial data frame.

S Ellison




*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to