data.frames 不同长度的哑 rbind
Dumb rbind for data.frames of different length
我不需要任何 smart rbind
,例如 rbindlist
、rbind.fill
、bind_row
和其他。
我需要一个笨蛋 rbind
来简单地绑定两个数据帧:
> a <- data.frame(a = 1:3)
> b <- data.frame(b = 1:2)
> some.magic.bind(a, b) # what function to use here?
a b
1 1 1
2 2 2
3 3 NA
你想要 cbind
而不是 rbind
。
尝试:
a = c(1:3)
b = c(1:2)
length(b) = length(a)
cbind(a, b)
merge
直接作用于两个不同长度的 data.frame
并将其保留为 data.frame
:
merge(a,b,by="row.names",all.x=TRUE)[,-1]
a b
1 1 1
2 2 2
3 3 NA
我不需要任何 smart rbind
,例如 rbindlist
、rbind.fill
、bind_row
和其他。
我需要一个笨蛋 rbind
来简单地绑定两个数据帧:
> a <- data.frame(a = 1:3)
> b <- data.frame(b = 1:2)
> some.magic.bind(a, b) # what function to use here?
a b
1 1 1
2 2 2
3 3 NA
你想要 cbind
而不是 rbind
。
尝试:
a = c(1:3)
b = c(1:2)
length(b) = length(a)
cbind(a, b)
merge
直接作用于两个不同长度的 data.frame
并将其保留为 data.frame
:
merge(a,b,by="row.names",all.x=TRUE)[,-1]
a b
1 1 1
2 2 2
3 3 NA