[R] manipulating a matrix

Erik Iverson eriki at ccbr.umn.edu
Wed May 12 21:22:24 CEST 2010



Clark Johnston wrote:
> Is there a way to create a new matrix from and existing matrix with
> 
> A
>           [,1]     [,2]
> [1,]      1        13
> [2.]      2        18 
> [3,]      3        14
> [4,]      4        20
> 
> if(A[,2] > 15)
>    
> B
>        [,1]   [,2]    
> [1,]   2      18
> [2,]   4      20
> 
> 

It's easiest to get help if you give your objects as the output from ?dput.

This is just simple indexing:

B <- A[A[, 2] > 15, ]



More information about the R-help mailing list