Chapter 7 Dataframes

7.1 Introduction

In this chapter, we will learn to:

  • create dataframe
  • select columns
  • select rows
  • utitlity functions

7.2 Create dataframes

Use data.frame to create dataframes. Below is the function syntax:

## function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, 
##     fix.empty.names = TRUE, stringsAsFactors = default.stringsAsFactors()) 
## NULL

Data frames are basically lists with elements of equal lenght and as such, they are heterogeneous. Let us create a dataframe:

##   name age graduate
## 1 John  29     TRUE
## 2 Jack  25     TRUE
## 3 Jill  27    FALSE

7.5 Select Rows

If you have observed carefully, the column names has been coerced to type factor. This happens because of a default argument in data.frame which is stringsAsFactors which is set to TRUE. If you do not want to treat it as factors, set the argument to FALSE.