Shubha Vishwanath Karanth
2007-Jan-24 13:12 UTC
[R] Conversion of column matrix into a vector without duplicates
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? Thanks in advance Shubha. [[alternative HTML version deleted]]
ONKELINX, Thierry
2007-Jan-24 13:24 UTC
[R] Conversion of column matrix into a vector without duplicates
?unique unique(A[, 2]) ------------------------------------------------------------------------ ---- ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 Thierry.Onkelinx op inbo.be www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -----Oorspronkelijk bericht----- Van: r-help-bounces op stat.math.ethz.ch [mailto:r-help-bounces op stat.math.ethz.ch] Namens Shubha Vishwanath Karanth Verzonden: woensdag 24 januari 2007 14:13 Aan: r-help op stat.math.ethz.ch Onderwerp: [R] Conversion of column matrix into a vector without duplicates 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? Thanks in advance Shubha. [[alternative HTML version deleted]] ______________________________________________ R-help op 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.
Dimitris Rizopoulos
2007-Jan-24 13:26 UTC
[R] Conversion of column matrix into a vector without duplicates
you need: unique(A[, 2]) Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm ----- Original Message ----- From: "Shubha Vishwanath Karanth" <shubhak at ambaresearch.com> To: <r-help at stat.math.ethz.ch> Sent: Wednesday, January 24, 2007 2:12 PM Subject: [R] Conversion of column matrix into a vector without duplicates> 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? > > > > Thanks in advance > > Shubha. > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
Chuck Cleland
2007-Jan-24 13:27 UTC
[R] Conversion of column matrix into a vector without duplicates
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 at 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