The problem is simple, I have a grouped data frame and I want to throw out groups. filter however, does not work. This seems like a very common idiom, so I’m thinking I’m missing some very simple way to handle it.
p.s. i meant within the DataFrame environment. clearly i can create my own filter function and just push!(a, g) to collect the groups i want.
Thanks,
julia> using DataFrames
x
julia> x=DataFrame([[1,1,2,2,3,3],collect(1:6)],[:a,:b])
6×2 DataFrame
│ Row │ a │ b │
│ │ Int64 │ Int64 │
├─────┼───────┼───────┤
│ 1 │ 1 │ 1 │
│ 2 │ 1 │ 2 │
│ 3 │ 2 │ 3 │
│ 4 │ 2 │ 4 │
│ 5 │ 3 │ 5 │
│ 6 │ 3 │ 6 │
julia> g=groupby(x, :a)
GroupedDataFrame with 3 groups based on key: a
First Group (2 rows): a = 1
│ Row │ a │ b │
│ │ Int64 │ Int64 │
├─────┼───────┼───────┤
│ 1 │ 1 │ 1 │
│ 2 │ 1 │ 2 │
⋮
Last Group (2 rows): a = 3
│ Row │ a │ b │
│ │ Int64 │ Int64 │
├─────┼───────┼───────┤
│ 1 │ 3 │ 5 │
│ 2 │ 3 │ 6 │
julia> filter(y->y[1,:a]==3,g)
ERROR: MethodError: no method matching filter(::getfield(Main, Symbol("##3#4")), ::GroupedDataFrame{DataFrame})
Closest candidates are:
filter(::Any, ::Array{T,1} where T) at array.jl:2351
filter(::Any, ::BitArray) at bitarray.jl:1710
filter(::Any, ::AbstractArray) at array.jl:2312
...
Stacktrace:
[1] top-level scope at none:0