Convert character string to name class object

Convert character string to name class object, The R programming language’s and functions are demonstrated in this tutorial.

Let’s get going…

Definitions: The and functions are described in the sections that follow.

A character string is transformed into a name class object using the R function.

The R function determines whether a data object contains the class name.

Please see the fundamental R programming syntaxes for the functions and below.                  # function basic R syntax                  # Basic R syntax of function

It should be noted that the functions and are equivalent to as.symbol and is.symbol. If you’d like, you can swap out these function names.

But, we’ll demonstrate how to use the R programming language’s and commands and functions in the following two examples.


The following information will be used as the starting point for this R programming tutorial:

x <- "myname"              # Create character string object
x                           # Print character string object

Have a peek at the RStudio console’s earlier output. It demonstrates that the sample data we used was just a plain character string kept in the data object x.

To determine the data type of our data object, we can utilize the class function.

class(x)                    # Check class

The class character appears in the example data.

Example 1: Convert character string to name class object

We’ll demonstrate how to use the function to convert the character class to the name class in Example 1. Consider the following R code.

x_name <-        # Apply function

Our data type was altered from character to name in the prior R syntax. With the class function, we can determine the data type of our new data object:

class(x_name)               # Check class

New class name is “name” mode

Example 2: Verify the class name of the data object.

In order to determine whether a data object contains the class name, we can use the function, which returns a logical value.

Let’s use our initial data object x to test the function.                  # Test character string

As evidenced by the output from the RStudio console, our original data object is not a name object.

Let’s use our new data object to apply the function now.             # Test name object

The function returns the logical value YES, indicating that the class name is present in our new data object.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

four × five =