-1

I want to create a sample matrix from the main one with the sam number of columns but less rows (50) I tried to use a series of loops but it didn't work:

n=nrow(data) camp <- sample(1:n,size=50,replace=TRUE) n<-length(camp) c<-ncol(data) for(i in 1:n){ t<-camp[i] for(k in 1:c){ campione[i,k]<-data[t,k]} } 
1
  • you want data[camp,] Commented Mar 31, 2017 at 9:25

1 Answer 1

0

You don't need to use loop. You just have to take random lines from your main matrix:

mat = matrix(runif(2000),ncol=20) sample_matrix = mat[sample(1:nrow(mat),50),] 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.