What is the expand.grid() function in R?
expand.grid(...)
Syntax for the expand.grid() function
#creating factor objectsa <- c( 1, 2, 3)b <- c( 4, 5, 6)c <- c( 7, 8, 9)# implementing the expand.grid() functionexpand.grid(a, b, c)
Explanation
- Lines 2 to 4: We create factor objects,
a,bandc. - Line 7: We call the
expand.grid()function and pass the factor objects as its arguments. We obtain and print the result to the console.