Get range from entire dataframe
we can get a range from the entire dataframe. Here we are getting the maximum value and minimum value by directly using min and max functions in the dataframe, then subtracting the minimum value from the maximum value.
Syntax:
max(dataframe,na.rm=TRUE)-min(dataframe,na.rm=TRUE)
Example:
R
# create dataframe data = data.frame (column1= c (12, 45, NA , NA , 67, 23, 45, 78, NA , 89), column2= c (34, 41, NA , NA , 27, 23, 55, 78, NA , 73)) # display print (data) # find range in entire dataframe print ( max (data, na.rm= TRUE )- min (data, na.rm= TRUE )) |
Output:
column1 column2 1 12 34 2 45 41 3 NA NA 4 NA NA 5 67 27 6 23 23 7 45 55 8 78 78 9 NA NA 10 89 73 [1] 77
How to Find the Range in R?
In this article, we will discuss how to find the Range in R Programming Language.
The range can be defined as the difference between the maximum and minimum elements in the given data, the data can be a vector or a dataframe. So we can define the range as the difference between maximum_value – minimum_value