I am trying to create a dataframe based on user-provided input. The user will decide the number of variables to be included in the dataframe.
Below I provide the codes that do what I am after. What I want to do is to create a function that does this same task.
var1 <- c(1:6)
var2 <- c(1:6)
var3 <- c(1:6)
var1 <- sample(var1, 10, replace = TRUE)
var2 <- sample(var2, 10, replace = TRUE)
var3 <- sample(var3, 10, replace = TRUE)
mydata <- data.frame(var1, var2, var3)
I expect the output below.
var1 var2 var3
1 4 1 3
2 2 5 1
3 5 6 2
4 4 5 2
5 5 3 3
6 5 5 2
7 1 3 6
8 3 5 5
9 2 4 1
10 5 5 5