Dear Kathie,
See ?unique.

y = c(-1,-1,0,2,2,2,2,4,4,5,5,5,5,5)
unique(y)
[1] -1  0  2  4  5

HTH,

Jorge


On Wed, Oct 8, 2008 at 3:12 PM, kathie <kathryn.lord2000@gmail.com> wrote:

>
> Dear R users,
>
> I'd like to make this data
>
>        rem.y = c(-1,0,2,4,5)
>
> from
>
>        y = c(-1,-1,0,2,2,2,2,4,4,5,5,5,5,5).
>
> That is, I need to remove repeated values.
>
>
> Here is my code, but I don't think it is efficient.  How could I improve
> this?
>
>
> #------------------------------------------------------------------------
> y = c(-1,-1,0,2,2,2,2,4,4,5,5,5,5,5)
> n=length(y)
>
> for (i in 1:n)          # removed same values in y
> {
>        imsi = 0
>        if (i==1) {rem.y = y[i]}
>        else {c = length(rem.y)
>              for (j in 1:c) { if (y[i]==rem.y[j]) imsi=1 }
>              if (imsi==0) rem.y = c(rem.y,y[i])}
> }
>
> rem.y
> #-------------------------------------------------------------------------
>
>
> Any suggestion will be greatly appreciated.
>
> Regards,
>
> Kathryn Lord
> --
> View this message in context:
> http://www.nabble.com/Remove-repeated-values-tp19885503p19885503.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@r-project.org mailing list
> 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]]

