Basic Methods for Handling Variables
In this lesson, we’ll learn how to List and Delete variables.
We'll cover the following
Listing and Deleting Variables #
Listing #
We can check all the variables that have been created in the workspace using the keyword ls()
.
To import recent packages for execution of codes on our platform, we have declared a variable r at our backend. Under normal circumstances, you will not get this variable when using the ls() command.
myRealNumeric <- 10myDecimalNumeric <- 10.0myCharacter <- "10"myBoolean <- TRUEmyInteger <- 0:10myComplex <- 5icat("Variables in the current directory: \n")ls() # returns all the variables created in the workspace alphabeticallycat("\n")
Deleting #
We can delete a specific variable from the workspace.
The keyword rm()
can help us permanently remove one or more objects from the workspace:
myRealNumeric <- 10myDecimalNumeric <- 10.0myCharacter <- "10"myBoolean <- TRUEmyInteger <- 0:10myComplex <- 5icat("Variables in the current directory: \n")ls() # returns all the variables created in the workspacecat("\n")cat("Deleting myRealNumeric and myDecimalNumeric \n\n")rm(myRealNumeric, myDecimalNumeric) # delete the two mentioned variablescat("Variables in the current directory, now: \n")ls() # returns all the variables created in the workspace# myRealNumeric, myDecimalNumeric are now deletedcat("\n")