0

I know there is some threads about my problem (especially this one R rbind error row.names duplicates not allowed) but the author did not leave the answer.

I got a seems to be regular 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"

But for some reasons theses attributes look weird, contrary to the regular 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

As you can see, mydf contains lists attributes and data.frames attributes. I noticed that this characteristic could be the root of an rbind failure.

error

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’ 

So the question is what to do to make mydf's attributes more regular so that the rbind operation would work?

Community
  • 1
  • 1
hans glick
  • 2,431
  • 4
  • 25
  • 40
  • You can try `dplyr`'s `bind_rows()` function, which may be more forgiving of nested `data.frame`s – RoyalTS Mar 10 '17 at 17:39
  • Fyi, your current question has little hope of being more helpful than the one you linked to unless you post a (long-term) reproducible example (that doesn't depend on external websites). See http://stackoverflow.com/a/28481250/ – Frank Mar 10 '17 at 17:41
  • @ Frank i'm ok with you, but I dwled those data, and I do not understand how it could be structured that way, that's the reason why I load the rds on my ftp. – hans glick Mar 10 '17 at 17:48
  • @RoyalTS ok i'm gonna check it – hans glick Mar 10 '17 at 17:48

0 Answers0