Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Julia's equivalent of R's which?

Tags:

r

julia

In Rb given a vector x one can find the indices where its elements are TRUE using the which function. E.g. y = 1:100 and which(is.even(y)) should return 2,4,...,100

There are also which.max and which.min which returns the indices of minimum and maximum values respectiely.

What are their equivalents in Julia?

like image 315
xiaodai Avatar asked Jan 05 '18 05:01

xiaodai


2 Answers

The find function does that.

In R:

y = c(1,2,3,4)    
which(y > 2)     

In Julia:

y = [1, 2, 3, 4]    
find(y .> 2)    
like image 82
rsaavedra Avatar answered Oct 10 '22 22:10

rsaavedra


There is no exact equivalent but findall

There is a comparison list of vocabularies for Julia vs R; which is on the list

http://www.johnmyleswhite.com/notebook/2012/04/09/comparing-julia-and-rs-vocabularies/

However, according to the list Julia's find is equivalent to R's which as answered by others.

like image 42
xiaodai Avatar answered Oct 10 '22 21:10

xiaodai