Determine the size of a data frame

June 9, 2020
By

[This article was first published onQuantargo博客, and kindly contributed to188bet app]. (You can report issue about the content on this page这里)
要共享R-博客内容?188bet app188bet app 如果你有一个博客,或这里如果你不这样做。

的数据帧的大小,如行或列的数量,通常需要并且可以以各种方式来确定。

  • Get number of rows of a data frame
  • Get number of columns of a data frame
  • Get dimensions of a data frame
nrow(___) ncol(___) dim(___) length(___)

Data Frame Dimensions

nrow(___) ncol(___) dim(___) length(___)

数量的行s and columns in a data frame can be guessed through the printed output of the data frame. However, it is much easier to get this information directly through functions. Additionally, you might want to use this information in some parts of the code.

数据帧有两个维度。数量的行s is considered to be the first dimension. It typically defines the number of observations in a data set. To get the number of rows from the戴维斯data frame in thecarDatadataset use thenrow()function:

nrow(戴维斯)
[1] 200

Similarly, the number of columns or属性of the data frame can be retrieved with的NcoI():

ncol(Davis)
[1] 5

Exercise: Determine number of elements in data frame

survived sex age passengerClass Allen, Miss. Elisabeth Walton yes female 29 1st [ reached 'max' / getOption("max.print") -- omitted 1308 rows ]

确定数据值在数TitanicSurvivaldata frame above given as the number of rows multiplied by the number of columns.

Start Exercise

Retrieving data frame dimensions

nrow(___) ncol(___) dim(___) length(___)

To retrieve the size of all dimensions from a data frame at once you can use thedim()function.dim()returns a vector with two elements, the first element is the number of rows and the second element the number of columns.

For example, the dimensions of the戴维斯dataset can be retrieved as

昏暗(戴维斯)
[1] 200 5

除了数据帧dim()can also be used for other multi-dimensional R objects such as matrices or arrays. However, when used with vectorsdim唯一的回报空值:

dim(c(1, 3, 5, 7))
空值

取而代之的是,一个矢量的长度被确定,通过length():

length(c(1, 3, 5, 7))
[1] 4

In the case of a data framelength()返回其列数:

length(Davis)
[1] 5

提问:数据帧尺寸

dim(Florida)

What does the above command return for the data setFloridafrom thecarDatapackage which has 11 columns and 67 rows?

  • 6711
  • 1167
  • 11
  • 67

Start Quiz

Determine the size of a data frame is an excerpt from the courseIntroduction to R, which is available for free atquantargo.com

VIEW FULL COURSE

To发表评论for the author, please follow the link and comment on their blog:Quantargo博客

R-bloggers.comoffersdaily e-mail updates金宝搏网址 Rnews and tutorials about金宝搏网址 and many other topics.Click here if you're looking to post or find an R/data-science job
要共享R-博客内容?188bet app188bet app 如果你有一个博客,或这里如果你不这样做。



If you got this far, why notsubscribe for updatesfrom the site? Choose your flavor:e-mail,twitter,1188bet app, orfacebook。。。

Comments are closed.

Search R-bloggers

Sponsors

Never miss an update!
订阅R-博客188bet app受到
e-mails with the latest R posts.
(您将不会再看到这条消息。)

Click here to close (This popup will not appear again)