[R] Is there a quick way to count the number of times each element in a vector appears?

José Rafael Ferrer Paris jr_frrr at yahoo.de
Tue Mar 6 14:23:34 CET 2007


El lun, 05-03-2007 a las 22:16 -0800, Dylan Arena escribió:

> So here is my question in a nutshell:
> Does anyone have ideas for how I might efficiently process a matrix
> like that returned by a call to combinations(n, r, rep=TRUE) to
> determine the number of repetitions of each element in each row of the
> matrix?  If so, I'd love to hear them!
> 
> 

here is an answer in a nutshell:

my.table <- combinations(3,3,rep=TRUE)

## one possibility is 
apply(my.table,1,table)

## or better, in plain 
table(my.table,row(my.table))

look at the help pages of 
?table
?apply
?row

> Thanks very much for your time,
> Dylan Arena
> (Statistics M.S. student)
> 

that took probably one minute of my time... so never mind


-- 
Dipl.-Biol. JR Ferrer Paris
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Laboratorio de Biología de Organismos --- Centro de Ecología
Instituto Venezolano de Investigaciones Científicas (IVIC) 
Apdo. 21827, Caracas 1020-A 
República Bolivariana de Venezuela

Tel: (+58-212) 504-1452
Fax: (+58-212) 504-1088

email: jferrer at ivic.ve
clave-gpg: 2C260A95



More information about the R-help mailing list