Home » R Tutorials » R is.data.frame – Check if object is Data frame in R

R is.data.frame – Check if object is Data frame in R

R is.data.frame() function is used to check if the object is a data frame or not. is.data.frame() function in R returns TRUE if the object is data frame else returns FALSE.

Data frame in R is very powerful to store data of different data types, data manipulation. data.frame() function is used to create a data frame in R.

In this tutorial, we will discuss how to use is.data.frame() function in R to check the object is data frame in R or not.

R is.data.frame() – Is object data frame?

is.data.frame() syntax in R is

Syntax : 
is.data.frame(x)

Argument:
x = data frame

Let’s understand with an example to check specified data type is a data frame or not using is.data.frame() in R.

Let’s use the CO2 dataset to check if it is data frame or not

# Use CO2 dataset Carbon dioxide uptake in grass plants
data <- CO2
# Use is.data.frame() 
is.data.frame(data)

The output of the above R code to check the CO2 dataset using is.data.frame() function is:

[1] TRUE

It returns a TRUE value, which means the CO2 dataset is the data frame type.

Check Data is Data Frame in R

Let’s understand more on to know if data is data frame in R using is.data.frame() function.

# R is.data.frame() to check data frame for different data types like int,float, list
# Check if string is of type data frame in R
is.data.frame("Test")
# Check if int is of type data frame in R
is.data.frame(12)
# Check if decimal is of type data frame in R
is.data.frame(10.3)
# Creat a vector and Check if vector is of type data frame in R
name <- c("Tom", "Aron", "Gary","Jeannie")
is.data.frame(name)

The output of the different data types to check if data is data frame in R using is.data.frame() is:

[1] FALSE
[1] FALSE
[1] FALSE
[1] FALSE

Conclusion

I hope the above article using the R is.data.frame() function to check if data is a data frame or not.

is.data.frame() function in R returns TRUE if data is a data frame else returns FALSE.

Leave a Comment