Data files and data frames

Last chapter, we learned about vectors: sequences of numbers or strings. But if you’ve ever worked with data, you know that data usually doesn’t get emailed to you as a vector, it comes as a table or spreadsheet. Tables are also the most common way to work with data in R, and in this chapter, we’ll learn more about that.

The first thing we’ll learn is that, in R, tables are called data frames. There are many ways to create data frames, and one basic way is to stick some vectors in the data.frame() function. For example, data.frame(x, y, z) would create a data frame that includes the data from vectors x, y, and z as columns.

Replace the ______ placeholder with a data frame with columns quarter, revenue, and expenses, and assign it to the variable finances. Then, press ▶ Run Code.

It can take up to a minute for R to start up here, so please be patient.

quarter = c("Q1", "Q2", "Q3", "Q4")
revenue <- c(120, 150, 78, 104)
expenses <- c(106, 112, 96, 98)
finances <- ______
_webr_editor_1 = Object {code: null, options: Object, indicator: it}
Downloading package: tidyverse