rturf 4: reading a file, making a calculation, and common summary plots

Continuing with the rturf series, this screencast shows how I would typically:

  • read a file of data into the working environment by first placing the file into a /data/ folder within the project directory

  • how to create a new variable by making calculations on existing data—in this case using the Brede equation to convert uphill and downhill measurements in inches to a stimpmeter measurement in feet

  • how to use base graphics to create density plots and histograms of a single variable

  • how I typically search for documentation and help from within R

By the end of the screencast, the file can be read in from its location in the /data/ folder, the structure and a summary of the data can be viewed, the speed is calculated, and then the speed is viewed as a density plot and as a histogram.

# read in the KPMG data file

d <- read.csv("data/kpmg_speed_vol_2019.csv",
              header = TRUE, stringsAsFactors = FALSE)

str(d)

summary(d)

d$speed <- (2 * d$uphill * d$downhill) / (d$uphill + d$downhill) / 12

plot(density(d$speed))

plot(hist(d$speed, breaks = 40))
Next
Previous