Take the 2-minute tour ×

I have a DataFrame df with a column named "cond". One of the values in this column is "aer". To select all the rows with cond == "aer", this code works:

select(:(cond .== "aer"), df)

But this doesn't

select(:(contains(["aer"],cond)), df)

It fails with the error:

ERROR: all SubDataFrame indices must be > 0 in SubDataFrame at /Users/seanmackesey/.julia/DataFrames/src/dataframe.jl:1007 in sub at /Users/seanmackesey/.julia/DataFrames/src/dataframe.jl:1020 in select at /Users/seanmackesey/.julia/DataFrames/src/dataframe.jl:1031

I looked at the source but fail to understand what's going on here. What are the general limitations on what I can put in expression predicates like this?

share|improve this question

1 Answer 1

I think the problem is that contain isn't a vectorized operation:

julia> contains(["aer"], ["aer", "aer", "abr"])

This probably means that it's not generating valid indices.

In general, the family of expressions that should work in select are those that generate a vector of indices. There are a few broken cases, but I believe the problem in this case is just that the predicate isn't producing useful indices.

share|improve this answer
I think there is an error contain -> contains. Apparently I can not edit your answer because the fix is less than 6 characters. –  ivarne Oct 11 '13 at 13:48
@JohnMylesWhite I see-- is there a simple way to take any expression that would return true/false for each row and wrap it so that it can return a vector of indices? I tried doing @vectorize_2arg Any contains but this did not work. –  Sean Mackesey Oct 11 '13 at 19:03

Your Answer


