ncol()
KyraThompson73 total contributions
Published Oct 7, 2022
Contribute to Docs
The ncol()
function returns the number of columns in a data frame.
Syntax
ncol(df_object)
The df_object
parameter is the data frame passed into the ncol()
function.
Example
The following example uses a CSV file named patients.csv
with the following information:
First Name | Last Name | DOB |
---|---|---|
Kiercen | Tremboly | 06/24/1992 |
Phaedra | Blackborn | 08/19/1972 |
Toby | Spencer | 11/16/1953 |
Sandra | Speller | 07/05/1989 |
The data within the file can be read in and the ncol()
function can be used to retrieve the number of columns:
# Read filedf <- read.csv("patients.csv")# Retrieve number of columnsncol(df)
This results in the following output:
3
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.