Getting started with dplyr
To start off with, I will create an R script called dplyr_intro.R
and set up my R environment. First, you should set your working directory to the ch7
project folder. Next, you should read the fuel economyhttps://catalog.data.gov/dataset/consumer-price-index-average-price-data dataset into a dataframe as follows:
setwd("path/to/your/project/folder") vehicles<-read.csv("data/vehicles.csv")
The next step is to import the dplyr
and tibble
packages. In R, you can import a package using the library()
function. The following lines import the dplyr
package and the tibble
package:
library('dplyr') library('tibble')
I will start with the select()
function. The select()
function allows you to select a certain number of columns from a dataframe and returns another dataframe containing only those selected columns. As its first argument, the select()
function takes a dataframe. The following arguments to the select()
function after the first argument are the names of the columns...