Page 225 - Data Science class 11
P. 225

The following result is produced:


















            6.8 List in r Programming

            A list in R is a type of R object that contains different types of elements like—numbers, vectors, strings, and another
            list within it. A list can also contain a function, a matrix, or data frames as its elements.

            To create a list, we use the list() function. An example is shown below to create a list using strings, numbers, vectors,
            and logical values.
            Example

            Enter the following code snippet:

                # list containing strings, numbers, vectors and a logical
                list_data <- list("Red", "White", c(1,2,3), TRUE, 22.4)
                print(list_data)

























            6.8.1 name elements of a List
            Matrix: It is a collection of elements of the same type arranged into a fixed number of rows and columns. So, it is
            two-dimensional in nature.
            With the help of an example, we will now learn to name the R list elements. Let’s create a list containing a vector,
            matrix, and list.
            Example
            Enter the following code snippet:

                #creating a list containing a vector, matrix, and list





                                                                                         Programming with R    223
   220   221   222   223   224   225   226   227   228   229   230