Displaying 20 results from an estimated 10000 matches similar to: "Vectorized forms of isTRUE, identical and all.equal?"
2013 May 20
1
Inconsistent results from .C()
Hello,
I've run into a problem which is both maddening and rather hard to
replicate, therefore I wondered if someone might know of a plausible
explanation for it. I couldn't find anything in the archives, though
maybe I'm searching for the wrong thing.
I'm calling some C code using .C, and get the vector I'm interested in
back as the 7th location in the returned list.
2005 Aug 29
5
Testing if all elements are equal in a vector/matrix
Is there a canonical way to check if all elements of a vector or matrix are
the same? Solutions below work, but look hackish to me.
> x <- rep(1, 10)
> all(x == x[1]) # == operator does not provide for small differences
[1] TRUE
> isTRUE(all.equal(x, rep(x[1], length(x)))) # ugly
[1] TRUE
Best,
Vincent
--
Vincent Goulet, Associate Professor
??cole d'actuariat
2011 May 02
1
Location of Internal Code
Hello,
This seems like a fairly elementary question, but I couldn't seem to
find the answer anywhere online.
Where can I find code which is called with .Internal? ?Specifically,
the R function colSums() calls an internal function with the same name
(I presume a C function), and I'd like to see how it works.
I've searched through the header files in R-2.x.x/include/ (Windows
2009 Jun 16
1
Testing if all elements are equal in a vector/matrix
Hi All,
There are several replies to the question below, but I think there must
exist a better way of doing so.
I just want to check whether all the elements of a vector are same. My
vector has one million elements and it is highly likely that there are
distinct elements in the first few itself. For example:
> x = c(1,2,rep(1,100000))
I want the answer as FALSE, which is clear from the
2005 Jun 26
2
is.all.equal
Hi,
The description of all.equal states "is.all.equal should be used for
programming, typically in if expressions. It is a simple wrapper using
identical as shown in the documentation there.", but is.all.equal is
not explicitly defined there (although there is a hint in the comments
that is.all.equal <- function(x,y) isTRUE(all.equal(x,y))).
Could the documentation be corrected? (or
2010 Apr 17
1
Frequency table
Hello,
I'm trying to make a table like windfreq.dat in the rose diagram example of
the climatol package.
It looks like:
N NNE NE ENE E ESE SE SSE S SSW SW WSW W
WNW NW NNW
0-3 59 48 75 90 71 15 10 11 14 20 22
22 24 15 19 33
3-6 3 6 29 42 11 3 4 3 9 50
67 28
2020 Aug 11
2
M[cbind()] <- assignment with Matrix object loses attributes
? Does this constitute a bug, or is there something I'm missing?
assigning sub-elements of a sparse Matrix via M[X]<-..., where X is a
2-column matrix, appears to drop user-assigned attributes. I dug around
in the R code for Matrix trying to find the relevant machinery but my
brain started to hurt too badly ...
?? Will submit this as a bug if it seems warranted.
library(Matrix)
m1
2006 Jan 10
2
Correct way to test for exact dimensions of matrix or array
Dear R Users,
I want to test the dimensions of an incoming vector, matrix or array safely
and succinctly. Specifically I want to check if the unknown object has
exactly 2 dimensions with a specified number of rows and columns.
I thought that the following would work:
> obj=matrix(1,nrow=3,ncol=5)
> identical( dim( obj) , c(3,5) )
[1] FALSE
But it doesn't because c(3,5) is numeric
2005 Jan 05
4
output from table() in matrix form
Hi
How do I get the output from table() in matrix form?
If I have
R> table(c(1,1,1,1,2,20))
1 2 20
4 1 1
I want
[,1] [,2] [,3]
[1,] 1 2 20
[2,] 4 1 1
The problem is that names(table) is a vector of characters and I need
the numeric values.
I am using
R> rbind(as.integer(names(x)),x)
I thought tabulate() might be better as it takes an
2006 Feb 03
2
all.equal() and which()
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
2018 Mar 14
0
Possible Improvement to sapply
>>>>> Henrik Bengtsson <henrik.bengtsson at gmail.com>
>>>>> on Tue, 13 Mar 2018 10:12:55 -0700 writes:
> FYI, in R devel (to become 3.5.0), there's isFALSE() which will cut
> some corners compared to identical():
> > microbenchmark::microbenchmark(identical(FALSE, FALSE), isFALSE(FALSE))
> Unit: nanoseconds
> expr
2007 Sep 03
3
When 1+2 != 3 (PR#9895)
Full_Name: Marco Vicentini, University of Verona
Version: 2.4.1 & 2.5.1
OS: OsX & WinXP
Submission from: (NULL) (157.27.253.46)
When I proceed to test the following equation 1 + 2 == 3, I obviously obtain the
value TRUE. But when I tryed to do the same using real number (i.e. 0.1 + 0.2 ==
0.3) I obtained an unusual FALSE.
In the online help there are some tricks for this problem. It
2009 Oct 10
1
isFALSE
Hello,
Just wondering why there is "isTRUE" and not "isFALSE".
Romain
--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/BcPw : celebrating R commit #50000
|- http://tr.im/ztCu : RGG #158:161: examples of package IDPmisc
`- http://tr.im/yw8E : New R package : sos
-------------- next part --------------
An
2008 Feb 18
2
Number of digits of a value for problem 7.31 RFAQ
Hello dear R users!
I did not find a function which gives information about the number of
digits of a value shown by R.
Do you know one?
I need it to solve the problem (see RFAQ 7.31)that 0.2==0.2+0.1-0.1 FALSE
The solution suggested in RFAQ is to use isTRUE(all.equal(0.2,0.2+0.1-0.1))
But if I want to compare inequality:
0.2<=0.2 +0.1-0.1 TRUE
but 0.2<=0.2 +0.1-0.1 FALSE
bad!
but in
2006 Jan 30
2
'all' inconsistent?
Hello,
I came across the following behavior, which seems illogical to me. I don't
know if it is a bug or if I'm missing something:
> all(logical(0))
[1] TRUE
> any(logical(0))
[1] FALSE
> isTRUE(logical(0))
[1] FALSE
This actually came up in practice when I did something like
> all( names(x) %in% vec )
as an error-handling, and I was hoping that it would work regardless
2018 Aug 31
2
compairing doubles
El vie., 31 ago. 2018 a las 16:00, Mark van der Loo
(<mark.vanderloo at gmail.com>) escribi?:
>
> how about
>
> is_evenly_spaced <- function(x,...) all.equal(diff(sort(x)),...)
This doesn't work, because
1. all.equal does *not* return FALSE. Use of isTRUE or identical(.,
TRUE) is required if you want a boolean.
2. all.equal compares two objects, not elements in a vector.
2013 May 30
2
RFC: a "safe" uniroot() function for future R
With main R releases only happening yearly in spring, now is
good time to consider *and* discuss new features for what we
often call "R-devel" and more officially is
R Under development (unstable) (.....) -- "Unsuffered Consequences"
Here is one such example I hereby expose to public scrutiny:
A few minutes ago, I've committed the following to R-devel
(the
2018 Aug 31
3
compairing doubles
Agreed that's it's rounding error, and all.equal would be the way to go.
I wouldn't call it a bug, it's simply part of working with floating point numbers, any language has the same issue.
And while we're at it, I think the function can be a lot shorter:
.is_continous_evenly_spaced <- function(n){
length(n)>1 && isTRUE(all.equal(n[order(n)], seq(from=min(n),
2020 Jan 10
2
SUGGESTION: Settings to disable forked processing in R, e.g. parallel::mclapply()
I'd like to pick up this thread started on 2019-04-11
(https://hypatia.math.ethz.ch/pipermail/r-devel/2019-April/077632.html).
Modulo all the other suggestions in this thread, would my proposal of
being able to disable forked processing via an option or an
environment variable make sense? I've prototyped a working patch that
works like:
> options(fork.allowed = FALSE)
>
2009 Sep 15
5
identical(length(x), 1) returns FALSE, but print(length(x)) is 1, length(x)==1 is TRUE, and is.integer(lenght(x)) is TRUE????
Dear R,
the condition:
identical(length(x),1) returns FALSE
but
print(length(x))
returns 1 and:
is.vector(x) is TRUE.
is.integer(length(x)) is TRUE
length(x) ==1 is TRUE
I am puzzled.
Regards
--
Corrado Topi
Global Climate Change & Biodiversity Indicators
Area 18,Department of Biology
University of York, York, YO10 5YW, UK
Phone: + 44 (0) 1904 328645, E-mail: ct529 at york.ac.uk