all.equal() and which()

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

all.equal() and which()

Tom Wright-9
Please excuse the lack of a complete dataset here, if its needed I'll be
happy to provide it.
Can anyone show me how to rewrite this?

Browse[1]> time(data)[24210:24220]
[1] 24.209 24.210 24.211 24.212 24.213 24.214 24.215 24.216 24.217
[10] 24.218 24.219

Browse[1]> which(time(data)==24.211)
numeric(0)

I'm assuming its an eps fault but
which(all.equal(time(data),24.211))

dosnt seem to work

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: all.equal() and which()

Marc Schwartz (via MN)
On Fri, 2006-02-03 at 10:41 -0500, tom wright wrote:

> Please excuse the lack of a complete dataset here, if its needed I'll be
> happy to provide it.
> Can anyone show me how to rewrite this?
>
> Browse[1]> time(data)[24210:24220]
> [1] 24.209 24.210 24.211 24.212 24.213 24.214 24.215 24.216 24.217
> [10] 24.218 24.219
>
> Browse[1]> which(time(data)==24.211)
> numeric(0)
>
> I'm assuming its an eps fault but
> which(all.equal(time(data),24.211))
>
> dosnt seem to work


There might be an easier way, but here is one approach:

> mydat
 [1] 24.209 24.210 24.211 24.212 24.213 24.214 24.215 24.216 24.217
[10] 24.218 24.219

> which(sapply(mydat, function(x) isTRUE(all.equal(24.211, x))))
[1] 3


This uses sapply() to check each element of 'mydat' against the target
value of 24.211.  The use of 'isTRUE(all.equal(...))' returns a boolean
result of either TRUE or FALSE, enabling the use of which() against the
vector returned from sapply():

> sapply(mydat, function(x) isTRUE(all.equal(24.211, x)))
 [1] FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE

See ?all.equal and ?isTRUE for more information.

HTH,

Marc Schwartz

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: all.equal() and which()

Patrick Burns
In reply to this post by Tom Wright-9
How about

which(abs(time(data) - 24.211) < 1e-7)

or the tolerance of your choice.

Patrick Burns
[hidden email]
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")

tom wright wrote:

>Please excuse the lack of a complete dataset here, if its needed I'll be
>happy to provide it.
>Can anyone show me how to rewrite this?
>
>Browse[1]> time(data)[24210:24220]
>[1] 24.209 24.210 24.211 24.212 24.213 24.214 24.215 24.216 24.217
>[10] 24.218 24.219
>
>Browse[1]> which(time(data)==24.211)
>numeric(0)
>
>I'm assuming its an eps fault but
>which(all.equal(time(data),24.211))
>
>dosnt seem to work
>
>______________________________________________
>[hidden email] mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>
>
>  
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: all.equal() and which()

Frank Samuelson-2
In reply to this post by Marc Schwartz (via MN)
I think that this thread demonstrates a useful point:
The more logical and useful output of all.equal(A,B) would be
a vector of TRUEs and FALSEs with a length equal to that of the arguments,
rather than some human readable text string.
If I really want a tolerance I can always do sd/min/max/etc(abs(A-B))
and have it in a useful numeric form.

-Frank


Marc Schwartz (via MN) wrote:

> On Fri, 2006-02-03 at 10:41 -0500, tom wright wrote:
>
>>Please excuse the lack of a complete dataset here, if its needed I'll be
>>happy to provide it.
>>Can anyone show me how to rewrite this?
>>
>>Browse[1]> time(data)[24210:24220]
>>[1] 24.209 24.210 24.211 24.212 24.213 24.214 24.215 24.216 24.217
>>[10] 24.218 24.219
>>
>>Browse[1]> which(time(data)==24.211)
>>numeric(0)
>>
>>I'm assuming its an eps fault but
>>which(all.equal(time(data),24.211))
>>
>>dosnt seem to work
>
>
>
> There might be an easier way, but here is one approach:
>
>
>>mydat
>
>  [1] 24.209 24.210 24.211 24.212 24.213 24.214 24.215 24.216 24.217
> [10] 24.218 24.219
>
>
>>which(sapply(mydat, function(x) isTRUE(all.equal(24.211, x))))
>
> [1] 3
>
>
> This uses sapply() to check each element of 'mydat' against the target
> value of 24.211.  The use of 'isTRUE(all.equal(...))' returns a boolean
> result of either TRUE or FALSE, enabling the use of which() against the
> vector returned from sapply():
>
>
>>sapply(mydat, function(x) isTRUE(all.equal(24.211, x)))
>
>  [1] FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
>
> See ?all.equal and ?isTRUE for more information.
>
> HTH,
>
> Marc Schwartz
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html