Re: [R] Another way to count TRUE

2017-06-07 Thread Suharto Anggono Suharto Anggono via R-help
rge memory. On Thu, 8/6/17, Bert Gunter wrote: Subject: Re: [R] Another way to count TRUE Cc: "R-help" Date: Thursday, 8 June, 2017, 1:09 AM Bad idea! In R3.3.3 it doesn't even work: > y1 <- tabulate(x,1) Error in tabulate(x, 1) : 'bin' must be nu

Re: [R] Another way to count TRUE

2017-06-07 Thread Bert Gunter
Bad idea! In R3.3.3 it doesn't even work: > y1 <- tabulate(x,1) Error in tabulate(x, 1) : 'bin' must be numeric or a factor ## This does: > y1 <- tabulate(as.integer(x),1) But it's more inefficient than just using sum(), even discounting the as.integer() conversion: > y1 <- tabulate(as.intege

[R] Another way to count TRUE

2017-06-07 Thread Suharto Anggono Suharto Anggono via R-help
To get the number of TRUE in logical vector 'x', tabulate(x, 1) can be used. Actually, it gives count of 1, but TRUE as integer is 1. Since R 3.4.0, it gives a correct answer, too, when the count is 2^31 or more. __ R-help@r-project.org mailing list --