I need to build a prediction model as a final project. However, I am having problems splitting the data. Any help you can give me is greatly appreciated. Thanks!
Here is my code:
set.seed(123)
split <- sample.split(Trends,SplitRatio =0.70)
train <- subset(Trends,split==TRUE)
test <- subset(Trends,split==FALSE)
Here is the error:
Error: Must subset rows with a valid subscript vector.
i Logical subscripts must match the size of the indexed input.
x Input has size 2960 but subscript r
has size 11.
Here is the rlang:: last_error (I do not understand how to fix this):
<error/vctrs_error_subscript_size>
Must subset rows with a valid subscript vector.
i Logical subscripts must match the size of the indexed input.
x Input has size 2960 but subscript r
has size 11.
It continues:
Backtrace
x
- +-base::subset(Trends, split == TRUE)
- -base::subset.data.frame(Trends, split == TRUE)
- +-x[r, vars, drop = drop]
- -tibble:::
[.tbl_df
(x, r, vars, drop = drop) -
\-tibble:::tbl_subset_row(xo, i = i, i_arg)
-
\-tibble:::vectbl_as_row_index(i, x, i_arg)
-
\-tibble:::vectbl_as_row_location(i, nr, i_arg, assign)
-
+-tibble:::subclass_row_index_errors(...)
-
| \-base::withCallingHandlers(...)
-
\-vctrs::vec_as_location(i, n)
-
\-(function () ...
-
\-vctrs:::stop_indicator_size(...)
Example of My Dataset:
PeriodEnd | HomesSold | Inventory | MedianDom | MedianListPpsf | MedianListPrice | MedianPpsf | MedianSalePrice | NewListings | PermitBldgs | PermitValue | |
---|---|---|---|---|---|---|---|---|---|---|---|
1/31/2017 | 62 | 458 | 99 | 178 | 369900 | 180 | 367912 | 76 | 73 | 18924074 | |
1/31/2018 | 60 | 432 | 55 | 191 | 339900 | 189 | 398040 | 94 | 65 | 18275062 | |
10/31/2017 | 84 | 425 | 73 | 177 | 334100 | 191 | 389118 | 112 | 110 | 26795999 | |
12/31/2017 | 97 | 422 | 53 | 179 | 354400 | 191 | 411088 | 83 | 90 | 24514262 | |
6/30/2019 | 51 | 444 | 118 | 185 | 400520 | 193 | 390000 | 83 | 85 | 23513520 | |
7/31/2018 | 85 | 472 | 37 | 188 | 372355 | 185 | 379900 | 77 | 121 | 34700456 | |
11/30/2019 | 55 | 394 | 110 | 202 | 379000 | 195 | 409900 | 67 | 108 | 30880359 | |
7/31/2017 | 74 | 438 | 155 | 191 | 372800 | 179 | 348710 | 69 | 112 | 29117986 | |
11/30/2017 | 76 | 418 | 89 | 175 | 369700 | 183 | 359752 | 96 | 103 | 27644803 | |
3/31/2017 | 62 | 490 | 43 | 175 | 358943 | 178 | 384591 | 98 | 78 | 21168124 | |
9/30/2017 | 67 | 428 | 58 | 180 | 379500 | 178 | 348069 | 110 | 141 | 35000701 | |
8/31/2017 | 78 | 431 | 95 | 186 | 356300 | 178 | 364315 | 118 | 132 | 32577586 | |
5/31/2018 | 76 | 487 | 62 | 185 | 353615 | 190 | 438845 | 111 | 170 | 43139495 | |
10/31/2018 | 75 | 492 | 76 | 195 | 373645 | 185 | 375819 | 124 | 139 | 36139075 |