2016-04-19 4 views
-2

Ich versuche, zwei Datenrahmen in R zu binden, aber immer noch eine 'doppelte' row.names 'sind nicht erlaubt' Fehler. Sie sind zwei Datenrahmen mit jeweils hundert Zeilen und der gleichen Anzahl von Spalten. Ich habe versucht, die Zeilennamen vor der Verwendung von rbind zu definieren, aber ich bekomme immer noch den Fehler. Ich benutze dies:Warum kann ich diese Datenframes nicht in R binden?

Meine Daten stammen aus der API des UK Companies House. Einträge im Array sehen so aus:

description_identifier     kind      title company_type 
X1   dissolved-on searchresults#company THIS IS A COMPANY NAME   ltd 
       self        snippet date_of_cessation 
X1 /company/08733334 Unit 2, 41 A Road, London, E8 2QH  2015-11-10 
           description date_of_creation company_number company_status 
X1 08730034 - Dissolved on 10 November 2015  2013-10-14  08730034  dissolved 

Wie kann ich diese Datenrahmen binden?

EDIT: wie gewünscht, Ausgänge für dput (Kopf (Söhne)) ist

structure(list(title = c("SON AND SONS PRODUCTIONS LTD", "SJ AND SONS LTD", 
"DW AND SONS LTD", "PJ AND SONS LTD", "ND AND SONS LTD", "TF AND SONS LTD" 
), company_type = c("ltd", "ltd", "ltd", "ltd", "ltd", "ltd"), 
    links = structure(list(self = c("/company/08730034", "/company/08902692", 
    "/company/09211826", "/company/09496249", "/company/09669572", 
    "/company/NI633653")), .Names = "self", row.names = c(NA, 
    6L), class = "data.frame"), snippet = c("Unit E1, 41 Dace Road, London, E3 2NG", 
    "17 Poundgate Lane, Westwood Heath, Coventry, CV4 8HJ", "60, Hawkins Road, Folkestone, CT19 4JA", 
    "Dalton House, 9 Dalton Square, Lancaster, LA1 1WD", "19 Barnston Lane, Moreton, Wirral, CH46 7TN", 
    "C/O Rpb Chartered Accountants, 22, St. Colmans Park, Newry, County Down, BT34 2BX" 
    ), date_of_cessation = c("2015-11-10", "2015-09-29", "2015-03-17", 
    NA, NA, NA), description = c("08730034 - Dissolved on 10 November 2015", 
    "08902692 - Dissolved on 29 September 2015", "09211826 - Dissolved on 17 March 2015", 
    "09496249 - Incorporated on 18 March 2015", "09669572 - Incorporated on 3 July 2015", 
    "NI633653 - Incorporated on 16 September 2015"), date_of_creation = c("2013-10-14", 
    "2014-02-19", "2014-09-10", "2015-03-18", "2015-07-03", "2015-09-16" 
    ), company_number = c("08730034", "08902692", "09211826", 
    "09496249", "09669572", "NI633653"), company_status = c("dissolved", 
    "dissolved", "dissolved", "active", "active", "active")), .Names = c("title", 
"company_type", "links", "snippet", "date_of_cessation", "description", 
"date_of_creation", "company_number", "company_status"), row.names = c("X1", 
"X2", "X3", "X4", "X5", "X6"), class = "data.frame") 

und für dput (Kopf (sons2)) ist es

structure(list(title = c("SON AND SONS PRODUCTIONS LTD", "SJ AND SONS LTD", 
"DW AND SONS LTD", "PJ AND SONS LTD", "ND AND SONS LTD", "TF AND SONS LTD" 
), company_type = c("ltd", "ltd", "ltd", "ltd", "ltd", "ltd"), 
    links = structure(list(self = c("/company/08730034", "/company/08902692", 
    "/company/09211826", "/company/09496249", "/company/09669572", 
    "/company/NI633653")), .Names = "self", row.names = c(NA, 
    6L), class = "data.frame"), snippet = c("Unit E1, 41 Dace Road, London, E3 2NG", 
    "17 Poundgate Lane, Westwood Heath, Coventry, CV4 8HJ", "60, Hawkins Road, Folkestone, CT19 4JA", 
    "Dalton House, 9 Dalton Square, Lancaster, LA1 1WD", "19 Barnston Lane, Moreton, Wirral, CH46 7TN", 
    "C/O Rpb Chartered Accountants, 22, St. Colmans Park, Newry, County Down, BT34 2BX" 
    ), date_of_cessation = c("2015-11-10", "2015-09-29", "2015-03-17", 
    NA, NA, NA), description = c("08730034 - Dissolved on 10 November 2015", 
    "08902692 - Dissolved on 29 September 2015", "09211826 - Dissolved on 17 March 2015", 
    "09496249 - Incorporated on 18 March 2015", "09669572 - Incorporated on 3 July 2015", 
    "NI633653 - Incorporated on 16 September 2015"), date_of_creation = c("2013-10-14", 
    "2014-02-19", "2014-09-10", "2015-03-18", "2015-07-03", "2015-09-16" 
    ), company_number = c("08730034", "08902692", "09211826", 
    "09496249", "09669572", "NI633653"), company_status = c("dissolved", 
    "dissolved", "dissolved", "active", "active", "active")), .Names = c("title", 
"company_type", "links", "snippet", "date_of_cessation", "description", 
"date_of_creation", "company_number", "company_status"), row.names = c("X101", 
"X102", "X103", "X104", "X105", "X106"), class = "data.frame") 
+0

Fügen Sie die Ausgabe von 'dput (Kopf (Söhne))' und 'dput (Kopf (Söhne2))' zu Ihrer Frage (ersetzen Sie sensible Daten durch alles, was Sie vor dem Posten wollen) – Tensibai

+0

Sind beide Söhne und 'Söhne2' identisch strukturiert (dh' Spaltennamen')? Du sagst, du kannst sie nicht binden, wie sieht 'soes3' aus? ('dput (head (sonses3)))') – r2evans

+0

Ich habe die dput-Ausgänge hinzugefügt. Die Spaltennamen für beide Frames sind identisch. Söhne3 ist leer. –

Antwort

1

Es scheint, dass variable Ihre Links ist als data.frame gespeichert, was das Herz des Problems ist. Um dies zu beheben, verwenden Sie die folgenden Schritte aus:

sons$links <- as.character(unlist(sons$links)) 
sons2$links <- as.character(unlist(sons2$links)) 

Sie müssen möglicherweise auch die rownames ganz entfernen:

row.names(sons) <- NULL 
row.names(sons2)<- NULL 
sons3 <- rbind(sons, sons2) 

Wenn Sie möchten, um sie zu halten, dann speichern Sie sie als Vektoren zuerst. Zusätzlich

Verwandte Themen