R Sorting Matrix name, including 1 string but excluding the other
<p>I am currently trying to sort a matrix, and for the life of me can't figure out how to do this. I have rownames that consist of 2 words, and I want to be able to compare them by sorting these 2 words. Currently I am able to use grep to sort for the 2 words that I want. Here is a quick example.</p>

<pre><code>x &lt;- matrix(NA,nrow=12,ncol=2)
multi &lt;- 4
colour &lt;- c("Red","Blue","Dark Blue")
colour &lt;- as.vector(sapply(colour,function(y) rep(y,multi)))
food &lt;- c("Water","Milk","Juice")
food &lt;- as.vector(t(sapply(food,function(y) rep(y,multi))))
rownames(x) &lt;- paste(food,colour,sep=" ,")

Milk &lt;- x[grep(paste0("^Milk ,","Blue$"),rownames(x)),]
</code></pre>

<p>What I am trying to do now from the above example, is find a way to sort for everything except "Milk", but still have the colour "Blue". Any ideas?</p>

<p>This is the current output</p>

<pre><code>            [,1] [,2]
Milk ,Blue   NA   NA
Milk ,Blue   NA   NA
</code></pre>

<p>What I would like is this. It would need to be able to differentiate between "Blue" and "Dark Blue".</p>

<pre><code>       [,1] [,2]
Water ,Blue   NA   NA
Juice ,Blue   NA   NA
</code></pre>