What is the as.name() function in R?
Overview
The as.name() function in R converts a given R object into a name class object.
The name class object has the class
"name".class(name_object)returns the name of the class from which the R object is inherited.
Syntax
as.name(value)
Parameter value
The as.name() function takes the parameter value, value, which represents the R object.
Return value
The as.name() function returns a name class object.
Code example
# creating an R objectnumber <- 123# printing the value stored in numbernumber# calling the as.name() functionname_object = as.name(number)# printing the name class objectname_object# checking if its a name class objectis.name(name_object)# checking the classclass(name_object)
Code explanation
- Line 2: We create a variable
number. - Line 5: We print the value stored in variable
number. - Line 8: We implement the
as.name()function on thenumbervariable. The result is assigned to a variablename_object. - Line 11: We print the variable
name_object. - Line 14: We use the
is.name()function and check if the variable,name_objectis a name class object. - Line 17: We use the
class()function we returned the class of the objectname_object.