[R] How do I tell whether two vectors are identical?

David Winsemius dwinsemius at comcast.net
Wed Oct 13 00:16:50 CEST 2010


On Oct 12, 2010, at 5:11 PM, Łukasz Ręcławowicz wrote:

> Let's test speed in this way:
>
>> benchmark(isTRUE(all.equal.numeric(x,y)),replications=1e3)
>                                  replications elapsed relative
> user.self sys.self
>                                            1000   34.01        1
> 29.09     0.16
>> benchmark(differences<-compare$id[compare$x!=compare 
>> $y],replications=1e3)
>                                  replications elapsed relative
> user.self sys.self
>                                            1000    4.33        1
>   4        0

You are omitting the most time-costly act which is the creation of the  
"compare" data.frame object. You are also omitting any evaluation of  
"differences". So your comparison is entirely meaningless. The act of  
assignment is _not_ the same as turning the differences object into a  
logical result.


>
> 2010/10/12 David Winsemius <dwinsemius at comcast.net>:
>> The method of embedding in a dataframe is going to be really slow.

And as a result you have chosen not to include the creation of the  
data.frame inside your loop.

>
>
> -- 
> Miłego dnia

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list