R basics

We covered some of the basics of creating and working with objects in R during our first meeting. Now it is time to apply those skills to address some common tasks faced when processing data in R. Indicate what R commands and their output are for each question.

Download and read in the datafile tgpp.csv from the class website using the R function read.csv. Use these steps:

This will take you to a plain text view of the file. At this point you have to options for getting this file into R:

1) Manual download and import

tgpp <- read.csv('C:/users/dan/Rclass/data/tgpp.csv')

2) Alternatively I could just supply the function read.csv the url of the raw file that I navigated to on github:

tgpp <- read.csv('https://raw.githubusercontent.com/dmcglinn/quant_methods/gh-pages/data/tgpp.csv')

The second option is faster but if the file is ever taken offline then that code will break.

This dataset represents the vascular plant species richness that was collected from the Tallgrass Prairie Preserve from 10 x 10 m quadrats. Species richness is simply the number of species that occur within a quadrat.

Read the data into R, note this datafile has a header (i.e., it has column names) unlike the example we examined in class.

  1. What are the names of the columns in this dataset?

  2. How many rows and columns does this data file have?

  3. What kind of object is each data column? Hint: checkout the function sapply().

  4. What are the values of the the datafile for rows 1, 5, and 8 at columns 3, 7, and 10

  5. Create a pdf of the relationship between the variables “scale” and “richness”. Scale is the area in square meters of the quadrat in which richness was recorded. Be sure to label your axes clearly, and choose a color you find pleasing for the points. To get a list of available stock colors use the function colors(). Also see this link: https://r-charts.com/colors/.

  6. What happens to your plot when you set the plot argument log equal to ‘xy’. plot(..., log='xy')