【发布时间】:2013-12-16 03:20:20
【问题描述】:
我有两个如下所示的数据框:
d1 <- data.frame(h1 = c("foo","foo","bar","bar"), h2= c("a","b","c","d"), h3=c("x1","x2","x3","x4"))
哪些打印:
h1 h2 h3
1 foo a x1
2 foo b x2
3 bar c x3
4 bar d x4
还有
d2 <- data.frame(t1= c("a","b","c","d"), t2=c("x1","x2","x3","x4"),val=(rnorm(4)))
产生:
t1 t2 val
1 a x1 -1.183606
2 b x2 -1.358457
3 c x3 -1.512671
4 d x4 -1.253105
# surely the val columns will differ since we use rnorm()
我想要做的是基于d1中的h2-h3和d2中的t1-t2列组合d1和d2, 导致
foo a x1 -1.183606
foo b x2 -1.358457
bar c x3 -1.512671
bar d x4 -1.253105
有什么办法呢?
【问题讨论】: