Hi everyone, I want to compare if elements of vector x
are in elements of vector y
.
In R, I can do this as follows:
> x <- c("a", "b", "c")
> y <- c("b", "a")
> x %in% y
[1] TRUE TRUE FALSE
In Julia, I can do this as follows:
julia> x = ["a", "b", "c"];
julia> y = ["b", "c"];
julia> in.(x, Ref(y))
3-element BitArray{1}:
false
true
true
Now let’s make the vector big:
In R,
> set.seed(123)
> x <- rnorm(100000, 1000, 2)
> y <- rnorm(100000, 1000, 2)
> system.time(x %in% y)
user system elapsed
0.009 0.005 0.015
In Julia,
julia> using Distributions
julia> using Random
julia> Random.seed!(123);
julia> x = rand(Normal(1000, 2), 100_000);
julia> y = rand(Normal(1000, 2), 100_000);
julia> @time in.(x, Ref(y));
5.612967 seconds (10 allocations: 16.813 KiB)
I’m not sure if I missed something. Here’s the version info of my Julia and R
julia> versioninfo()
Julia Version 1.1.0
Commit 80516ca202 (2019-01-21 21:24 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin14.5.0)
CPU: Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
Environment:
JULIA = /Applications/Julia-1.0.app/Contents/Resources/julia/bin/julia
and R
> version
_
platform x86_64-apple-darwin15.6.0
arch x86_64
os darwin15.6.0
system x86_64, darwin15.6.0
status
major 3
minor 5.3
year 2019
month 03
day 11
svn rev 76217
language R
version.string R version 3.5.3 (2019-03-11)
nickname Great Truth
Thanks.