Page 277 - Data Science class 11
P. 277

7.11.2 Median

            The median is a measure of central tendency that gives the value of the middle-most observation in the data. In the
            case of ungrouped data, we first arrange the data values of the observations in ascending order. Then, if n is odd, the
                                th
            median is the (n+1)/2  observation.
            The median() function is used in R to calculate this value.
            Syntax
            The basic syntax for calculating the median in R is:

                                                 median(x, na.rm = FALSE)
            The following is a description of the parameters used:

               • x is the input vector.
               • na.rm is used to remove the missing values from the input vector.
            Example
            Enter the following code snippet in the script panel:

                # Create the vector.
                x <- c(13,7,3,4.9,19,3,45,-20,9,-4)

                # Find the median.
                median.result <- median(x)
                print(median.result)
            When we execute the above code, it produces the following result:
























            7.11.3 Mode
            The mode is the value that has the highest number of occurrences in a set of data. Unlike mean and median, mode
            can have both numeric and character data.

            UDF—UDF stands for User Defined Function. These are the functions created by the user as per the requirements of
            the program.
            To create a UDF, these elements are included.

            Function name—this assigns a name to the UDF and save it as a new object.
            Arguments—also known as parameters, these are the variables which are provided within the parenthesis.






                                                           Coding for Data Science Visualisation using R-Studio  275
   272   273   274   275   276   277   278   279   280   281   282