Page 276 - Data Science class 11
P. 276

result.mean <-  mean(x,trim = 0.3)

             print(result.mean)
        When we execute the above code, it produces the following result:




























        Applying NA Option
        If there are missing values, then the mean function returns NA.
        To drop the missing values from the calculation, use na.rm = TRUE. which means removing the NA values.
        Example
        Enter the following code snippet in the script panel:

             # Creating a vector.
             x <- c(12,7,3,4.2,18,2,54,-21,8,-5,NA)
             # Finding mean.
             result.mean <-  mean(x)
             print(result.mean)
             # Find mean dropping NA values.
             result.mean <- mean(x,na.rm = TRUE)
             print(result.mean)
        When we execute the above code, it produces the following result:



























          274   Touchpad Data Science-XI
   271   272   273   274   275   276   277   278   279   280   281