# [R] Remove a complete row as per the Range in a Matrix

arun smartpink111 at yahoo.com
Tue Jul 31 14:48:33 CEST 2012

```Hi,
Try this:
Name            Age
ANTONY        27
IMRAN          30
RAJ                  22
NAHAS          32
GEO                42
MinMaxArray  <- data.frame(MIN = 25,MAX=35)
myMatrix[myMatrix\$Age<=MinMaxArray\$MAX & myMatrix\$Age>=MinMaxArray\$MIN,]
#  Name Age
#1 ANTONY  27
#2  IMRAN  30
#4  NAHAS  32

#or
subset(myMatrix,myMatrix\$Age<=MinMaxArray\$MAX & myMatrix\$Age>=MinMaxArray\$MIN)
#    Name Age
#1 ANTONY  27
#2  IMRAN  30
#4  NAHAS  32

A.K.

----- Original Message -----
From: Rantony <antony.akkara at ge.com>
To: r-help at r-project.org
Cc:
Sent: Tuesday, July 31, 2012 3:58 AM
Subject: [R] Remove a complete row as per the Range in a Matrix

Hi,

Here i have a Matrix

MyMatrix <-

Name            Age
---------           -------
ANTONY        27
IMRAN           30
RAJ                   22
NAHAS           32
GEO                 42

and here i have an array with Minimum and Maximum values.
MinMaxArray  <- data.frame(MIN = 25,MAX=35)
MIN     MAX
------     --------
25           35
------------------------------------------------------
Now what is, i need to get a matrix by removing the rows which is NOT coming
the "Age"-column in between the MIN and MAX value.  Is it possible to avoid
"for-loop", bcz its a huge matrix.

so, final matrix looks like this,

Name            Age
---------           -------
ANTONY        27
IMRAN           30
NAHAS           32

Antony.

--
View this message in context: http://r.789695.n4.nabble.com/Remove-a-complete-row-as-per-the-Range-in-a-Matrix-tp4638508.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help