'Extracting column index as a list

I have a data frame of 12 columns. Columns 1-3 are character data, columns 4-10 are numerics. I want to create a list of all numeric columns, so I get c(4:10) for use in a loop.



Solution 1:[1]

If we want to find the index of numeric columns automatically, loop over the data.frame with sapply, check whether it is numeric (is.numeric) and wrap with which

indx <- which(sapply(df1, is.numeric))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 akrun