Learn R Theory
Object and Data Types
Objects are things which holds the values in R. Objects are named data structure that store data.
Most common object is vector. A vector can hold values of similar type. There is another object type which is List. List can hold values of different types. There are other objects as well such as Data Frames, Matrix etc.
The values which are stored by Objects have types, hence we ask what is Data Type of Object ? There are five basic or 'atomic' classes of objects(Data Type of Objects).
- character
- numeric (real numbers)
- integer
- complex
- logical (TRUE/FALSE)
# Example of Object
# Create an Object named "a"
a<-1
print(a) #print the value stored in object named "a"# Type of an Object
print(typeof(a))#Creating a Vector
vector<-c(1,2,3,4)
typeof(vector)Attributes of Objects
R objects can have attributes,these are like details which describes the objects. See the example below
Some examples of R object attributes are
- names, dimnames
- dimensions (e.g. matrices, arrays)
- class (e.g. integer, numeric)
- length
- other user-defined attributes/metadata
Attributes of an object (if any) can be accessed using the attributes() function. Not all R objects contain attributes, in which case the attributes() function returns NULL.
attributes(vector)