'Error while splitting dataframe in R (Using sample.split)
I have a dataframe with 140 rows and I'm splitting data randomly to test data and training data.
But while splitting the data using sample.split method in caTools library, I encountered an error.
Following is my code:
library(caTools)
set.seed(42)
features <- read.csv(file = './featur.csv', header = TRUE)
features
features$split = sample.split(features,SplitRatio = 0.8)
This is the error I get:
Error in `$<-.data.frame`(`*tmp*`, split, value = c(TRUE, FALSE, TRUE, :
replacement has 18 rows, data has 140
Can anyone give a clue on what's causing this error and how I can fix it?
Solution 1:[1]
Apparently user @RuiBarrads from the comment told me that the output of sample.split shouldn't be a column. I changed that, and it fixed it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Dennis Main |