Open In App

Check data format in R

In this article, we will discuss how to check the format of the different data in the R Programming Language. we will use the typeof() Function in R.

typeof() Function in R

In R Programming Language The typeof() function returns the types of data used as the arguments.



Syntax:

typeof(x)



Parameters:
x: specified data

R program to find data types of different values




# typeof function
# over different types of data
typeof(2)
typeof(5.5)
typeof("777")
typeof("gfg")
typeof(1 + 2i)

Output:

[1] "double"
[1] "double"
[1] "character"
[1] "character"
[1] "complex"

R program to find data types of mix values




# create a vector and store values
a1<-c(11,22,33,'GFG',55)
typeof(a1)

Output:

[1] "character"

R programme to find data types of dataset




# load inbuilt dataset
data(mtcars)
# check the data type of the data
typeof(mtcars)
 
# check the data type of the single column
typeof(mtcars$cyl)

Output:

[1] "list"
[1] "double"

To find out the data type is important term in programming it help us to understand that what type of value we have.

typeof() function in R is help us to find out the type of the data easily.


Article Tags :