简体   繁体   中英

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?

When I use dput now I get something like this:

-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) .

I get the error:

Error in .rowNamesDF<- (x, value = value) : invalid 'row.names' length`

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?

The length of that variable list_of_row_names does not match with the nrow() of the data frame

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

nrow(df)
#[1] 5

length(list_of_row_names)
# [1] 4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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