[R] remove repeated string in list

Karim Mezhoud kmezhoud at gmail.com
Thu Mar 5 08:38:18 CET 2015


Many Thanks JS
karim

On Thu, Mar 5, 2015 at 4:08 AM, JS Huang <js.huang at protective.com> wrote:

> Hi,
>
>   Here is one for preserving the first strings.  as.numeric in the previous
> posting is not necessary.
>
> > temp
> $set1
> [1] "a" "b" "d" "x"
>
> $set2
> [1] "b" "c" "q" "m"
>
> $set3
> [1] "b" "f" "e" "k" "q" "h"
>
> > sapply(1:length(temp),function(x){c <- list(); for (j in 1:x){c <-
> > c(c,temp[[j]])}; temp[[x]][table(unlist(c))[temp[[x]]]==1]})
> [[1]]
> [1] "a" "b" "d" "x"
>
> [[2]]
> [1] "c" "q" "m"
>
> [[3]]
> [1] "f" "e" "k" "h"
>
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/remove-repeated-string-in-list-tp4704166p4704191.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list