[R] Use of results in summary

Emmanuel Paradis paradis at isem.univ-montp2.fr
Thu Feb 28 15:15:49 CET 2002


At 12:24 28/02/02 +0100, you wrote:
>Dear R Community,
>
>When making a summary with a vector, the result is "numeric" and I can
>recall its components (like median, mean, etc.) for further use.
>However, if I use summary with a matrix, the result is of mode
>"character" (like  "Median : 1.2127") and I cannot extract the results
>for direct further use.
>Thanks for any hints,
>
>Patrick
>
>Attachment Converted: "C:\data\_exchange\patrick1.vcf"
>

Here is a suggestion. Note that it displays a warning since it uses NAs,
this display can be avoided by switching off the appropriate option
(`options("warn" = -1)').

my.summary.matrix <- function(M)
{
    if (!is.matrix(M)) stop("object \"M\" is not a matrix")
    S <- summary(M)
    V <- unlist(strsplit(S, ":"))
    V2 <- as.numeric(V)
    Q <- V2[!is.na(V2)]
    dim(Q) <- dim(S)
    rownames(Q) <- V[is.na(V2)][1:6]
    colnames(Q) <- colnames(S)
    return(Q)
}

This function returns a numeric matrix with the summaries (min, 1st Q.,
...) as rownames, and the names of the variables as colnames. (I have not
tested it extensively.)

Emmanuel Paradis
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list