The “str” Function in R

  • Package: Base R (no specific package required)

  • Purpose: Displays the internal structure of R objects in a concise and readable form.

  • General Class: Utility/Basic

  • Required Argument(s):

    • ...: One or more R objects.

  • Notable Optional Arguments (defaults may be different for you, run strOptions() to check):

    • max.level: Maximum level of nesting to print. The default is all levels.

    • vec.len: Number of elements to display for atomic vectors. The default is 4.

    • width: Maximum number of characters per line. The default is 52.

    • digits.d: Number of digits to print for numeric vectors. The default is 3.

    • strict.width: If TRUE, enforces the maximum width for atomic vectors. The default is FALSE.

  • Example:

  • # Example data frame
    data <- data.frame(
    Name = c("Alice", "Bob", "Charlie"),
    Age = c(25, 30, 35),
    Married = c(TRUE, FALSE, TRUE)
    )

    # Display the internal structure of the data frame
    str(data)

  • In this example, the str function is used to display the internal structure of a data frame data, including the types and values of its columns. The result is printed to the console.

Previous
Previous

The “table” Function in R

Next
Next

The “tail” Function in R