[R] Vectorial analogue of all.equal()?

2012-09-01 Thread Ted Harding
Greetings All. Once again, I am probably missing something fairly accessible, but since I can't find it I'd welcome advice! I have a dataframe derived from a text file of data in tabular format. For one of the variables, say X, I want to select the subsets which in which X equals a particular

Re: [R] Vectorial analogue of all.equal()?

2012-09-01 Thread Rui Barradas
Hello, Like this? equals - function(x, y, tol = .Machine$double.eps^0.5) abs(x - y) tol x - rnorm(5) y - x[2] equals(x, y) [1] FALSE TRUE FALSE FALSE FALSE y - rnorm(3) y[2] - x[2] equals(x, y) [1] FALSE TRUE FALSE FALSE FALSE Warning message: In x - y : longer object length is not a

Re: [R] Vectorial analogue of all.equal()?

2012-09-01 Thread Ted Harding
Thanks, Rui, but that was not my (apparently implicit) question. Apologies if my wording gave the wrong impression. I was really asking if such a function was already available somewhere in R. Yes, your definition of equals() is one possibility; or, with the work-round I was using, equals -

Re: [R] Vectorial analogue of all.equal()?

2012-09-01 Thread Rui Barradas
Hello, The two approaches are conceptually different. With yours we get equality given a certain number of (significant) digits, which might be what you are looking for if the measurements are known to be made with those digits, a frequent case. And there's also Bert's Vectorize way, with

Re: [R] Vectorial analogue of all.equal()?

2012-09-01 Thread Bert Gunter
Yes, Rui's suggestion is what I would do, too. However, for fun, here is a different, way less efficient, but perhaps instructive (or amusing?) alternative using Vectorize() and all.equal() directly: foo - function(target,current,...)isTRUE(all.equal(target,current,...)) equals -

Re: [R] Vectorial analogue of all.equal()?

2012-09-01 Thread Bert Gunter
Hi Rui: Good points. However, as my offering is, I think, little more than a disguised loop -- as compared to yours' and Ted's truly vectorized solutions --I think it is far too inefficient to useful. I offered it merely for its aesthetic interest, which is what you noted in your comments below.