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

David Winsemius dwinsemius at comcast.net
Tue Feb 8 23:21:29 CET 2011


On Feb 8, 2011, at 4:54 PM, Nicolas Gutierrez wrote:

> 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:

Then do this:

row.names(pop) <- NULL

>
>   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!!!!
>

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list