R operates on objects(entities to work with).
Other recursive structure are those of mode functions and expressions.
When we talked about mode of an object, we are talking about the basic type of its fundamental constituents.This is the special case of a property of object.
Length is the number of elements that is present in an object, or we can say that number of elements that are stored against an object.
mode(object_name) # return the mode of an object
length(object_name) # returns length of an object
attributes(object_name) # it will return attributes of an object if any
We can change the mode of any object if needed to do so, Like
# R caters for change of mode
x <- 0:9
x #[1] 0 1 2 3 4 5 6 7 8 9
## [1] 0 1 2 3 4 5 6 7 8 9
# as.character()/ as.type() will change the mode
digits <- as.character(x)
digits # [1] "0" "1" "2" "3" "4" "5" "6" "7" "8" "9"
## [1] "0" "1" "2" "3" "4" "5" "6" "7" "8" "9"
# further coercion/change of mode
d <- as.integer(digits)
d #[1] 0 1 2 3 4 5 6 7 8 9
## [1] 0 1 2 3 4 5 6 7 8 9
There is a collection of functions of the form as.something() for either coercion from one mode to other, or for investing properties of one object to other.
An empty object may still have a mode. Let’s just say
e <- numeric() # creates a numric empty vector
e
## numeric(0)
# can make empty vector of any type
When an object is created the new components can be added to it. By simply added the index value outside its previous range.
e[3] <- 17
e
## [1] NA NA 17
# 1st two values will be empty just because we have assigned one and that one value will be the 3rd one.
To truncate the size of an object requires only an assignment to do so.We have an object d of length 10. To make it an object of length 5 consisting of just former components with even index in following way:
d <- d[2 * 1:5]
d
## [1] 1 3 5 7 9
We can retain the first 3 values by
length(d) <- 3
d
## [1] 1 3 5
The function attributes(object_name) can be used to get all the non-instrinsic elements of an object.And the function attr(object, name) can be used to select a specific attribute.
All objects in R always belongs to some class which can be reported by class function.