There are numerous approaches to achieve data partitioning. For a more complete approach take a look at the createDataPartition
function in the caret
package.
Here is a simple example:
data(mtcars)
## 75% of the sample size
smp_size <- floor(0.75 * nrow(mtcars))
## set the seed to make your partition reproducible
set.seed(123)
train_ind <- sample(seq_len(nrow(mtcars)), size = smp_size)
train <- mtcars[train_ind, ]
test <- mtcars[-train_ind, ]
manpreet
Best Answer
2 years ago
I've just started using R and I'm not sure how to incorporate my dataset with the following ref="https://forum.tuteehub.com/tag/sample">sample code:
I have a dataset that I need to put into a training (75%) and testing (25%) set. I'm not sure what information I'm supposed to put into the x and size? Is x the dataset file, and size how many ref="https://forum.tuteehub.com/tag/sample">samples I have?