The “dim” Function in R

  • Package: Base R (no specific package required)

  • Purpose: Gets or sets the dimensions of arrays (matrices, data frames).

  • General Class: Data Manipulation

  • Required Argument(s):

    • An array, matrix, or data frame for which dimensions are to be retrieved or set.

  • Notable Optional Arguments:

    • value: If specified, sets the dimensions of the array to the specified values.

  • Example:

  • # Example data for using the dim function
    matrix_example <- matrix(1:6, nrow = 2, ncol = 3)

    # Get dimensions of the matrix
    dimensions <- dim(matrix_example)

    # Display the result
    print(dimensions)

  • In this example, the dim function is used to retrieve the dimensions of a matrix (matrix_example). The resulting dimensions vector contains the number of rows and columns in the matrix. The dim function is versatile and can be used to get or set the dimensions of various types of arrays in R.

Previous
Previous

The “names” Function in R

Next
Next

The “rbind” Function in R