if we already have nrow and ncol in r, then why there is NROW and NCOL is there. is there any difference between them or they are just an alias?
mx <- matrix(1:12,3,4)
nrow(mx)
NROW(mx)
ncol(mx)
NCOL(mx)
if we already have nrow and ncol in r, then why there is NROW and NCOL is there. is there any difference between them or they are just an alias?
mx <- matrix(1:12,3,4)
nrow(mx)
NROW(mx)
ncol(mx)
NCOL(mx)
in R you always can check the code of functions, typing their names without the parenthesis. Doing this, you can see the differences between NCOL and ncol:
NCOL
# function (x)
# if (length(d <- dim(x)) > 1L) d[2L] else 1L
# <bytecode: 0x560bca6cb290>
# <environment: namespace:base>
ncol
# function (x)
# dim(x)[2L]
# <bytecode: 0x560bc9691cd0>
# <environment: namespace:base>
ncol will always return the second dimension of the argument, while NCOL will check if the argument only has one dimension, in which case it will return 1.