2.1 At the Top of Your Code

  • With RStudio, you can see the objects in the Environment window, usually in the upper right of your screen. The ls() code lists all of the objects in your workspace.

  • The rm() code removes objects in your workspace. You can begin your code with the rm() function to clear all of the objects from your workspace to start with a clean environment. This way the workspace is empty and everything you create is clearly visible.

rm(list=ls())

ls()

The ls() command indicates that there is nothing in the workspace with the following response:

character(0)

showing that the workspace is empty. Also, in the top-right panel of RStudio, the Environment tab indicates that the workspace is empty.

  • You can set the working directory so that you know where your data, code and output are stored. The setwd() and getwd() codes set the working directory and then verify the working directory. You can either hard code this with typing in commands:
setwd("C:/Margie/MEPS")
getwd()

or you can go to the Session/Set Working Directory menu item at the top of RStudio and set it with your mouse.

  • A helpful command is str(nameofdata), where nameofdata is the name of your data frame. This function provides a quick listing of the data, with the number of observations, the variables, and the type of the variables, whether they are an integer, real, or character.