# Creating a 3d frequency array for categorical variables from a dataframe

**URL:** https://discourse.julialang.org/t/creating-a-3d-frequency-array-for-categorical-variables-from-a-dataframe/55163
**Category:** New to Julia
**Tags:** dataframes
**Created:** [February 12, 2021, 5:39pm UTC](https://discourse.julialang.org/t/creating-a-3d-frequency-array-for-categorical-variables-from-a-dataframe/55163 "2021-02-12T17:39:45Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)
#### Post date: [February 12, 2021, 10:20pm UTC](https://discourse.julialang.org/t/creating-a-3d-frequency-array-for-categorical-variables-from-a-dataframe/55163/4 "2021-02-12T22:20:31Z")

</div>

Ah yes I see now.

This is is a commonly requested feature in DataFrames. There is no way to index columns for an easy lookup like that.

You can make a `GroupedDataFrame` grouping on `[:a, :b, :c]` and then index like

```julia
gd[(a = 1, b = 2, c = 3)]

```

This will be fast since a `GroupedDataFrame` creates a hash for lookup just like a `Dict`.

However this will return a `SubDataFrame`, which is itself not the nicest object.

I would do the following

```julia
julia> gd = groupby(df_fraction, [:a, :b, :c]);

julia> function get_fraction(gd, ;a = nothing, b = nothing, c = nothing)
           only(gd[(;a, b, c)]).fraction
       end
get_fraction (generic function with 1 method)

julia> get_fraction(gd; a = 1, b = 2, c = 3)
0.018

```

```julia

```

---

_[View the full topic](https://discourse.julialang.org/t/creating-a-3d-frequency-array-for-categorical-variables-from-a-dataframe/55163)._
