Message-ID: <1A8C1289955EF649A09086A153E267240BA3DB200B@GBTEDVPEXCMB04.corp.lgc-group.com>
Date: 2017-06-12T13:54:18Z
From: S Ellison
Subject: Keep only those values in a row in a data frame which occur only once.
In-Reply-To: <CAC8=1er_BvCWEFjQ6x-8pEfuGiM7G-hDQ3nQW6ZtuNzE3Uz_9g@mail.gmail.com>
> 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}}