Hi,
I often need to take columns from two data.frames and 'splice' them
together (alternately taking a column from the first data frame, then
from the second). For example:
x - table(sample(letters[1:9], 100, replace=TRUE),
sample(letters[1:4], 100, replace=TRUE))
y - prop.table(x)
what about:
@
*=
z-data.frame(matrix(rbind(x,y),nrow(x),2*ncol(x)))
rownames(z)-rownames(x)
z
@
output-start
Thu Aug 25 11:24:29 2005
X1 X2 X3 X4 X5 X6 X7 X8
a 2 0.02 1 0.01 2 0.02 2 0.02
b 3 0.03 0 0.00 4 0.04 3 0.03
c 3 0.03 2 0.02 1 0.01 6 0.06
d 3 0.03 4 0.04 2 0.02
Thank you! I think I can simplify the first line further to:
z-data.frame(matrix(rbind(x,y),nrow(x)))
i.e. remove 2 * ncol(x)
Thanks.
Dave
Peter Wolf wrote:
what about:
@
*=
z-data.frame(matrix(rbind(x,y),nrow(x),2*ncol(x)))
rownames(z)-rownames(x)
z
@
output-start
Thu Aug 25