Page 239 - Data Science class 11
P. 239

Example

            Enter the following code snippet:

                # Creating the data frame.
                emp.data <- data.frame(

                   emp_id = c (1:5),
                   emp_name = c("Robert","Dharam","Mini","Sharan","Garima"),
                   salary = c(20000.5,35000.2,60000.0,70000.0,84253.25),

                   start_date = as.Date(c("2011-01-21", "2013-11-03", "2014-01-25", "2014-07-21",
                      "2015-05-17")),
                   stringsAsFactors = FALSE
                )

                # Printing the data frame.
                print(emp.data)
            On execution of the above code, the following result is shown:



























            6.11.3 getting the structure of the Data Frame

            The structure of the data frame can be seen by  using the str() function.

            Example
            Enter the following code snippet:

                # Creating the data frame.

                emp.data <- data.frame(
                   emp_id = c (1:5),
                   emp_name = c("Robert","Dharam","Mini","Sharan","Garima"),
                   salary = c(20000.5,35000.2,60000.0,70000.0,84253.25),

                   start_date = as.Date(c("2011-01-21", "2013-11-03", "2014-01-25", "2014-07-21",
                      "2015-05-17")),



                                                                                         Programming with R    237
   234   235   236   237   238   239   240   241   242   243   244