samedi 1 octobre 2022

How do I create a function in r that assigns one person to 3 other person?

I would like to create a function that allows me to easily import any name list with last name and first name (2 columns) and then based on that name list, 3 persons should be randomly assigned to 1 other person. Just wondering how can I do that by creating by own function?

name.list <- data.frame(StudentNames = c("Person A", "Person B", "Person C", "Person D", "Person E", "Person B"))
NROW.test <- nrow(name.list)

for(i in 1:NROW.test){
  student_1 <- name.list$StudentNames [i + 1] 
  student_2 <- name.list$StudentNames [i+ 2] 
  student_3 <- name.list$StudentNames [i + 3] 
}

test_student_assigned <- data.frame(AssignedStudent = (name.list$StudentNames),
                                   Student_1 = student_1, 
                                   Student_2 = student_2,
                                   Student_3 = student_3, 
                                   stringsAsFactors=FALSE) 



Aucun commentaire:

Enregistrer un commentaire