Shorthand to shuffle a data frame and save
Usage
data_shuffle(., which = c("rows", "cols"), seed = NULL)
Arguments
- .
data to shuffle as data frame
- which
what to shuffle, rows or columns
- seed
apply seed if indicated for reproducibility
Examples
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
#> ID PK
#> 3 48 Treatment
#> 9 54 Placebo
#> 8 53 Placebo
#> 4 49 Treatment
#> 5 50 Treatment
#> 6 51 Placebo
#> 1 46 Treatment
#> 2 47 Treatment
#> 10 55 Placebo
#> 7 52 Placebo
data.f2<-df1
data_shuffle(data.f2)
data.f2 #first output
#> ID PK
#> 6 51 Placebo
#> 7 52 Placebo
#> 5 50 Treatment
#> 8 53 Placebo
#> 2 47 Treatment
#> 3 48 Treatment
#> 10 55 Placebo
#> 4 49 Treatment
#> 1 46 Treatment
#> 9 54 Placebo
data.f2<-df1
data_shuffle(data.f2)
data.f2 # different output from first output top
#> ID PK
#> 9 54 Placebo
#> 6 51 Placebo
#> 7 52 Placebo
#> 10 55 Placebo
#> 4 49 Treatment
#> 2 47 Treatment
#> 8 53 Placebo
#> 5 50 Treatment
#> 3 48 Treatment
#> 1 46 Treatment
data.f2<-df1
data_shuffle(data.f2,seed = 344L)
data.f2 #second output
#> ID PK
#> 8 53 Placebo
#> 3 48 Treatment
#> 6 51 Placebo
#> 10 55 Placebo
#> 9 54 Placebo
#> 2 47 Treatment
#> 7 52 Placebo
#> 5 50 Treatment
#> 1 46 Treatment
#> 4 49 Treatment
data.f2<-df1
data_shuffle(data.f2,seed = 344L)
data.f2 #the same output as second output top
#> ID PK
#> 8 53 Placebo
#> 3 48 Treatment
#> 6 51 Placebo
#> 10 55 Placebo
#> 9 54 Placebo
#> 2 47 Treatment
#> 7 52 Placebo
#> 5 50 Treatment
#> 1 46 Treatment
#> 4 49 Treatment