nrow()
Published Oct 7, 2022
Contribute to Docs
The nrow()
function returns the number of rows in a data frame.
Syntax
nrow(df_object)
The df_object
parameter is the data frame passed into the nrow()
function.
Example
The following example uses a CSV file named supplies.csv
with the following information:
Item | Quantity Needed | Price |
---|---|---|
Brooms | 15 | 8.5 |
Bucket | 3 | 4 |
Cloth | 6 | 2 |
Duster | 10 | 5.5 |
Mop | 5 | 10 |
The data within the file can be read in with the read.csv()
function and the nrow()
function can be used to retrieve the number of rows:
# Read filedf <- read.csv("supplies.csv")# Retrieve number of rowsnrow(df)
This results in the following output:
5
Contribute to Docs
- 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.
Learn R on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn R
Learn how to code and clean and manipulate data for analysis and visualization with the R programming language.Beginner Friendly14 hours