Re: [R] Conversion of column matrix into a vector without duplicates

From: Chuck Cleland <ccleland_at_optonline.net>
Date: Wed 24 Jan 2007 - 13:27:16 GMT

Shubha Vishwanath Karanth wrote:
> Hi R,
>
> I have a matrix A,
>
> A=
>
> [,1] [,2]
>
> [1,] a u
> [2,] b v
> [3,] c x
> [4,] d x
> [5,] e x
>
> I want to put the 2nd column of this matrix in a vector without
> duplicates. i.e., my vector v should be (u, v, x), whose length is 3.
>
> Can anybody help me on this?

> A <- matrix(c("a","b","c","d","e","u","v","x","x","x"), ncol=2)

> A[,2]

[1] "u" "v" "x" "x" "x"

> unique(A[,2])

[1] "u" "v" "x"

> is.vector(unique(A[,2]))

[1] TRUE   You probably could have helped yourself by checking the results of RSiteSearch("duplicate") .

> Thanks in advance
>
> Shubha.
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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.

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

______________________________________________
R-help@stat.math.ethz.ch 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.
Received on Thu Jan 25 00:51:15 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 24 Jan 2007 - 14:00:33 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.