Converting data between DataFrame and Matrix
The DataFrames.jl
package provides a vast array of procedures that allow you to manipulate tabular data with rows of heterogeneous types. However, you often have your data stored initially in a matrix. In this recipe, we discuss how you can convert such data to DataFrame
. We also show how you can perform the reverse procedure, that is, transform the data from DataFrame
to a value of a standard Matrix
type available in Julia.
Getting ready
Make sure that you have theDataFrames.jl
package installed. You can check this by writing this in the Julia command line:
julia> using DataFrames
If this command fails, then add theDataFrames.jl
package, in accordance with the instructions in the Managing packages recipe in Chapter 1, Installing and Setting Up Julia:
julia> using Pkg; Pkg.add("DataFrames")
Note
In the GitHub repository for this recipe, you will find the commands.txt
 file, which contains the presented sequence of shell and Julia commands.
Now, open...