TuringTester69
TuringTester69

Reputation: 177

Matrix without a particular submatrix in R

I have randomly generated a submatrix “train” from “mat” using the following:

train <- mat[sample(nrow(mat), size = 317, replace = FALSE),] 

My question is, how do I then create “test” as a submatrix of “mat” which excludes the matrix “train”?

Thanks!

Upvotes: 2

Views: 41

Answers (1)

JayCe
JayCe

Reputation: 251

train.index are the indexes used for training.

mat <- matrix(rnorm(20000),nrow=1000)
train.index <-sample(nrow(mat), size = 317, replace = FALSE)
train <- mat[train.index,]
test <- mat[-train.index,]

Try it online!

Upvotes: 1

Related Questions