Re: [R] which() vs. just logical selection in df

2020-10-14 Thread 1/k^c
Hi Bert, Thank you very much! I was unaware that .Internal() referred to C code. I figured out the difference. which() dimensions the object returned to be only the relevant records first. Logical indexing dimensions last. > length(index1<-dat$gender2=="other") [1] 200 > length(index2<-which

Re: [R] which() vs. just logical selection in df

2020-10-14 Thread Bert Gunter
Inline. Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Wed, Oct 14, 2020 at 3:23 PM 1/k^c wrote: Is which() invoking c-level code by chance, making it slight

Re: [R] which() vs. just logical selection in df

2020-10-14 Thread 1/k^c
From: Greg Snow <538...@gmail.com> > To: "1/k^c" > Cc: r-help > Subject: Re: [R] which() vs. just logical selection in df > Message-ID: > > Content-Type: text/plain; charset="utf-8" > > I would suggest using the microbenchmark package t

Re: [R] which() vs. just logical selection in df

2020-10-12 Thread Greg Snow
I would suggest using the microbenchmark package to do the time comparison. This will run each a bunch of times for a more meaningful comparison. One possible reason for the difference is the number of missing values in your data (along with the number of columns). Consider the difference in the

[R] which() vs. just logical selection in df

2020-10-10 Thread 1/k^c
Hi R-helpers, Does anyone know why adding which() makes the select call more efficient than just using logical selection in a dataframe? Doesn't which() technically add another conversion/function call on top of the logical selection? Here is a reproducible example with a slight difference in timi