Home > Mobile >  Find the number of records in R
Find the number of records in R

Time:09-13

My tutor told me to write down the number of records in a data frame, call it employee consensus data. Should I use the length() or nrow() function

CodePudding user response:

Unless your data frame has the same number of rows and columns, length() and nrow() will give you different values: length(Dataframe) will give you the number of columns in Dataframe, while nrow(Dataframe) will give you the number of rows.

Assuming your dataframe is set up in the standard way (i.e. each record is a row), then use nrow(). You'll need to look at your dataframe to confirm this.

You could use length(Dataframe[,1]) to give you the length of the first column of Dataframe, which should be the number of rows - but I can't think of a reason why this would be any better than just using nrow() which is also more readable.

In short: Use nrow()

CodePudding user response:

Generally in computer science, records are rows, use nrow

  • Related