Page 238 - Data Science class 11
P. 238

On executing the above code, it produces the following result:






























        6.11 Data Frames

        A data frame is the most common way of storing data in R and, generally, is the data structure most often used for

        data analyses. Under this structure, a data frame is a list of equal-length vectors. As a result, data frames can store
        different classes of objects in each column (i.e., numeric, character, and factor).
        Factor: a factor in R is a data structure which is used to store categorical data.

        A data frame is a table or a two-dimensional array-like structure in which each column contains values of one variable
        and each row contains one set of values from each column.

        To combine a number of vectors into a data frame, you simply add all vectors as arguments to the data. frame()
        function is, separated by commas. R will create a data frame with the variables that are named the same as the vectors
        used.
        6.11.1 characteristics of a Data Frame

        The following are the characteristics of a data frame:

           • The column names must not be empty.
           • The row names should be unique.

           • The data stored in a data frame can be of any numeric, factor, or character type.
           • Each column should contain the same number of data items.

        6.11.2 creating Data Frame

        Syntax of Data Frame

             Dataframe1<-data.frame(first_col=c(val1,val2,….),
                            second_col=c(val1,val2,….),
                            third_col=c(val1,val2,val3,….),
                            ….
                            )

          236   Touchpad Data Science-XI
   233   234   235   236   237   238   239   240   241   242   243