How to convert DataFrame into Array{T,2}?

#1

Let’s say I have a dataframe that only holds number or missings.
How can I convert it to a Array{T, 2} ? Without the names / header

Thank you

using DataFrames
df = DataFrame(a=[ 1, 2, 3, 4, missing], b= [1, 2, 3, 4, 5])
df[:,:]
0 Likes

#2

Try this one

df1=convert(Matrix,df)
0 Likes

#3

Matrix(df) or Matrix{T}(df) if you want to specify T that is different that is automatically inferred.

0 Likes

#4

In the given example, Matrix{T}(df) throws an error if T is not = “Any” because one of the value is missing. Matrix(df) also works fine.

0 Likes

#5

You have to choose an appropriate T of course. Note for example that Matrix{Union{Real, Missing}}(df) will work fine.

0 Likes

#6

Great thank you!

0 Likes