+4 votes
in Programming Languages by (17.0k points)
What R function should I use to see the number of rows and columns in a dataframe?

1 Answer

0 votes
by (33.7k points)
edited by

You can use nrow() and ncol() functions to find the number of rows and columns in a dataframe respectively.

You can also use the dim() function to get the dimension of the dataframe.

Here is an example:

> x=c(1,2,3,4,5,6,7)
> y=c(11,12,13,14,15,16,17)
> df = data.frame(x=x, y=y)
> df
  x  y
1 1 11
2 2 12
3 3 13
4 4 14
5 5 15
6 6 16
7 7 17
> nrow(df)
[1] 7
> ncol(df)
[1] 2

Using the dim() function:

> x=c(1,2,3,4,5,6,7)
> y=c(11,12,13,14,15,16,17)
> df = data.frame(x=x, y=y)
> dim(df)
[1] 7 2

...