我知道我的问题有一些线索(特别是这一个R rbind error row.names duplicates not allowed),但作者没有留下答案。
我似乎是常规的data.frame。
# download dataframe
filename="mydf.rds"
host="http://moshetoronto.free.fr/data/"
path=paste0(host,filename)
download.file(path,filename, mode = "wb")
mydf=readRDS('mydf.rds')
class(mydf)
[1] "data.frame"
但由于某些原因,这些属性看起来很奇怪,与常规data.frame
相反# mydf contains list and data.frames
str(mydf)
'data.frame': 20 obs. of 12 variables:
$ geometry :'data.frame': 20 obs. of 2 variables:
..$ location:'data.frame': 20 obs. of 2 variables:
.. ..$ lat: num 31.8 31.8 31.8 31.8 31.8 ...
.. ..$ lng: num 34.7 34.7 34.7 34.7 34.7 ...
..$ viewport:'data.frame': 20 obs. of 2 variables:
.. ..$ northeast:'data.frame': 20 obs. of 2 variables:
.. .. ..$ lat: num 31.9 31.8 31.8 31.8 31.8 ...
.. .. ..$ lng: num 34.7 34.7 34.7 34.7 34.7 ...
.. ..$ southwest:'data.frame': 20 obs. of 2 variable
..
..
..
# contrary to a classic data.frame
other=data.frame("a"=seq(1,10),"b"=letters[1:10])
str(other)
'data.frame': 10 obs. of 2 variables:
$ a: int 1 2 3 4 5 6 7 8 9 10
$ b: Factor w/ 10 levels "a","b","c","d",..: 1 2 3 4 5 6 7 8 9 10
如您所见,mydf包含列表属性和data.frames属性。我注意到这个特征可能是一个rbind失败的根源。
rbind(mydf,mydf)
Error in `row.names<-.data.frame`(`*tmp*`, value = value) :
duplicate 'row.names' are not allowed
In addition: Warning message:
non-unique values when setting 'row.names': ‘1’, ‘10’, ‘11’, ‘12’, ‘13’, ‘14’, ‘15’, ‘16’, ‘17’, ‘18’, ‘19’, ‘2’, ‘20’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’
所以问题是如何使mydf的属性更加规则,以便rbind操作起作用?