UrbanPro
true

Learn R Programming from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

R programming: Factors

Indranil Rath
28/10/2016 0 0

Admittedly, R has a steep learning curve. But most common errors faced by beginners can be resolved with a good understanding of the language basics. For example, categorical variables must always be converted to 'factor' class before any data analysis in R. Here's an intuitive explanation. Say we have a an atomic vector with 1 = female and 0 = male:

> gender_vec = c(1, 0, 0, 1, 1)

Would an arithmetic operation on this vector make sense? No!

> gender_vec + 2           # meaningless!

[1] 3 2 2 3 3

We would like R to distinguish between such categorical variables and other numeric vectors. The 'factor' class in R allows for this distinction. Once we convert our vector to 'factor' class, R recognises that the vector represents a categorical variable and refuses to perform meaningless operations on it.

> as.factor(gender_vec)

[1] 1 0 0 1 1

Levels: 0 1

 

 

 

 

0 Dislike
Follow 0

Please Enter a comment

Submit

Other Lessons for You

Decision Tree or Linear Model For Solving A Business Problem
When do we use linear models and when do we use tree based classification models? This is common question often been asked in data science job interview. Here are some points to remember: We can use any...

Market Basket Analysis
Market Basket Analysis (MBA): Market Basket Analysis (MBA), also known as affinity analysis, is a technique to identify items likely to be purchased together. The introduction of electronic point of sale...

Python Programming or R- Programming
Most of the students usually ask me this question before they join the classes, whether to go with Python or R. Here is my short analysis on this very common topic. If you have interest/or having a job...

What are the basic differences between SAS and R languages?
SAS SAS is the integrated system of software solutions, and it is the leader in the data analytics field. This software has a lot of features like good GUI and others to provide excellent technical...

Basics Of R Programming 1
# To know the working directory which is assigned by defaultgetwd()# set the working directory from where you would like to take the files setwd("C:/Mywork/MyLearning/MyStuddocs_UrbanPro/Data") # Assign...
X

Looking for R Programming Classes?

The best tutors for R Programming Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn R Programming with the Best Tutors

The best Tutors for R Programming Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more