1

Is it possible to pass an object for the dependent variable in sample.split?

This works where Exited is the dependent variable.

set.seed(880)
split = sample.split(ds$Exited, SplitRatio = 0.65)

This doesn't work passing an object for the dependent variable.

dv <- "Exited"
set.seed(880)
split = sample.split(ds$dv, SplitRatio = 0.65)

Error in sample.split(ds$dv, SplitRatio = 0.65) : 
      Error in sample.split: 'SplitRatio' parameter has to be i [0, 1] range or [1, length(Y)] range

1 Answers1

0

Use [[ instead of $ for extraction

sample.split(ds[[dv]], SplitRatio = 0.65)
akrun
  • 874,273
  • 37
  • 540
  • 662