[R] Remove a complete row as per the Range in a Matrix
Rui Barradas
ruipbarradas at sapo.pt
Tue Jul 31 10:31:29 CEST 2012
Hello,
Please learn how to use dput(), it's not your first post.
And try the following.
myMatrix <- data.matrix(read.table(text="
Name Age
ANTONY 27
IMRAN 30
RAJ 22
NAHAS 32
GEO 42
", header=TRUE))
MinMaxArray <- data.frame(MIN = 25,MAX=35)
inx <- MinMaxArray[[ "MIN" ]] <= myMatrix[, "Age"] & myMatrix[, "Age"]
<= MinMaxArray[[ "MAX" ]]
myMatrix[ inx , ]
Hope this helps,
Rui Barradas
Em 31-07-2012 08:58, Rantony escreveu:
> 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
>
>
> - Thanks in advance,
> 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
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list