2016-04-19 8 views
-2

私はRで2つのデータフレームをrbindしようとしていますが、「重複した」row.names 'は許可されていません。それらは、それぞれ100行と同じ数の列を持つ2つのデータフレームです。 rbindを使う前に行の名前を定義しようとしましたが、まだエラーが出ます。私はこれを使用しています:これらのデータフレームをRでバインドできないのはなぜですか?

row.names(sons) <- make.names(1:100, unique=TRUE) 
row.names(sons2)<-make.names(101:200, unique = TRUE) 
sons3 <- rbind(sons, sons2) 

私のデータは、UK Companies CompaniesのAPIに由来しています。配列内のエントリは次のようになります。

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 

これらのデータフレームをどのようにバインドできますか?

EDIT:要求され、dputのための出力(ヘッド(息子が))

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

あるとdput(ヘッド(sons2))のために、それは

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

あなたの質問に 'dput(head(sons))'と 'dput(head(sons2))'の出力を追加してください(機密データを投稿する前に何でも置き換えてください) – Tensibai

+0

'sons'と'sons2'も同様に構造化されています(つまり、' colnames')?あなたは彼らを縛ることはできないと言っています。「sons3」のように見えますか? ( 'dput(head(sons3)))') – r2evans

+0

出力を追加しました。両方のフレームのcolnamesは同一です。 sons3は空です。 –

答えて

1

だとして、あなたのリンク変数があることが表示されます問題の核心であるdata.frameとして保存されます。これを修正するには、以下を使用します。

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

また、完全rownamesを削除する必要があります。

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

あなたがそれらを維持したい場合は、最初のベクトルとして保存します。さらに、

関連する問題