Displaying 6 results from an estimated 6 matches for "counttrue".
Did you mean:
construe
2018 Jan 25
2
sum() returns NA on a long *logical* vector when nb of TRUE values exceeds 2^31
...cond this feature request (it's understandable that this and
> possibly other parts of the code was left behind / forgotten after the
> introduction of long vector).
>
> I think mean() avoids full copies, so in the meanwhile, you can work
> around this limitation using:
>
> countTRUE <- function(x, na.rm = FALSE) {
> nx <- length(x)
> if (nx < .Machine$integer.max) return(sum(x, na.rm = na.rm))
> nx * mean(x, na.rm = na.rm)
> }
>
> (not sure if one needs to worry about rounding errors, i.e. where n %% 0 != 0)
>
> x <- rep(TRUE, times =...
2017 Jun 02
0
sum() returns NA on a long *logical* vector when nb of TRUE values exceeds 2^31
I second this feature request (it's understandable that this and
possibly other parts of the code was left behind / forgotten after the
introduction of long vector).
I think mean() avoids full copies, so in the meanwhile, you can work
around this limitation using:
countTRUE <- function(x, na.rm = FALSE) {
nx <- length(x)
if (nx < .Machine$integer.max) return(sum(x, na.rm = na.rm))
nx * mean(x, na.rm = na.rm)
}
(not sure if one needs to worry about rounding errors, i.e. where n %% 0 != 0)
x <- rep(TRUE, times = .Machine$integer.max+1)
object.size(x)...
2017 Jun 02
4
sum() returns NA on a long *logical* vector when nb of TRUE values exceeds 2^31
Hi,
I have a long numeric vector 'xx' and I want to use sum() to count
the number of elements that satisfy some criteria like non-zero
values or values lower than a certain threshold etc...
The problem is: sum() returns an NA (with a warning) if the count
is greater than 2^31. For example:
> xx <- runif(3e9)
> sum(xx < 0.9)
[1] NA
Warning message:
In sum(xx
2018 Jan 30
2
sum() returns NA on a long *logical* vector when nb of TRUE values exceeds 2^31
...parts of the code was left behind / forgotten after the
> >> introduction of long vector).
> >>
> >> I think mean() avoids full copies, so in the meanwhile, you can work
> >> around this limitation using:
> >>
> >> countTRUE <- function(x, na.rm = FALSE) {
> >> nx <- length(x)
> >> if (nx < .Machine$integer.max) return(sum(x, na.rm = na.rm))
> >> nx * mean(x, na.rm = na.rm)
> >> }
> >>
> >> (not sure if one needs to worry about...
2018 Jan 27
0
sum() returns NA on a long *logical* vector when nb of TRUE values exceeds 2^31
...is and
>> possibly other parts of the code was left behind / forgotten after the
>> introduction of long vector).
>>
>> I think mean() avoids full copies, so in the meanwhile, you can work
>> around this limitation using:
>>
>> countTRUE <- function(x, na.rm = FALSE) {
>> nx <- length(x)
>> if (nx < .Machine$integer.max) return(sum(x, na.rm = na.rm))
>> nx * mean(x, na.rm = na.rm)
>> }
>>
>> (not sure if one needs to worry about rounding errors, i.e. where n %% 0...
2018 Feb 01
0
sum() returns NA on a long *logical* vector when nb of TRUE values exceeds 2^31
...was left behind / forgotten after the
>> >> introduction of long vector).
>> >>
>> >> I think mean() avoids full copies, so in the meanwhile, you can work
>> >> around this limitation using:
>> >>
>> >> countTRUE <- function(x, na.rm = FALSE) {
>> >> nx <- length(x)
>> >> if (nx < .Machine$integer.max) return(sum(x, na.rm = na.rm))
>> >> nx * mean(x, na.rm = na.rm)
>> >> }
>> >>
>> >> (not sure if one ne...