[R] Column of probabilities
    David Winsemius 
    dwinsemius at comcast.net
       
    Wed Aug 24 23:20:06 CEST 2011
    
    
  
On Aug 24, 2011, at 3:31 PM, Jim Silverton wrote:
> Hi all,
> I have a vector xm say:  xm = c(1,2,3,4,5,5,5,6,6)
>
> I want to return a vector with the corresponding probabilities based  
> on the
> amount of times the numbers occurred. For example, I should get the
> following vector for xm:
> prob.xm = c(1/9, 1/9, 1/9, 1/9, 3/9, 3/9, 3/9, 2/9, 2/9)
?prop.table
Usage (with table)
 > prob.xm <- round( prop.table(table(xm)), digits=3)
 > prob.xm
xm
     1     2     3     4     5     6
0.111 0.111 0.111 0.111 0.333 0.222
-- 
David Winsemius, MD
West Hartford, CT
    
    
More information about the R-help
mailing list