Skip to content

Kedai-Cheng/Random-Grouping

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Instructions:

random.group is a function that assigns elements into groups randomly without replacement. There are 2 arguments:

  • data: is a vector of numerical values.
  • size: is the targeted size of each group.

If elements are allocated evenly into groups, random.group generates a matrix with each row representing a group. If elements are not evenly allocated and there are leftover elements, random.group generates two lists.

  • List 1 shows group assignments with targeted groups size. Each row represents for a group.
  • List 2 shows any leftover elements.

Examples:

#################
### Example 1 ###
#################
data <- seq(from = 1 , to = 30)
size <- 7
groups <- random.group(data = data , size = size)
print(groups)

#################
### Example 2 ###
#################
data <- seq(from = 1 , to = 30)
size <- 6
groups <- random.group(data = data , size = size)
print(groups)

#################
### Example 3 ###
#################
n.objects <- 21
roster <- data.frame(cbind(paste0("FirstName", 1:n.objects),
                           paste0("LastName", 1:n.objects)))

data <- seq(from = 1 , to = dim(roster)[1] , by = 1)
size <- 6

groups <- random.group(data = data , size = size)

for (i in 1:dim(groups[[1]])[1]){
  print(roster[(groups[[1]][i,]),])
}

print(roster[(groups[[2]]),])

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages