[R] Create column of frequency

Chuck Cleland ccleland at optonline.net
Tue Sep 29 12:48:05 CEST 2009


On 9/29/2009 6:06 AM, abdul kudus wrote:
> Dear all,
> 
> Given mypi
> mypi <- c(0.1,0.2,0.2,0.1,0.3,0.4,0.4,0.4,0.4,0.2)
> 
> I want to create myfreq as follows
> 
> mypi myfreq
> 0.1 2
> 0.2 3
> 0.2 3
> 0.1 2
> 0.3 1
> 0.4 4
> 0.4 4
> 0.4 4
> 0.4 4
> 0.2 3
> 
> where myfreq is frequency of its corresponding observation.  How to do that?

mypi <- c(0.1,0.2,0.2,0.1,0.3,0.4,0.4,0.4,0.4,0.2)

ave(mypi, mypi, FUN=length)
 [1] 2 3 3 2 1 4 4 4 4 3

?ave

> Thank you,
> 
> Regards,
> 
> A. Kudus
> Institute for Math Research
> Univ Putra Malaysia
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at 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. 

-- 
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
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




More information about the R-help mailing list