Hi, I would try to sample by row index and column index. Hope it helps.
df <- data.frame(matrix(1:18,nrow=3,ncol=6,byrow=TRUE)) colnames(df) <- c(letters[1:3],LETTERS[1:3]) ## Generate a new data frame with 10 rows one <- two <- three <- numeric(10) for (i in 1:10) { ## Sample from type I col.1 <- sample(1:3,1) row.1 <- sample(1:nrow(df),1) one[i] <- df[row.1,col.1] ## Sample from type II col.2 <- sample(setdiff(4:6,col.1+3),2,replace=TRUE) row.2 <- sample(1:nrow(df),2,replace=TRUE) two[i] <- df[row.2[1],col.2[1]] three[i] <- df[row.2[2],col.2[2]] } new.data <- data.frame(one, two, three) ----- A R learner. -- View this message in context: http://r.789695.n4.nabble.com/use-sample-function-to-create-new-data-frame-tp3052110p3052159.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.