[Rd] Why is any() only defined for a numeric and not logical data.frame?
k@ro||@@koncev|c|u@ @end|ng |rom gm@||@com
Sun Feb 16 20:23:47 CET 2020
I recently stumbled on an unusual behaviour of any() and all() and have
been adviced from StackOverflow to share it here .
df1 <- data.frame(A=TRUE, B=FALSE)
df2 <- data.frame(A=1, B=0)
Error in FUN(X[[i]], ...):
only defined on a data frame with all numeric variables
Warning message: In any(c(1, 2), na.rm = FALSE):
coercing argument of type 'double' to logical
Same results happen when using all()
So the any() and all() do not work on data frames with logical values,
but work if the values are numeric.
This doesn't seem to be a bug because error correctly states that any()
will only work on an all-numeric data.frame. However the behaviour
doesn't seem intentional and I cannot come up with any reason for it
behaving this way.
Maybe any() and all() need to be modified to not work on data.frames()
at all, which would also be consistent with is.nan() ?
More information about the R-devel