rturf 3: reading a file into R

I made this screencast to show how I would typically get data into the R working environment.

This is a series about R for turfgrass, so for the example data file I chose one that includes morning green speed (stimpmeter) measurements from the 2019 KPMG Women’s PGA Championship at Hazeltine National Golf Club.

One can open a file in RStudio but that doesn’t get us what we want. Opening a file allows us to view the file, or edit the file, but it doesn’t put the file into the working environment so that R can perform operations on the file.

I generally have files in a spreadsheet and save them as comma separated values—csv.

In this example, I had a file named kpmg_speed_vol_2019.csv on my Desktop. Then I use the read.csv function to read the csv file into the R working environment.

# read in the KPMG data file

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



Now the object d contains the data from that file, with 80 observations (rows) of 11 variables (columns).

Running the str (inspect the structure of the object) and the summary commands on the object will often be useful to see what one is working with, or to check for missing data, or to generate some summary statistics.

Now that these data are in the R working enviroment, we are ready to make some calculations.

Related Posts