R : Extracting Numeric and Factor Variables

In R, you can extract numeric and factor variables using sapply function.

Extracting Numeric Variables
# Extracting Numeric Variables
cols <- sapply(mydata, is.numeric)
abc = mydata [,cols]
Note : mydata is a dataframe

Extracting Factor Variables
# Extracting Numeric Variables
cols <- sapply(mydata, is.factor)
abc = mydata [,cols]
Note : mydata is a dataframe
Related Posts
About Author:

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 10 years of experience in data science. During his tenure, he has worked with global clients in various domains like Banking, Insurance, Private Equity, Telecom and Human Resource.

0 Response to "R : Extracting Numeric and Factor Variables"

Post a comment

Next → ← Prev
Love this Post? Spread the Word!
Share