[R] removing particular row from matrix

S Ellison S.Ellison at LGCGroup.com
Thu Feb 23 12:53:41 CET 2012


 

> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of uday

> Error in rowSums(a[, 2] == -999.99) : 
>   'x' must be an array of at least two dimensions
Indeed it must - but you have asked for rowSums on a one-dimensinal object (a[,2]). You didn;t need to sum the rows of that.

Try
a[ a[,2] != -999 , ]

assuming that the column is integer or that you have read the Note on finite representation of ractions in ?Comparison and are willing to take your chances, or 

a[ a[,2] > -998 , ]
if it's not and if it's safe to assume that all large negative numbers are 'missing'.

Better still, if you read the data using read.table, use na.strings=c('"-999", "NA") . That will mark "-999" as missing data. An na.omit will then remove the offending rows (but also those that contain NAs of thre reasons.

S*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}



More information about the R-help mailing list