Skip to content

Extract rows from a matrix according to value in column

2 messages · Sverre Stausland, Ista Zahn

#
Dear helpers,

I'm trying to extract certain rows from a matrix according to the
values the rows have in a certain column. I've been googling for a
while without result.

Here's a reproducible example of a matrix (and the one I was playing
with initially):
[1] "matrix"

I can extract according to rows and column positions:
[1] "0.1"

But how can I extract the rows according to their values in a column,
when $ is not usable for vector matrices? Say I would like all the
rows where the value in the column "Version" is "0.1" (as above). For
a data frame, I would have done it like this:
Error in avail.pack$Version : $ operator is invalid for atomic vectors

Also, thanks to those who responded to my recent question in
https://stat.ethz.ch/pipermail/r-help/2011-August/285650.html (I
assume it's best not to respond at the end of threads with a "thank
you" only, to avoid cluttering people's inboxes?)

best
Sverre
#
Hi Sverre,

On Tue, Aug 2, 2011 at 10:22 PM, Sverre Stausland
<johnsen at fas.harvard.edu> wrote:
Use [ instead of $, like this:

avail.pack[avail.pack[, "Version"] == "0.1", ]

best,
Ista