-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom.group.R
More file actions
26 lines (26 loc) · 759 Bytes
/
random.group.R
File metadata and controls
26 lines (26 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
random.group <- function(data , size){
### If original data size is smaller than group size ###
if (length(data) < size){
list(data)
message(paste("Data size is smaller than group size."))
}
### If original data size is larger than group size ###
else {
new.data <- data
sample.x <- c()
while(length(new.data) >= size){
sample.x <- rbind(sample.x ,
sample(x=new.data , size=size , replace = FALSE))
new.data <- data[-sample.x]
}
### If there are no leftover elements ###
if (length(new.data) == 0){
print(sample.x)
}
### If there are leftover elements ###
else {
message("Leftover elements are shown in list 2")
list(sample.x , new.data)
}
}
}