[R] How two compare two matrixes
William Dunlap
wdunlap at tibco.com
Fri Mar 4 19:02:05 CET 2011
I sometimes use the enclosed sideBySide() function to
look at two printouts (of any sort of objects) in
parallel. Perhaps that would help.
sideBySide <- function (a, b, argNames)
{
oldWidth <- options(width = getOption("width")/2 - 4)
on.exit(options(oldWidth))
if (missing(argNames)) {
argNames <- c(deparse(substitute(a))[1],
deparse(substitute(b))[1])
}
pa <- capture.output(print(a))
pb <- capture.output(print(b))
nlines <- max(length(pa), length(pb))
length(pa) <- nlines
length(pb) <- nlines
pb[is.na(pb)] <- ""
pa[is.na(pa)] <- ""
retval <- cbind(pa, pb, deparse.level = 0)
dimnames(retval) <- list(rep("", nrow(retval)), argNames)
noquote(retval)
}
Try:
> x1 <- matrix(sort(rnorm(100)),10,10)
> x2 <- matrix(sort(rnorm(100)),10,10)
> sideBySide(x1,x2)
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
> -----Original Message-----
> From: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] On Behalf Of Alaios
> Sent: Thursday, March 03, 2011 11:42 PM
> To: R-help at r-project.org
> Subject: [R] How two compare two matrixes
>
> Dear all I have two 10*10 matrixes and I would like to
> compare theirs contents. By the word content I mean to check
> visually (not with any mathematical formulation) how similar
> are the contents.
>
> I also know edit that prints my matrix in the scree but still
> one edit blocks the prompt to launch a second edit() screen.
>
> What is the best way to compare these two matrices?
>
> I would like to thank you in avdance for your help
>
> Regards
> Alex
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list