This might help:
repcbind <- function(x,y) {
nx <- nrow(x)
ny <- nrow(y)
if (nx<ny)
x <- apply(x,2,rep,length=ny)
else if (ny<nx)
y <- apply(y,2,rep,length=nx)
cbind(x,y)
}
Someone else may well have a shorter/faster/sneakier/more robust/more
general way of doing this, but this at least seems to work for your
example. (Presumably, if someone thought it was a good idea, there could
be a switch on cbind that explicitly allowed for combinations of
unequal-length matrices: as now implemented and documented, cbind will
replicate unequal-length vectors to match the longest vector or the number
of rows of any matrix arguments, but all matrices must have the same
number of rows.)
There might be some slick way of doing this with do.call("cbind",...),
but
I can't figure out a way that doesn't coerce everything to characters.
By the way: there's a trivial typographic error on l. 2 of para. 3 of
"Details" ("rosw" instead of "rows") in the
documentation.
On Thu, 22 Jun 2000, Stephen Arthur wrote:
> Hi,
>
> Is there a function (a way) to merge to files in R, as could be done in
> SAS?
>
> Example Data:
>
> File1
>
> C A T
>
> File2
>
> 1 2 34 56
> 2 3 45 67
> 3 4 56 78
>
> To Yield:
>
> C A T 1 2 34 56
> C A T 2 3 45 67
> C A T 3 4 56 78
>
> functions merge, cbind don't seem to do the trick.
>
> Thanks,
>
> steve
>
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
>
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._