Skip to content
Prev 107985 / 398498 Next

Query about extracting subsets from a table

On Tue, 2007-01-23 at 09:28 -0800, lalitha viswanath wrote:
help.search("subset") would lead you to ?subset, where you could do
something like:

DF <- subset(YourData, log10escore < -3)

If you just wanted the values of the two other columns, you could also
use:

DF <- subset(YourData, log10escore < -3, 
             select = c(genomenames, treedist))


One additional alternative is to use which(). This will return the
_indices_ of the values that match the criteria.  For example:

  Ind <- which(YourData$log10escore < -3)

In that case, you could then use:

  YourData$genomename[Ind]

and 
 
  YourData$treedist[Ind]

These would return vectors of the two columns meeting the criteria. 

Which approach you take depends upon what else you may want to do with
the data.

See ?which for more information.

HTH,

Marc Schwartz