[R] removing particular row from matrix

Sarah Goslee sarah.goslee at gmail.com
Wed Feb 22 20:28:19 CET 2012


Is this not what you want:

a[a[,2] != -999.99,]

I didn't see the earlier message so I'm not sure how rowSums
was involved.

Sarah

On Wed, Feb 22, 2012 at 1:50 PM, uday <uday_143_4u at hotmail.com> wrote:
> Hi Petr,
> Thanks for reply
>
> sorry for late message there was typo error the both values are -999.99
>  a[rowSums(a ==  -999.99) == 0, ], this solution works only if we have to
> remove certain value from matrix.
>
> but if
> a<-matrix(c(1,2,3,5,-999.99,5,-999.99,6,1,5,9,1),nrow=4)
>
> a
>     [,1]    [,2] [,3]
> [1,]    1 -999.99    1
> [2,]    2    5.00    5
> [3,]    3 -999.99    9
> [4,]    5    6.00    1
>
> and I would like to remove whole row those have value -999.99 , this
> particular function does not work
> I got error
>
> Error in rowSums(a[, 2] == -999.99) :
>  'x' must be an array of at least two dimensions
>
>  it need matrix, so is there any way to deal with this kind of problem.
>
>
> Cheers
> Uday
>


-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list