How to remove columns from data.frame by data type?

I have data.frame with almost 200 variables (columns) and different data types (num, int, logi, factor). Now I would like to remove all variables of type "factor" to run the cor () function

When I use the str () function, I can see which variables are of type “factor”, but I don’t know how to select and delete all these variables, because deleting one by one takes a lot of time. To select these variables, I tried attr () and typeof () with no results.

Which direction?

+4
source share
1 answer

Assuming generic data.frame, this will remove columns of typefactor

df[,-which(sapply(df, class) == "factor")]

EDIT

@Roland , factor. .

df[, sapply(df, class) != "factor"]

2

cor, @Ista , is.numeric. factor.

df[,sapply(df, is.numeric)]
+7

All Articles