简体   繁体   English

R:具有负 row.name 值的对象

[英]R: object with negative row.name value

I think I have the same issue with this: What's the difference between row.names() and attributes$row.names?我想我有同样的问题: row.names() 和 attributes$row.names 之间有什么区别?

When I use dput now I get something like this:当我现在使用dput我得到了这样的信息:

-0.0120067403271522, -0.00712477902137182, -0.0105058179972997, 
-0.0115956365572667, -0.00507521571067687, -0.013870827853567, 
-0.0160501419238977, -0.00225243465241482, -0.0145865320678265, 
-0.00118232647592066, -0.0190385732141539, 0.0108223868283294, 
-0.0159300331503545, 0.0319315053338279, 0, 0.00315703437341087, 
0.0368045045454188, -0.0276264287281491, -0.0101235678857984, 
0.00486601316019395)), class = "data.frame", row.names = c(NA, 
-11834L))

I discovered this while I was trying to force define rownames(var) <- c(list_of_row_names) .我在尝试强制定义rownames(var) <- c(list_of_row_names)发现了这一点。

I get the error:我收到错误:

Error in .rowNamesDF<- (x, value = value) : invalid 'row.names' length` .rowNamesDF<- (x, value = value) 中的错误:'row.names' 长度无效

The thing is this object has values inside it.问题是这个对象里面有值。 Anyone can tell me how I can rewind/fix this?任何人都可以告诉我如何倒带/解决这个问题?

From my understanding, this happened bc R didnt know row names when this object was created?根据我的理解,这发生了 bc R 在创建此对象时不知道行名称?

The length of that variable list_of_row_names does not match with the nrow() of the data frame该变量list_of_row_names的长度与数据框的nrow()不匹配

See an example given below:请参阅下面给出的示例:

df <- data.frame(1:5)
list_of_row_names <- letters[1:4]
rownames(df) <- list_of_row_names

Error in row.names<-.data.frame ( *tmp* , value = value) : invalid 'row.names' length row.names<-.data.frame ( *tmp* , value = value) 错误:'row.names' 长度无效

nrow(df)
#[1] 5

length(list_of_row_names)
# [1] 4

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

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