What are factors in R?

What are factors in R?

What are factors in R?

This recipe explains what are factors in R

Recipe Objective

What are factors in R ? Factors () are data objects that categorize the data or represent the categorical data, in order to store that data on multiple levels. The distinct values in factors are called levels. Factors can store integer as well as string values. This recipe demonstrates an example of factors with vectors as input.

Step 1 - Create a input vector

Enter all the categorical values in a input vector x

x <- c("good","better","good","best","bad","bad")

Step 2 - Apply factor()

Apply factor() function to x and storein output vector y

y <- factor(x)

Step 3 - Print output

Print y . The 'factors' are all values of input range and 'Levels' are the distinct values of the factors.

"Output of the code is":

 good   better good   best   bad    bad   
Levels: bad best better good

To check if the value is factor or not , is.factor() can be used , if it returns TRUE, the value is a factor, if it returns FALSE, the value is not a factor.

"Output: TRUE" 

Relevant Projects

Build OCR from Scratch Python using YOLO and Tesseract
In this deep learning project, you will learn how to build your custom OCR (optical character recognition) from scratch by using Google Tesseract and YOLO to read the text from any images.

Digit Recognition using CNN for MNIST Dataset in Python
In this deep learning project, you will build a convolutional neural network using MNIST dataset for handwritten digit recognition.

Demand prediction of driver availability using multistep time series analysis
In this supervised learning machine learning project, you will predict the availability of a driver in a specific area by using multi step time series analysis.

Forecasting Business KPI's with Tensorflow and Python
In this machine learning project, you will use the video clip of an IPL match played between CSK and RCB to forecast key performance indicators like the number of appearances of a brand logo, the frames, and the shortest and longest area percentage in the video.

Churn Prediction in Telecom using Machine Learning in R
Estimating churners before they discontinue using a product or service is extremely important. In this ML project, you will develop a churn prediction model in telecom to predict customers who are most likely subject to churn.

House Price Prediction Project using Machine Learning
Use the Zillow dataset to follow a test-driven approach and build a regression machine learning model to predict the price of the house based on other variables.

Build a Collaborative Filtering Recommender System in Python
Use the Amazon Reviews/Ratings dataset of 2 Million records to build a recommender system using memory-based collaborative filtering in Python.

Customer Churn Prediction Analysis using Ensemble Techniques
In this machine learning churn project, we implement a churn prediction model in python using ensemble techniques.

Predict Churn for a Telecom company using Logistic Regression
Machine Learning Project in R- Predict the customer churn of telecom sector and find out the key drivers that lead to churn. Learn how the logistic regression model using R can be used to identify the customer churn in telecom dataset.

Machine Learning or Predictive Models in IoT - Energy Prediction Use Case
In this machine learning and IoT project, we are going to test out the experimental data using various predictive models and train the models and break the energy usage.