How to view the number of rows and columns in R language?
In R, you can use the functions nrow() and ncol() to respectively check the number of rows and columns in a data frame or matrix.
For example, suppose there is a data frame df, we can view the number of rows and columns using the following method:
# 查看行数
nrow(df)
# 查看列数
ncol(df)
To check the number of rows and columns of a matrix mat, you can also use the functions nrow() and ncol().
# 查看行数
nrow(mat)
# 查看列数
ncol(mat)
Please note that these functions only work with data frames and matrices, and will return an error for other types of objects such as vectors or lists.