2016-08-25 6 views
0

のデータフレームにrbind使用して、私はこれで問題のビットに実行しています:R - データフレーム

> dput(df1) 

structure(list(`1` = structure(list(type = c("Player", "Player", 
"Player"), value = c(2980668L, 2980676L, 2980670L)), .Names = c("type", 
"value"), row.names = c(NA, 3L), class = "data.frame"), `2` = structure(list(
    type = c("Player", NA, "Player"), value = c(NA, NA, 419405L 
    )), .Names = c("type", "value"), row.names = c(NA, 3L), class = "data.frame"), 
    `26` = structure(list(type = c(NA_character_, NA_character_, 
    NA_character_), value = structure(list(coordinates = structure(list(
     x = c(0.90043921853644, NA, NA), y = c(0.40441176470588, 
     NA, NA)), .Names = c("x", "y"), row.names = c(NA, 3L), class = "data.frame"), 
     region = c(2L, NA, NA)), .Names = c("coordinates", "region" 
    ), row.names = c(NA, 3L), class = "data.frame")), .Names = c("type", 
    "value"), row.names = c(NA, 3L), class = "data.frame"), `36` = structure(list(
     type = c(NA, NA, NA), value = c("Unknown", NA, NA)), .Names = c("type", 
    "value"), row.names = c(NA, 3L), class = "data.frame")), .Names = c("1", 
"2", "26", "36"), class = "data.frame", row.names = c("200001", 
"200002", "200003")) 


> dput(df2) 
structure(list(`1` = structure(list(type = c("Player", "Player", 
"Player"), value = c(2980668L, 2980676L, 2980670L)), .Names = c("type", 
"value"), row.names = c(NA, 3L), class = "data.frame"), `2` = structure(list(
    type = c("Player", NA, "Player"), value = c(NA, NA, 419405L 
    )), .Names = c("type", "value"), row.names = c(NA, 3L), class = "data.frame"), 
    `26` = structure(list(type = c(NA_character_, NA_character_, 
    NA_character_), value = structure(list(coordinates = structure(list(
     x = c(0.90043921853644, NA, NA), y = c(0.40441176470588, 
     NA, NA)), .Names = c("x", "y"), row.names = c(NA, 3L), class = "data.frame"), 
     region = c(2L, NA, NA)), .Names = c("coordinates", "region" 
    ), row.names = c(NA, 3L), class = "data.frame")), .Names = c("type", 
    "value"), row.names = c(NA, 3L), class = "data.frame"), `36` = structure(list(
     type = c(NA, NA, NA), value = c("Unknown", NA, NA)), .Names = c("type", 
    "value"), row.names = c(NA, 3L), class = "data.frame")), .Names = c("1", 
"2", "26", "36"), class = "data.frame", row.names = c("200004", 
"200005", "200006")). 

これらは私が一緒にrbind()にしようとしている例のデータフレームです。この例の場合、rownames以外のものはすべて同じです。私は2つ上rbind()を実行しようとすると、私は次のエラーを取得:私はこのrbind()作品を作ることができる方法についての

> rbind(temp, temp2) 
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’, ‘2’, ‘3’ 

任意の考えをいただければ幸いです、ありがとう!

+0

からデータを抽出することです、temp2、make.row.names = FALSE) ' – Sathish

+0

ありがとうございましたが、それらの提案のいずれかで運がありません – Canovice

+1

この構造はかなり厄介です。私は内側のdata.framesを 'rbind'の前に単一のdata.frameに抽出することを提案します – lmo

答えて

0

別のアプローチは、 `rbind(温度、TEMP2、make.row.names = TRUE) 'または' rbind(TEMPを試してみて、一緒にすべてのオリジナルJSONsに参加そこ

library(jsonlite) 
json1 <- toJSON(df1) 
json2 <- toJSON(df2) 

df <- fromJSON(paste(substr(json1, 1, nchar(json1)-1),substr(json2, 2, nchar(json2)), sep = ",")) 
df 
# 1.type 1.value 2.type 2.value 26.value.coordinates.x 26.value.coordinates.y 26.value.region value 
# 1 Player 2980668 Player  NA     0.9004     0.4044    2 Unknown 
# 2 Player 2980676 <NA>  NA      NA      NA    NA <NA> 
# 3 Player 2980670 Player 419405      NA      NA    NA <NA> 
# 4 Player 2980668 Player  NA     0.9004     0.4044    2 Unknown 
# 5 Player 2980676 <NA>  NA      NA      NA    NA <NA> 
# 6 Player 2980670 Player 419405      NA      NA    NA <NA>