R sapply is.factor

*爱你&永不变心* 提交于 2019-12-05 04:16:08

Correct way:

nonFactorCols <- sapply(df1, function(col) !is.factor(col))
# or, more efficiently
nonFactorCols <- !sapply(df1, is.factor)
# or, even more efficiently
nonFactorCols <- !factorCols

Joshua gave you the correct way to do it. As for why sapply(df1, !is.factor) did not work:

sapply is expecting a function. !is.factor is not a function. The bang operator returns a logical value (albeit, it cannot take is.factor as an argument).

Alternatively, you could use Negate(is.factor) which does in fact return a function.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!