ncol() function in R Language is used to return the number of columns of the specified matrix.
Syntax: ncol(x)
Parameters:
x: matrix, vector, array or data frame
Example 1:
# R program to illustrate # ncol function # Getting R Biochemical Oxygen Demand Dataset BOD # Calling ncol() function to # get the number of columns ncol(BOD) |
chevron_right
filter_none
Output:
Time demand 1 1 8.3 2 2 10.3 3 3 19.0 4 4 16.0 5 5 15.6 6 7 19.8 [1] 2
Example 2:
# R program to illustrate # ncol function # Specifing a matrix x <- matrix(c(1, 2, 3, 4), 2, 2) # Calling the ncol() function ncol(x) |
chevron_right
filter_none
Output:
[1] 2
Recommended Posts:
- Get the number of rows of an Object in R Programming - nrow() Function
- Getting a Matrix of number of columns in R Programming - col() Function
- Get the Maximum element of an Object in R Programming - max() Function
- Get the Minimum element of an Object in R Programming - min() Function
- Search and Return an Object with the specified name in R Programming - get() Function
- Get or Set names of Elements of an Object in R Programming - names() Function
- Get or Set the Type of an Object in R Programming - mode() Function
- Calculate the Sum of Matrix or Array columns in R Programming - colSums() Function
- Naming Rows and Columns of a Matrix in R Programming - rownames() and colnames() Function
- Merge Two Data Frames by common Columns in R Programming - merge() Function
- Rename Columns of a Data Frame in R Programming - rename() Function
- Choose Specific Columns of a Data Frame in R Programming - select() Function
- Scale the Columns of a Matrix in R Programming - scale() Function
- Applying a Function over an Object in R Programming - sapply() Function
- Get the List of Arguments of a Function in R Programming - args() Function
- Get the Number of Levels of a Factor in R Programming - nlevels() Function
- Print the Value of an Object in R Programming - identity() Function
- Convert type of data object in R Programming - type.convert() Function
- Return True Indices of a Logical Object in R Programming - which() Function
- Create an Object of mode call in R Programming - call() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

