numeric_cols <- vector("logical", length(df)) # test whether each column is numeric for (i in seq_along(df)) { numeric_cols[[i]] <- is.numeric(df[[i]]) } # find the indexes of the numeric columns idxs <- which(numeric_cols)
Is there a reason not to use
idxs <- which(sapply(df, is.numeric)) ?