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
Love this Post? Spread the Word!
Comment and share to motivate us to write more!
About Author:

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

While I love having friends who agree, I only learn from those who don't.

Let's Get Connected: Email | LinkedIn

Get Free Email Updates :
*Please confirm your email address by clicking on the link sent to your Email*
Related Posts:
0 Response to "R : Extracting Numeric and Factor Variables"

Post a Comment

Next → ← Prev
Scroll to Top