0
列
我已經在我的環境無數dataframes:行綁定多個dataframes並添加起始數據幀的名字變成
x1 <- structure(list(time = structure(c(1327241343, 1327327803, 1327414263
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), x1 = c(22.5,
12, 0)), .Names = c("time", "x1"), class = c("tbl_df", "tbl",
"data.frame"), row.names = c(NA, -3L))
x2 <- structure(list(time = structure(c(1326636543, 1326636603, 1326636663
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), x2 = c(8,
6, 1)), .Names = c("time", "x2"), class = c("tbl_df", "tbl",
"data.frame"), row.names = c(NA, -3L))
x3 <- structure(list(time = structure(numeric(0), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), x3 = numeric(0)), .Names = c("time",
"x1"), class = c("tbl_df", "tbl", "data.frame"), row.names = integer(0))
##-----------------------------------------------------------------------------
## PREVIEW
##-----------------------------------------------------------------------------
> knitr::kable(x1)
|time | x1|
|:-------------------|----:|
|2012-01-22 14:09:03 | 22.5|
|2012-01-23 14:10:03 | 12.0|
|2012-01-24 14:11:03 | 0.0|
> knitr::kable(x2)
|time | x2|
|:-------------------|--:|
|2012-01-15 14:09:03 | 8|
|2012-01-15 14:10:03 | 6|
|2012-01-15 14:11:03 | 1|
> knitr::kable(x3)
|time | x1|
|:----|--:|
注意,X3是一個空的數據幀,因爲這反映了我的情況。我想獲得以下行綁定的單數據幀:
x.all <- structure(list(time = structure(c(1327241343, 1327327803, 1327414263,
1326636543, 1326636603, 1326636663), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), x = c(22.5, 12, 0, 8, 6, 1), which = c("x1",
"x1", "x1", "x2", "x2", "x2")), .Names = c("time", "x", "which"
), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-6L))
##-----------------------------------------------------------------------------
## PREVIEW
##-----------------------------------------------------------------------------
> knitr::kable(x.all)
|time | x|which |
|:-------------------|----:|:-----|
|2012-01-22 14:09:03 | 22.5|x1 |
|2012-01-23 14:10:03 | 12.0|x1 |
|2012-01-24 14:11:03 | 0.0|x1 |
|2012-01-15 14:09:03 | 8.0|x2 |
|2012-01-15 14:10:03 | 6.0|x2 |
|2012-01-15 14:11:03 | 1.0|x2 |
我知道如何通過一個做到這一點的。但是,有超過100個數據框,我正在尋找一種有效的方法(每個數據框包含2列和> 500,000行)。
謝謝。
謝謝。這幾乎奏效。你能編輯一個案例,當x變量不能從一個模式構造出來(即'paste0(「x」,1:3)')?很高興接受它作爲答案。 –
'listofdf < - c(「x1」,「x2」,「x3」)'? –