10.1 Simple Data Frame

To allow a common example for illustration purposes, suppose we have three sequences of numbers, \(time\), \(t\), and \(accum\) that are in separate lists. The first command removes all objects in your workspace so that you start with a clean slate.

rm(list = ls())

i <- 0.05
t <- seq(from = 0, to = 5, by = 0.5)
accum <- (1 + i)^t
time <- c("Zero", "One Half", "One", "One+Half", "Two", 
          "Two+Half", "Three", "Three+Half", "Four", "Four+Half", "Five")

After you run the code, check in the Global Environment Window to see that 4 values are listed and how they are listed. Note that t and accum are shown as numeric vectors, while time is shown as a character vector. You can check this with the following code:

is.vector(t)
is.vector(accum)
is.vector(time)

To combine these vectors together, we use the function data.frame() and name the data frame dat. You can view the data frame either by typing dat in the script/console window as indicated in the following code.

dat <- data.frame(time, t, accum)
dat

The data frame dat is shown in the Global Environment Window with 11 observations and 3 variables. You can click on the blue circle next to dat to see a listing of the variables in the data frame and their data type. If you double-click on dat you can view the data frame.

This approach is great for small data sets. For large data frames, i.e. with a large number of rows and/or a large number of variables, we need other tools to help navigate the information in the data frame object.