[R] filtering a simple matrix

jim holtman jholtman at gmail.com
Sun Feb 22 21:00:14 CET 2009


Did you read the Introduction to R and the use of indexing to 'filter'?

> x <- read.table(textConnection("a        b         c
+
+ 1        2        23
+ 2        3        42
+ 3        0        54
+ 4        5        23
+ 5        0        22
+ 6        7        21
+ 7        1        20
+ 8        9        19"), header=TRUE)
> closeAllConnections()
>
> x
  a b  c
1 1 2 23
2 2 3 42
3 3 0 54
4 4 5 23
5 5 0 22
6 6 7 21
7 7 1 20
8 8 9 19
> x[x$b > 1,]
  a b  c
1 1 2 23
2 2 3 42
4 4 5 23
6 6 7 21
8 8 9 19


On Sun, Feb 22, 2009 at 1:10 PM, Juan Pablo Fededa <jpfededa at gmail.com> wrote:
> Hi all,
>
> I have the next matrix:
>
>
> a        b         c
>
> 1        2        23
> 2        3        42
> 3        0        54
> 4        5        23
> 5        0        22
> 6        7        21
> 7        1        20
> 8        9        19
>
> I want to filter the rows with the values of b higher than 1 in a way that
> leaves me the next matrix:
>
>
> a        b         c
>
> 1        2        23
> 2        3        42
> 4        5        23
> 6        7        21
> 8        9        19
>
>
> Thanks in advance,
>
>
> Juan
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?




More information about the R-help mailing list