我有一個data.frame又包含data.frames,現在使用rbind上的兩個相同的組(例如rbind(k,k)
)這個數據的引發錯誤:Rbind,數據幀內有數據幀會導致錯誤?
Error in xpdrows.data.frame(x, rows, new.rows) : number of items to replace is not a multiple of replacement length
下面是與所述對象的結構數據。
> str(k)
'data.frame': 25 obs. of 18 variables:
$ location :'data.frame': 25 obs. of 5 variables:
..$ address :'data.frame': 25 obs. of 1 variable:
.. ..$ streetAddress: chr "Astrakangatan 110A" "Västmannagatan 85C" "Doktor Abelins gata 6" "Standarvägen 1" ...
..$ position :'data.frame': 25 obs. of 2 variables:
.. ..$ latitude : num 59.4 59.3 59.3 59.3 59.3 ...
.. ..$ longitude: num 17.8 18 18.1 18 18 ...
..$ namedAreas:List of 25
.. ..$ : chr "Hässelby"
.. ..$ : chr "Vasastan"
.. ..$ : chr "Södermalm"
.. ..$ : chr "Gamla Älvsjö"
.. ..$ : chr "Fruängen-Hägersten"
.. ..$ : chr "Södermalm"
.. ..$ : chr "Kungsholmen"
.. ..$ : chr "Fruängen"
.. ..$ : chr "Årsta"
.. ..$ : chr "Telefonplan"
.. ..$ : chr "Kista"
.. ..$ : chr "Östberga"
.. ..$ : chr "Hägerstensåsen"
.. ..$ : chr "Östermalm"
.. ..$ : chr "Årsta"
.. ..$ : chr "Bromma Blackeberg"
.. ..$ : chr "Similar Listings Overwritten Here"
.. ..$ : chr "Traneberg"
.. ..$ : chr "Kungsholmen"
.. ..$ : chr "Skärholmen"
.. ..$ : chr "Katarina"
.. ..$ : chr "Farsta stadsdelsområde"
.. ..$ : chr "Kista"
.. ..$ : chr "Bromma"
.. ..$ : chr "Akalla"
..$ region :'data.frame': 25 obs. of 2 variables:
.. ..$ municipalityName: chr "Stockholm" "Stockholm" "Stockholm" "Stockholm" ...
.. ..$ countyName : chr "Stockholms län" "Stockholms län" "Stockholms län" "Stockholms län" ...
..$ distance :'data.frame': 25 obs. of 1 variable:
.. ..$ ocean: int NA 2325 1223 6360 NA 329 2630 NA 2837 5537 ...
$ listPrice : int 1900000 4100000 4875000 2950000 1995000 1395000 2450000 2250000 2550000 1995000 ...
$ rent : int 4678 1586 3092 3983 2587 520 1437 3644 2936 2707 ...
$ floor : num 1 1 NA 1 3 0.5 1 6 3 NA ...
$ livingArea : num 60 40 70 91 37 11 28 59 54 42 ...
$ source :'data.frame': 25 obs. of 4 variables:
..$ name: chr "HusmanHagberg" "BOSTHLM" "Gripsholms Fastighetsförmedling" "Fastighetsbyrån" ...
..$ id : int 1610 1499 9895524 1573 58 713 2091 1566 1566 1566 ...
..$ type: chr "Broker" "Broker" "Broker" "Broker" ...
..$ url : chr "http://www.husmanhagberg.se/" "http://www.bosthlm.se/" "http://gripsholms.se/" "http://www.fastighetsbyran.se/" ...
$ rooms : num 2 2 2.5 3.5 2 1 1 2 2 2 ...
$ published : Date, format: "2015-07-17" "2015-07-16" "2015-07-15" "2015-07-10" ...
$ constructionYear : int 2006 NA 1929 1937 NA 1929 1930 2014 1949 1944 ...
$ objectType : chr "Lägenhet" "Lägenhet" "Lägenhet" "Lägenhet" ...
$ booliId : int 1920703 1919949 1896584 1917520 1918145 1918049 1917638 1849399 1916805 1826479 ...
$ soldDate : Date, format: "2015-07-21" "2015-07-19" "2015-07-20" "2015-07-20" ...
$ soldPrice : int 2000000 4100000 5175000 4200000 2500000 1850000 2820000 2600000 2900000 2230000 ...
$ url : chr "https://www.booli.se/bostad/lagenhet/hasselby/astrakangatan+110a/1920703" "https://www.booli.se/bostad/lagenhet/vasastan/vastmannagatan+85c/1919949" "https://www.booli.se/bostad/lagenhet/sodermalm/doktor+abelins+gata+6/1896584" "https://www.booli.se/bostad/lagenhet/gamla+alvsjo/standarvagen+1/1917520" ...
$ isNewConstruction: int NA NA NA NA NA NA NA NA NA NA ...
$ plotArea : int NA NA NA NA 0 NA NA NA NA NA ...
$ AreaSize : Factor w/ 10 levels "10","20","30",..: 6 4 7 9 3 1 2 5 5 4 ...
$ PriceDiff : int 100000 0 300000 1250000 505000 455000 370000 350000 350000 235000 ...
正在數據幀內使用數據幀生病嗎?還是我犯了一個錯誤?
@SimonG,Answer很好。但是我絆倒了一個非唯一的行名錯誤。現在使用nrbind()
適用於單個列或數據框,但運行整個data.frame時不會運行。即使我用row.names
更改了rownames,它仍會拋出錯誤。
> nrbind <- function(x,y) if(is.data.frame(x)) rbind(x,y) else c(x,y)
> as.data.frame(mapply(nrbind, k, k))
Show Traceback
Rerun with Debug
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’, ‘21’, ‘22’, ‘23’, ‘24’, ‘25’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’
我只看到你的數據框包含多層嵌套。我已在下面更新了我的答案。 – SimonG