The “nrow” Function in R
Package: Base R (no specific package required)
Purpose: Retrieves the number of rows in an array, matrix, or data frame.
General Class: Data Manipulation
Required Argument(s):
An array, matrix, or data frame for which the number of rows is to be retrieved.
Notable Optional Arguments:
None
Example:
# Example data for using the nrow function
matrix_example <- matrix(1:6, nrow = 2, ncol = 3)
# Get the number of rows in the matrix
num_rows <- nrow(matrix_example)
# Display the result
print(num_rows)In this example, the nrow function is used to retrieve the number of rows in a matrix (matrix_example). The resulting num_rows value is 2, as specified when creating the matrix. The nrow function is commonly used to determine the number of rows in matrices and data frames.