[R] unique columns of a matrix

John Fox jfox at mcmaster.ca
Tue Dec 19 03:49:43 CET 2006


Dear Roman,

You can use unique(X, MARGIN=2). See ?unique for details.

I hope this helps,
 John

--------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
-------------------------------- 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Roman 
> Akhter Ahmed
> Sent: Monday, December 18, 2006 8:42 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] unique columns of a matrix
> 
> Dear all,
> 
> I have a matrix of repeating columns in R, for example a matrix X is
> 
>           [,1]   [,2]   [,3]   [,4]
> [1,]       1      1      1      1
> [2,]       1      1      2      2
> 
> I want to store unique columns of the matrix X in a new matrix Y. 
> Therefore, Y will be
> 
>           [,1]   [,2]  
> [1,]       1      1    
> [2,]       1      2
> 
> It will be really appreciated if you can provide me some 
> function for this job.
> Thanks for your time and effort in advance, Roman
> 
> --
> ----------------------------------------------------------------------
> Roman Akhter Ahmed (Ph.D. Candidate)
> Department of Econometrics and Business Statistics Room 659, 
> Building 11 (East Wing), Clayton Campus Monash University, 
> Victoria 3800, Australia
> Ph.: +61 3 9905 8346 (W), +61 3 9543 1958 (R)
> Web: http://www.buseco.monash.edu.au/staff/profile.php?uid=rahmed
> ----------------------------------------------------------------------
> 
>



More information about the R-help mailing list