Open In App

Get or Set the Type of an Object in R Programming – mode() Function

Last Updated : 19 Jun, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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 object

Parameters:
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"

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads