简体   繁体   English

row.name 使用 `structure` 函数作为 c(NA, *integer*)

[英]row.name using `structure` function as c(NA, *integer*)

Does anyone know why when I run this:有谁知道为什么当我运行这个:

row.names(structure(list(speed = c(4, 7), dist = c(2, 22)), 
                    row.names = c(NA, 2L), class = "data.frame"))

I get this:我明白了:

# "1" "2"

and not c(NA, 2L) ?而不是c(NA, 2L) I mean what row.names argument in structure exactly does to the argument?我的意思是structure row.names参数到底对参数有什么作用?

I came across this when I tried to use dput to see the structure of some dataframes.当我尝试使用dput查看某些数据帧的结构时,我遇到了这个问题。 eg例如

dput(cars)

And I noticed the row.names argument in it, which is: c(NA, -50L) .我注意到其中的row.names参数,即: c(NA, -50L)

c(NA, n) is how data frames internally store the row names in the common case of 1:n so as to save space and processing time. c(NA, n)是数据帧在 1:n 的常见情况下内部存储行名称的方式,以节省空间和处理时间。 This is not supposed to be accessible to the user who is to regard it as "1", "2", ... so the accessor functions translate it.对于将其视为“1”、“2”等的用户来说,这不应该是可访问的,因此访问器函数对其进行了翻译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM