Get or Set the Type of an Object in R Programming – mode() Function
mode()
function in R Language is used to get or set the type or storage mode of an object.
Syntax:
mode(x)
mode(x) <- value
Here "value" is the desired mode or ‘storage mode’ (type) of the objectParameters:
x: R object
Example 1:
# R program to illustrate # mode function # Initializing some values x < - 3 y < - "a" # Calling the mode() function mode(x) mode(y) |
Output:
[1] "numeric" [1] "character"
Example 2:
# R program to illustrate # mode function # Initializing some values x < - 3 y < - "a" # Calling mode() function to # set the storage mode of the object mode(x) < - "character" mode(y) < - "numeric" # Getting the assigned storage mode mode(x) mode(y) |
Output:
[1] "character" [1] "numeric"
Please Login to comment...