Here’s the code I use to find numeric variables in a data frame:
Data <- iris
numericvars <- NULL
for (Var in names(Data)) {
if(class(Data[,Var]) == 'integer' | class(Data[,Var]) == 'numeric') {
numericvars <- c(numericvars,Var)
}
}
numericvars
Is there a less loopy way to do this?
This is a pretty simple one-liner with
sapply: