Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
572 views
in Technique[技术] by (71.8m points)

r - rbind error: "names do not match previous names"

As part of a larger problem (adding a ,makeUniqueIDs argument to rbind.SpatialPolygonsDataFrame for situations when the polygon IDs are identical), I'm running into this weird message from rbind:

> do.call("rbind",xd.small)
Error in match.names(clabs, names(xi)) : 
  names do not match previous names

The only other info I could find on this was this question, which leads me to believe that rbind was at the root of the problem there also.

I can just write my own rbind-like function of course, but presumably this match.names check occurs for a reason, and I'm curious what it is.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The names (column names) of the first dataframe do not match the names of the second one. Just as the error message says.

> identical(names(xd.small[[1]]), names(xd.small[[2]]) )
[1] FALSE

If you do not care about the names of the 3rd or 4th columns of the second df, you can coerce them to be the same:

> names(xd.small[[1]]) <- names(xd.small[[2]]) 
> identical(names(xd.small[[1]]), names(xd.small[[2]]) )
[1] TRUE

Then things should proceed happily.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...