I have a data frame composed of numeric and non-numeric columns.
I would like to extract (subset) only the non-numeric columns, so the character ones. While I was able to subset the numeric columns using the string: sub_num = x[sapply(x, is.numeric)], I’m not able to do the opposite using the is.character form. Can anyone help me?
Ok, I did a short try about my idea.
I could confirm that the following code snippet is working:
Using the correct class, your
sapply-approach should work as well, at least as long as you insert the missing,before thesapplyfunction.The approach using
!is.numericdoes not scale very well if you have classes that do not belong in the groupnumeric, factor, character(one I use very often isPOSIXct, for example)