2

I have a dataframe which have one column like this:

> df$stocks
1 stock1
2 stock2
3 stock3
4 stock4

Is there any function which changes randomly the order of rows when I execute it like the first time I execute it the result of the data frame will be:

 > df$stocks
    1 stock2
    2 stock1
    3 stock4
    4 stock3

The next time will be something different etc.

Berbery
  • 297
  • 2
  • 4
  • 12

1 Answers1

3

We can use sample

df$name[sample(nrow(df))]
akrun
  • 874,273
  • 37
  • 540
  • 662