user2684423
user2684423

Reputation:

Simulation data using a dataframe

I want to simulate an existing dataset to get the best model.Considering the following dataset and I want to create 100 or 1000 sample using this data in R. Any help?

x<-data.frame( A=c("A","B","M","N","P"),
B=c("G","N","P","R","I"),
C=c("T","F","L","U","U"),
D=c(9,12,13,13,12),
E=c(14,17,10,19,10),
F=c(10,12,19,17,15), 
G=c(7,12,10,14,15), 
H=c(18,19,19,12,12),
I=c("K","L","M","F","D"),
J=c("C","V","O","N","F"),
K=c("G","N","P","P","I"))

Upvotes: 0

Views: 68

Answers (1)

Benjamin
Benjamin

Reputation: 17359

If you want 1000 data sets, try putting them all into list with this.

lapply(1:1000, function(i, x) x[sample(nrow(x), size=1000, replace=TRUE), ], x)

Although I'm not sure what the value of using a simulated data sets of size 1000 from a sample of fewer observations. I believe Ben Bolker's recommendation of size=nrow(x) is probably the more sound way to approach this.

Upvotes: 1

Related Questions