From: Laetitia Marisa <Laetitia.Marisa_at_cgm.cnrs-gif.fr>

Date: Wed 25 Jan 2006 - 05:30:42 EST

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Jan 25 06:54:06 2006

Date: Wed 25 Jan 2006 - 05:30:42 EST

It is great! It takes now less than 1 second (with the table function
(0.34'), 2 sec with the ave function (1.91') ) with my "big" data and
only two lines of code ;).

Thanks a lot every one.

Regards,

Laetitia.

>Laetitia Marisa <Laetitia.Marisa@cgm.cnrs-gif.fr> writes:

*>
**>
**>
**>>Hello,
**>>
**>>Is there a simple and fast function that returns a vector of the number
**>>of replications for each object of a vector ?
**>>For example :
**>>I have a vector of IDs :
**>>ids <- c( "ID1", "ID2", "ID2", "ID3", "ID3","ID3", "ID5")
**>>
**>> I want the function returns the following vector where each term is the
**>>number of replicates for the given id :
**>>c( 1, 2, 2, 3,3,3,1 )
**>>
**>>Of course I have a vector of more than 40 000 ID and the function I
**>>wrote (it orders my data and checks on ID:Name of the data if the next
**>>term is the same as the previous one (see below) ) is really slow
**>>(30minutes for 44290 terms). But I don't have time by now to write a C
**>>function.
**>>Thanks a lot for your help,
**>>
**>>
**>
**>Will this do it?
**>
**>
**>
**>>table(ids)[ids]
**>>
**>>
**>ids
**>ID1 ID2 ID2 ID3 ID3 ID3 ID5
**> 1 2 2 3 3 3 1
**>
**>Or (could be faster):
**>
**>
**>
**>>f <- factor(ids,levels=unique(ids))
**>>as.vector(table(f))[f]
**>>
**>>
**>[1] 1 2 2 3 3 3 1
**>
**>
**>
**>
*

[[alternative HTML version deleted]]

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Jan 25 06:54:06 2006

*
This archive was generated by hypermail 2.1.8
: Wed 25 Jan 2006 - 08:13:55 EST
*