menu

0.4 - Important R Code

by

At the end of each chapter, there will be a section highlighting the most important R code used. The dark text will never change but the lighter (red) text will need to be customized to your particular application. The sub-bullet for each function will discuss the use of the function and pertinent options or packages required. You can use this as a guide to finding the function names and some hints about options that will help you to get the code to work or you can revisit the worked examples using each of the functions.

  • FILENAME<-read.csv("path to save csv file/ FILENAME.csv")
    • Can be generated using "Import Dataset" button or by modifying this text.
  • DATASETNAME$VARIABLENAME
    • To access a particular variable in a data.frame called DATASETNAME, use a $ and then the VARIABLENAME.
  • head(DATASETNAME)
    • Provides a list of the first few rows of the data set for all the variables in it.
  • mean(DATASETNAME$VARIABLENAME)
    • Calculates the mean of the observations in a variable.
  • sd(DATASETNAME$VARIABLENAME)
    • Calculates the SD of the observations in a variable.
  • favstats(DATASETNAME$VARIABLENAME)
    • Provides a suite of numerical summaries of the observations in a variable.
    • Requires the mosaic package to be loaded (require(mosaic)).
  • hist(DATASETNAME$VARIABLENAME)
    • Makes a histogram.
  • boxplot(DATASETNAME$VARIABLENAME)
    • Makes a boxplot.