Learn R Programming

quickcode (version 1.0.6)

data_shuffle: Shuffle a data frame just like shuffle in PHP

Description

Shorthand to shuffle a data frame and save

Usage

data_shuffle(., which = c("rows", "cols"), seed = NULL)

Value

shuffled data frame of items store to the data frame name

Arguments

.

data to shuffle as data frame

which

what to shuffle, rows or columns

seed

apply seed if indicated for reproducibility

Examples

Run this code

#basic example
data.frame(ID=46:55,PK=c(rep("Treatment",5),rep("Placebo",5))) #before
data_shuffle(
  data.frame(ID=46:55,PK=c(rep("Treatment",5),rep("Placebo",5)))
) #after shuffle row
data_shuffle(
  data.frame(ID=46:55,PK=c(rep("Treatment",5),rep("Placebo",5))),
  which = "cols"
) #after shuffle column


# examples using object
df1<-data.frame(ID=46:55,PK=c(rep("Treatment",5),rep("Placebo",5)))

#illustrate basic functionality
data_shuffle(df1)
df1 #shuffle and resaved to variable

data.f2<-df1
data_shuffle(data.f2)
data.f2 #first output

data.f2<-df1
data_shuffle(data.f2)
data.f2 # different output from first output top

data.f2<-df1
data_shuffle(data.f2,seed = 344L)
data.f2 #second output

data.f2<-df1
data_shuffle(data.f2,seed = 344L)
data.f2 #the same output as second output top

Run the code above in your browser using DataLab