Skip to content

Randomizing one column in the dataMatrix

2 messages · mogra, Marc Schwartz

#
On Thu, 2007-12-06 at 09:45 -0800, mogra wrote:
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