I would like to remove all integer columns from my dataframe utilizing dplyr leaving only non-integer numeric columns. I thought I would be able to do like with the below:
Note: I realize I can select the numerics in my example below, but my actual dataset has other variable types in addition to numeric and integer.
library(dplyr)
mydata <- USArrests
mydata2 <- mydata %>%
select(!is.integer)
but that gives the error:
Error in !is.integer : invalid argument type
mydata2 <- mydata %>%
select(-is.integer)
Errors out with:
Error in -x : invalid argument to unary operator
The following works, but I'd like to know how to do this in dplyr as well.
mydata_temp <- mydata[, sapply(mydata, function(x) !is.integer(x))]
mydata_numeric_vars <- mydata_temp %>%
select_if(is.numeric)
Any suggestions? Seems like this should be fairly straightforward in dplyr but in looking around stack I can't seem to find a similar Q/A for this?