-1

I have a matrix such as:

> ex2
      [,1] [,2]     [,3]     [,4]        [,5]
 [1,]    1 1912 55.40000 49.06132   6.3386825
 [2,]    9 1944 53.76998 46.90905   6.8609322
 [3,]   10 1948 52.31764 48.65840   3.6592392
 [4,]   11 1952 44.71056 50.34861  -5.6380584
 [5,]   13 1960 50.08676 47.58916   2.4975960
 [6,]   15 1968 49.59538 57.16136  -7.5659793
 [7,]   17 1976 51.05214 43.28484   7.7672977
 [8,]   18 1980 44.69676 57.55835 -12.8615819
 [9,]   23 2000 50.26476 49.67494   0.5898139
[10,]   25 2008 53.68885 49.11433   4.5745194

I want to delete the row with the values related to year 2000 (So, in this case, I want to delete row 9).

The matrix does not necessarily contain the values for 2000. For example, it may be:

> ex3
     [,1] [,2]     [,3]     [,4]     [,5]
[1,]   13 1960 50.08676 43.08453 7.002226
[2,]   25 2008 53.68885 49.92650 3.762

Thanks in advance.

thetax
  • 111
  • 3
  • 15

2 Answers2

0

Use regular subset rules. For instance:

ex2[ex2[,2]!=2000,]

which means "take all the rows that have the second column different from 2000".

nicola
  • 24,005
  • 3
  • 35
  • 56
-1
if(2000%in%ex2[,2]){
  newdata=ex2[-which(ex2[,2]==2000),]
}
Bambs
  • 545
  • 4
  • 14