VOOZH about

URL: https://www.geeksforgeeks.org/r-language/hasname-function-in-r/

⇱ hasName() Function in R - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

hasName() Function in R

Last Updated : 2 Jun, 2022

In this article, we are going to discuss hasName() function in R Programming Language.

hasName() Function

hasName() is used to check whether the dataframe object has a certain name or not.

Syntax: hasName(dataframe,"name")

where,

dataframe is the input dataframe and name is the variable present as variable(column_name) in the given dataframe. It will return TRUE, if the name exists otherwise it will return FALSE.

Example 1:

In this example, we are creating a dataframe with 4 rows and 3 columns.  Here column names are col1, col2 and col3.

Output:

 col1 col2 col3
1 12 34 2
2 2 32 45
3 3 1 3
4 4 0 2
[1] TRUE
[1] TRUE
[1] TRUE

Example 2:

In this example, we are creating a dataframe with 4 rows and 3 columns.  Here column names are col1, col2 and col3.

Output:

 col1 col2 col3
1 12 34 2
2 2 32 45
3 3 1 3
4 4 0 2
[1] FALSE
[1] FALSE
Comment

Explore