|
Viewing Data in R
There are many ways to view data in R. A few of the few common methods are detailed below. Viewing defined objects via the list function
The list (ls) function returns all of the defined objects (data.frames, vectors, constants, etc) in the current workspace. It does not provide any information regarding the structure or contents of the objects. ls() EXAMPLE: > ls() [1] "TestDataFrame" "TestValue" "TestVector" Viewing defined objects in RStudio
In RStudio, the workspace tab in the Top-Right frame lists all defined objects (along with their structure). The image below in shows an example where the following objects are shown:
Viewing contents of a defined object
The contents of a defined object can be viewed via the view function. The object contents will be shown in a new window. View(ObjectName) EXAMPLE: > View(TestVector) > View (TestData)
Viewing the mode of an object
The mode of an object provides information regarding what type of data is contained within the object. The mode of an object can be viewed using the mode function. mode(ObjectName) EXAMPLE: > mode(TestVector) [1] "numeric" >mode(TestData) [1] "list" Viewing the class of an object
For simple vectors the class will be the same as the mode. However, there are other possible values for "matrix", "array", "factor" and "data.frame" objects. The class of an object can be viewed with the class function. class(ObjectName) EXAMPLE: > class(TestVector) [1] "numeric" >class(TestData) [1] "data.frame" Viewing the length of an object
The length of an object can be viewed using the length function. The length function returns the number of entries for a vector, and the number of variables for a data frame. length(ObjectName) EXAMPLE: > length(TestVector) [1] 3 >length(TestData) [1] 4 |