Say I have two data frames, students and teachers.
students <- data.frame(name = c("John", "Mary", "Sue", "Mark", "Gordy", "Joey", "Marge", "Sheev", "Lisa"), height = c(111, 93, 99, 107, 100, 123, 104, 80, 95), smart = c("no", "no", "yes", "no", "yes", "yes", "no", "yes", "no")) teachers <- data.frame(name = c("Ben", "Craig", "Mindy"), height = c(130, 101, 105), smart = c("yes", "yes", "yes"))
I want to create all possible combinations of students and teachers and save the accompanying information, basically to create all combinations of strings from "frames" of data and "teachers". This can easily be done with a loop and cbind, but for a massive data frame it takes forever. Help newbie R - what's the fastest way to do this?
Edit: if this is not clear, I want the output to have the following format:
rbind( cbind(students[1, ], teachers[1, ]), cbind(students[1, ], teachers[2, ]) ... cbind(students[n, ], teachers[n, ]))