# Convert DataFrameRow to Vector

**URL:** <https://discourse.julialang.org/t/convert-dataframerow-to-vector/77390>\
**Category:** Data\
**Created:** [March 4, 2022, 3:43am UTC](https://discourse.julialang.org/t/convert-dataframerow-to-vector/77390 "2022-03-04T03:43:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frankiewaang](https://avatars.discourse-cdn.com/v4/letter/f/f9ae1b/32.png) [@Frankiewaang](https://discourse.julialang.org/u/Frankiewaang)\
**Post date:** [March 4, 2022, 3:43am UTC](https://discourse.julialang.org/t/convert-dataframerow-to-vector/77390/1 "2022-03-04T03:43:02Z")

</div>

Hi Guys,  
I got a super easy question:  
when I want to convert a DataFrameRow with the same type to a Vector, I saw from some thread to use:

```nohighlight
Vector(data[1,:]) 
#or
convert(Vector, data[1,:])

```

but some times I got the error message that:  
`MethodError: Cannot convert an object of type DataFrameRow{DataFrame, DataFrames.Index} to an object of type Vector{Int64}`  
PS: I finally end up using `collect(values(data[1:]))` where the `values` function would return a `NTuple` and use collect to make it a vector

Could any one tell me the best way or correct way to do it ?

---

<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:** [March 4, 2022, 3:53am UTC](https://discourse.julialang.org/t/convert-dataframerow-to-vector/77390/2 "2022-03-04T03:53:43Z")

</div>

You were close. Usually `convert` and the constructor are used for things which as “very alike”. A `DataFrameRow` isn’t close enough to qualify for that I guess. You want

```julia
collect(data[1, :])

```

---

<div class="post-metadata">

**Author:** ![Frankiewaang](https://avatars.discourse-cdn.com/v4/letter/f/f9ae1b/32.png) [@Frankiewaang](https://discourse.julialang.org/u/Frankiewaang)\
**Post date:** [March 4, 2022, 3:56am UTC](https://discourse.julialang.org/t/convert-dataframerow-to-vector/77390/3 "2022-03-04T03:56:10Z")

</div>

Thanks! learned two new ways to use `collect` today, such a magic function

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [March 4, 2022, 7:18am UTC](https://discourse.julialang.org/t/convert-dataframerow-to-vector/77390/4 "2022-03-04T07:18:28Z")

</div>

> [@Frankiewaang](#):
>
> `Vector(data[1,:]) `

This should work always. Can you please share the example allowing to reproduce the problem since if it fails it is a bug. Thank you!

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [March 4, 2022, 8:40am UTC](https://discourse.julialang.org/t/convert-dataframerow-to-vector/77390/5 "2022-03-04T08:40:52Z")

</div>

I have opened [https://github.com/JuliaData/DataFrames.jl/issues/3017](https://github.com/JuliaData/DataFrames.jl/issues/3017) to track this so you can also comment there with your failing example directly. Thank you!

---

<div class="post-metadata">

**Author:** ![Frankiewaang](https://avatars.discourse-cdn.com/v4/letter/f/f9ae1b/32.png) [@Frankiewaang](https://discourse.julialang.org/u/Frankiewaang)\
**Post date:** [March 6, 2022, 8:50pm UTC](https://discourse.julialang.org/t/convert-dataframerow-to-vector/77390/6 "2022-03-06T20:50:45Z")

</div>

Sorry for the late reply, I thought it was solved. ☹  
I encountered the issue from the course’s problem set 1: [mitmath/6S083: Materials for MIT 6.S083 / 18.S190: Computational thinking with Julia + application to the COVID-19 pandemic (github.com)](https://github.com/mitmath/6S083) which is offered by Julia academy.  
And I try to run the error code but it seems to work now, the error was shown in a for-loop when I convert the DataFrameRow to a vector, so I tested it separately, and `Vector(data[1,:])` seems to work, and I could not figure out why so I post this problem and used **sometimes** to describe it. After I switch to use `collect(data[1,:])` there is no error anymore, so I didn’t think too much.  
So I think maybe there is no bug in the source code, it could probably be my problem. So sorry for that, maybe you should close the issue. Big thanks for always giving the most effective solutions that help me a lot in the journey to learn Julia lang.

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [March 6, 2022, 8:55pm UTC](https://discourse.julialang.org/t/convert-dataframerow-to-vector/77390/7 "2022-03-06T20:55:49Z")

</div>

Thank you for reporting. I will investigate the code you have linked and make sure we do not have a bug :).
