Get startedGet started for free

Range

The range of a variable is the difference between the highest and lowest value. We can find these values using max() and min() on the variables of our choice. The value returned tells us which row (or case) contains the requested value. We can then index this case to find the desired values. Remember, you can index using [].

This exercise is part of the course

Basic Statistics

View Course

Exercise instructions

  • In your script, assign the minimum value of mtcars$mpg to x
  • In your script, assign the maximum value of mtcars$mpg to y
  • In your script, use the values of x and y to calculate the range of miles per gallon

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Minimum value
x <-
# Maximum value
y <-
# Calculate the range of mpg using x and y
Edit and Run Code