Skip to content
Back to formatted view

Raw Message

Message-ID: <1196969984.2955.100.camel@Bellerophon.localdomain>
Date: 2007-12-06T19:39:44Z
From: Marc Schwartz
Subject: Randomizing one column in the dataMatrix
In-Reply-To: <14197423.post@talk.nabble.com>

On Thu, 2007-12-06 at 09:45 -0800, mogra wrote:
> I have huge data file, and I would like randomize just one column at a time ,
> is there any easy way?
> 
> Thanks a lot.

If you just want to randomly <hint> sample <\hint> from a single column,
_independent of the other columns_, you can use:

  DF$Column[sample(nrow(DF))]

where DF$Column is the column of interest in your data frame 'DF'.

If you want to randomly sample entire rows from 'DF', you can use:

  DF[sample(nrow(DF)), ]

See ?sample for more information.

HTH,

Marc Schwartz