# Agents.jl: subset object returned from nearby\_positions

**URL:** <https://discourse.julialang.org/t/agents-jl-subset-object-returned-from-nearby-positions/91399>\
**Category:** Modelling & Simulations\
**Tags:** agents\
**Created:** [December 8, 2022, 2:17am UTC](https://discourse.julialang.org/t/agents-jl-subset-object-returned-from-nearby-positions/91399 "2022-12-08T02:17:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sea\_slug](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sea_slug/32/52907_2.png) [@sea\_slug](https://discourse.julialang.org/u/sea_slug)\
**Post date:** [December 8, 2022, 2:17am UTC](https://discourse.julialang.org/t/agents-jl-subset-object-returned-from-nearby-positions/91399/1 "2022-12-08T02:17:36Z")

</div>

I am making a predator-prey model, following the wolf-sheep example using `Agents.jl`.

Following on from [this](https://discourse.julialang.org/t/agents-jl-equivalent-of-nearby-agents-for-grid-cells/91290) question, instead of sheep moving to a random cell I am trying to make the sheep move to a cell that contains grass.

I can get all cells around a sheep with the following:

```
near_cells = nearby_positions(sheep.pos, model, 1)

```

I then want to subset those cells to only get the ones that contain grass e.g. this is pseudo code of what I want to do (doesn’t work):

```
cell_w_grass = near_cells[near_cells.fully_grown == true]

```

I am struggling with the above step, I cannot figure out how to subset the object `near_cells` I am having difficulty understanding the data structure which looks like this: `Base.Iterators.Filter{Agents.var"#74#76"{Matrix{Vector{Int64}}} ...`

Again, probably an obvious question that I am missing due to being a Julia/Agents novice, any advice would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![fbanning](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fbanning/32/14972_2.png) [@fbanning](https://discourse.julialang.org/u/fbanning)\
**Post date:** [December 8, 2022, 11:10am UTC](https://discourse.julialang.org/t/agents-jl-subset-object-returned-from-nearby-positions/91399/2 "2022-12-08T11:10:57Z")

</div>

I think what you want to do is to iterate over `near_cells` and check whether those positions are set to `true` inside `model.fully_grown`. Correct?

A simple way to do it without modifying the `near_cells` variable (which is possibly used somewhere else) could be:

```julia
grassy_cells = []
for cell in near_cells
    if model.fully_grown[cell...]
        push!(grassy_cells, cell)
    end
end

```

(Didn’t test this snippet but it might explain to you what you need to know to solve your problem.)
