Skip to content
Prev 301851 / 398506 Next

Remove a complete row as per the Range in a Matrix

On Jul 31, 2012, at 1:31 AM, Rui Barradas wrote:

            
I think the data.matrix transformation is a bad idea. It forces the  
numeric values to be character and the collation sequence is driven  
off the first letter, so "19" is less than "9", and "1010" is less  
than "2"
Why not just:

myDF <- read.table(text="Name            Age
ANTONY        27
IMRAN           30
RAJ                   22
NAHAS           32
GEO                 42
", header=TRUE)

MinMax <- c(MIN = 25,MAX=35)
# using a named vector rather than a two column dataframe

 > myDF[ myDF$Age > MinMax["MIN"] & myDF$Age < MinMax["MAX"] , ]
     Name Age
1 ANTONY  27
2  IMRAN  30
4  NAHAS  32

-- 
David.