Re: [R] Help : delete at random

From: Marc Schwartz <>
Date: Wed 02 Mar 2005 - 01:28:25 EST

On Tue, 2005-03-01 at 15:04 +0100, Caroline TRUNTZER wrote:
> Hello
> I would like to delete some values at random in a data frame. Does
> anyone know how I could do?
> With best regards

> Caroline

The basic process is to randomly select row indices from the possible number of rows. If your data frame is 'df' and you want to randomly delete 10 rows: <- df[-sample(1:nrow(df), 10), ]

The sample() function in this case randomly selects 10 values in the range 1:nrow(df). Using the '-' then removes these rows in the subsetting process, returning the new, smaller, data frame in

See ?sample and ?Extract for more information.

HTH, Marc Schwartz mailing list PLEASE do read the posting guide! Received on Wed Mar 02 01:53:26 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:38 EST