Skip to content

Inconsistent NA handling in createDataPartition #1384

@MichaelChirico

Description

@MichaelChirico

xtab <- table(y)

As I'm finding in work towards #1382, missing inputs are handled a bit inconsistently by createDataPartition():

library(withr)

# y is numeric, missing --> error
createDataPartition(c(NA, 1))
# Error in quantile.default(y, probs = seq(0, 1, length = groups)) : 
#   missing values and NaN's not allowed if 'na.rm' is FALSE

# y is character, level with only one observation --> warning
with_seed(78458, createDataPartition(c("a", "b", "b")))
# $Resample1
# [1] 1 3
# Warning message:
# In createDataPartition(c("a", "b", "b")) :
#   Some classes have a single record ( a ) and these will be selected for the sample

# y is character, missing level has only one observation --> no warning
with_seed(78458, createDataPartition(c(NA, "b", "b")))
# $Resample1
# [1] 1 3

What is the proper handling of missing y? Should we just error if y has any missing observations? That would certainly make the migration away from dlply() simpler (c.f. 5805d30).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions