[R] Randomizing one column in the dataMatrix

Marc Schwartz marc_schwartz at comcast.net
Thu Dec 6 20:39:44 CET 2007


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



More information about the R-help mailing list