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

Similar Reads

Method 1: Find range in a vector using min and max functions

We can find the range by performing the difference between the minimum value in the vector and the maximum value in the given vector. We can find the maximum value using the max() function and the minimum value by using the min() function....

Method 2: Get range in the dataframe column

...

Method 3: Get range from entire dataframe

We can get the range in a particular column in the dataframe. Similarly, like a vector, we can get the maximum value from a column using the max function excluding NA values and we can get the minimum value from a column using the min function excluding NA values and finally, we can find the difference....

Method 4: Using range() function

...