The “data.frame” Function in R

  • Package: Base R (no specific package required)

  • Purpose: Creates a data frame, a two-dimensional structure for storing data with rows and columns.

  • General Class: Data Manipulation

  • Required Argument(s):

    • Named vectors, matrices, or other objects that should be columns in the data frame.

  • Notable Optional Arguments:

    • None

  • Example:

  • # Example data for using the data.frame function
    names <- c("Alice", "Bob", "Charlie")
    ages <- c(25, 30, 22)

    # Create a data frame with two columns
    df <- data.frame(Name = names, Age = ages)

    # Display the result
    print(df)

  • In this example, the data.frame function is used to create a data frame (df) with two columns, “Name” and “Age.” The columns are populated with data from the vectors names and ages. The resulting object is a data frame that is a fundamental structure for handling tabular data in R.

Previous
Previous

The “matrix” Function in R

Next
Next

The “c” Function in R