[R] delete a row in dataframe w/o changing indexing

Nicolas Gutierrez nicolasg at uw.edu
Tue Feb 8 22:54:21 CET 2011


Hi All,

I'm trying to delete a row from my dataframe "pop" without changing the 
indexing (column 0) as follows:

 >pop

    id birth size xloc yloc weight energy gonad consumed
1   1    36   13   34   43      0     18     0        0
2   2    36   10   39   38      0     18     0        0
3   3    36   10   37   35      0     18     0        0
4   4    36   10   31   25      0     18     0        0
5   5    36   17   34   43      0     18     0        0

By using:

 >i=3
 >pop=pop[-pop$id[i],]

    id birth size xloc yloc weight energy gonad consumed
1   1    36   13   34   43      0     18     0        0
2   2    36   10   39   38      0     18     0        0
4   4    36   10   31   25      0     18     0        0
5   5    36   17   34   43      0     18     0        0

But what I really need is:

    id birth size xloc yloc weight energy gonad consumed
1   1    36   13   34   43      0     18     0        0
2   2    36   10   39   38      0     18     0        0
3   4    36   10   31   25      0     18     0        0
4   5    36   17   34   43      0     18     0        0

*note the first column.

Any ideas?

THANKS!!!!

Nico



More information about the R-help mailing list