10 Creating data frame objects

 

This chapter covers

  • Creating data frames
  • Using RCall.jl to integrate with the R language
  • Understanding the Tables.jl interface
  • Plotting a correlation matrix
  • Constructing a data frame iteratively by adding rows to it
  • Serializing Julia objects

In chapter 8, I introduced you to working with data frames, using sample data loaded from a CSV file. In this chapter, I’ll show you more ways to convert values of different types to and from a DataFrame object. You need to have this fundamental knowledge so you can use the DataFrames.jl package efficiently. You must be prepared for source data to come in various formats, and you need to know how to convert that data to a DataFrame.

Since the topic of creating DataFrame objects is broad, in this chapter, I use several small tasks as examples of applying the concepts you learn. Following one complex example (as we did with the Lichess puzzle data in chapters 8 and 9) would not allow me to show all the options that are useful in practice. To ensure that this chapter, apart from teaching you how to create data frames, also gives you useful recipes for data analysis, we will create a plot of a correlation matrix of data stored in a data frame.

I divided the chapter into two sections to help you easily navigate the available options and concentrate on the scenarios that are most relevant in your day-to-day work:

10.1 Reviewing the most important ways to create a data frame

10.1.1 Creating a data frame from a matrix

10.1.2 Creating a data frame from vectors

10.1.3 Creating a data frame using a Tables.jl interface

10.1.4 Plotting a correlation matrix of data stored in a data frame

10.2 Creating data frames incrementally

10.2.1 Vertically concatenating data frames

10.2.2 Appending a table to a data frame

10.2.3 Adding a new row to an existing data frame

10.2.4 Storing simulation results in a data frame

Summary