How to do it...

Perform the following steps:

  1. First, load the mtcars data into a DataFrame with a variable named mtcars:
        > data(mtcars)  
  1. To obtain the vector range, the range function will return the lower and upper bound of the vector:
        > range(mtcars$mpg)
        Output:
    
        [1] 10.4 33.9
  1. Compute the length of the variable:
        > length(mtcars$mpg)
        Output:
    
        [1] 32  
  1. To obtain the mean of mpg:
        > mean(mtcars$mpg)
        Output:
    
        [1] 20.09062  
  1. To obtain the median of the input vector:
        > median(mtcars$mpg)
        Output:
    
        [1] 19.2
  1. To obtain the standard deviation of the input vector:
        > sd(mtcars$mpg)
        Output:
    
        [1] 6.026948  
  1. To obtain the variance of the input vector:
        > var(mtcars$mpg)
        Output:
    
        [1] 36.3241 
  1. The variance can also be computed with the square of ...

Get Machine Learning with R Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.