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
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.

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

Post a Comment

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