Skip to content

getting the unique values and counts from a vector

3 messages · Ravi.Vishnu@outokumpu.com, Ravi Varadhan, Dimitris Rizopoulos

#
Hi,
"table" should do it.
x
1 2 4 
5 3 2 

--------------------------------------------------------------------------
Ravi Varadhan, Ph.D.
Assistant Professor,  The Center on Aging and Health
Division of Geriatric Medicine and Gerontology
Johns Hopkins University
Ph: (410) 502-2619
Fax: (410) 614-9625
Email:  rvaradhan at jhmi.edu
--------------------------------------------------------------------------
#
you could use table(), i.e.,

x <- c(2, 1, 2, 1, 4, 2, 1, 4, 1, 1)
#######
tab <- table(x)
xu <- as.numeric(names(tab))
xn <- as.vector(tab)
xu; xn

I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
     http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm


----- Original Message ----- 
From: <Ravi.Vishnu at outokumpu.com>
To: <r-help at stat.math.ethz.ch>
Sent: Friday, May 20, 2005 4:48 PM
Subject: [R] getting the unique values and counts from a vector