# Minimum and maximum by column in a datafram

**URL:** <https://discourse.julialang.org/t/minimum-and-maximum-by-column-in-a-datafram/72111>\
**Category:** General Usage\
**Tags:** array, dataframes\
**Created:** [November 26, 2021, 1:59pm UTC](https://discourse.julialang.org/t/minimum-and-maximum-by-column-in-a-datafram/72111 "2021-11-26T13:59:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![corny85](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@corny85](https://discourse.julialang.org/u/corny85)\
**Post date:** [November 26, 2021, 1:59pm UTC](https://discourse.julialang.org/t/minimum-and-maximum-by-column-in-a-datafram/72111/1 "2021-11-26T13:59:19Z")

</div>

Hello,

I’m a beginner with Julia.

I’ve got a dataframe called data that i converted in an array of floats.

```julia
data_temp = deepcopy(data)
array=Matrix(data_temp[:,2:size(data_temp,2)])
df=Array{Float64}(array)

```

Now, i want to extract from the array df (10 rows and 5 columns)

- a vector{Float64} including the smallest values for the 3 first columns and the highest values for the 2 last columns
- a vector{Float64} including the highest values for the 3 first columns and the smallest values for the 2 last columns

I don’t know how to do it.

Thanks in advance for your help

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [November 26, 2021, 2:24pm UTC](https://discourse.julialang.org/t/minimum-and-maximum-by-column-in-a-datafram/72111/2 "2021-11-26T14:24:54Z")

</div>

You don’t need a Matrix at all:

```julia
vec_1 = [minimum.(eachcol(df[!, 1:3]); maximum.(eachcol(df[!, 4:5]))]

```

---

<div class="post-metadata">

**Author:** ![corny85](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@corny85](https://discourse.julialang.org/u/corny85)\
**Post date:** [November 26, 2021, 3:45pm UTC](https://discourse.julialang.org/t/minimum-and-maximum-by-column-in-a-datafram/72111/3 "2021-11-26T15:45:23Z")

</div>

I’ve tried:

```julia
bo=[minimum(df[:,1:3],dims=1);maximum(df[:,4:5],dims=1)]

```

But it doesn’t work.  
Why ?

---

<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:** [November 26, 2021, 3:48pm UTC](https://discourse.julialang.org/t/minimum-and-maximum-by-column-in-a-datafram/72111/4 "2021-11-26T15:48:02Z")

</div>

> [@corny85](#):
>
> ```julia
> bo=[minimum(df[:,1:3],dims=1);maximum(df[:,4:5],dims=1)]
> 
> ```

```julia
minimum(df[:,1:3],dims=1)

```

gives a `1x3` matrix, which is not a vector. Maybe you want to `collect` that output so you can `vcat` them.

The error is pretty self-explanatory imo. Make sure you read the error messages and debug piece by piece.

---

<div class="post-metadata">

**Author:** ![corny85](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@corny85](https://discourse.julialang.org/u/corny85)\
**Post date:** [November 26, 2021, 3:54pm UTC](https://discourse.julialang.org/t/minimum-and-maximum-by-column-in-a-datafram/72111/5 "2021-11-26T15:54:04Z")

</div>

ok but how can i concatenate the 1x3 matrix and the 1x2 matrix ?

```julia
bo=vcat(minimum(df[:,1:3],dims=1),maximum(df[:,4:5],dims=1))

```

doesn’t work

---

<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:** [November 26, 2021, 4:01pm UTC](https://discourse.julialang.org/t/minimum-and-maximum-by-column-in-a-datafram/72111/6 "2021-11-26T16:01:56Z")

</div>

The `vcat` here is exactly the same as `;` above.

You can use `hcat` or, as I wrote above, use `collect`

> [@pdeffebach](#):
>
> Maybe you want to `collect` that output so you can `vcat` them.

Please read the responses carefully.

---

<div class="post-metadata">

**Author:** ![corny85](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@corny85](https://discourse.julialang.org/u/corny85)\
**Post date:** [November 26, 2021, 4:03pm UTC](https://discourse.julialang.org/t/minimum-and-maximum-by-column-in-a-datafram/72111/7 "2021-11-26T16:03:53Z")

</div>

You are right !  
Sorry…and thanks a lot !
