From ggrothendieck at myway.com  Sun Feb 20 17:16:15 2005
From: ggrothendieck at myway.com (Gabor Grothendieck)
Date: Sun Feb 20 17:20:04 2005
Subject: [Rd] matrix operations
References: <52ea15e4ad9646d0c54ac9a29d2d906b@mac.com>
Message-ID: <loom.20050220T171039-337@post.gmane.org>

Melanie Vida <mvida <at> mac.com> writes:

: 
: In R, I'm imported a data frame of  2,321,123 by 4 called "dataF".
: I converted the data frame "dataF" to a matrix
: 
: dataM <- as.matrix(dataF)
: 
: Does R have an efficient routine to treat the special elements that 
: contain "inf" in them. For example, can you separate the rows that have 
: "inf" elements from the matrix into a separate matrix without iterating 
: over the entire matrix?

This will eliminate all rows that contain Inf or -Inf.

m[apply(is.finite(m), 1, all),]

: 
: Also, does R have an efficient way to sort columns in a matrix?

This can be interpreted a number of different ways:

See
?order
?sort

m[order(m[,1]),] # sorts so that column 1 is sorted and rows stay together
apply(m, 2, sort) # sort each column separately


[Rd] matrix operations
Gabor Grothendieck