Getting class of different data types in R Programming – class() Function

class() function in R Language is used to return the class of data used as the arguments.

Syntax: class(x)

Parameters:
x: specified data

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate
# class function
  
# Specifying "Biochemical oxygen demand"
# data set
x <- BOD
x
  
# Calling class() function
class(x)

chevron_right


Output:

  Time demand
1    1    8.3
2    2   10.3
3    3   19.0
4    4   16.0
5    5   15.6
6    7   19.8
[1] "data.frame"

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate
# class function
  
# Calling class() function 
# over different types of data 
class(2)
class(2.8)
class("3")
class("gfg")
class(1 + 2i)

chevron_right


Output:

[1] "numeric"
[1] "numeric"
[1] "character"
[1] "character"
[1] "complex"
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.