UrbanPro
true
default_background

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

R vs Statistics
I frequently asked the below question from my students: 'Do I You need Statistics to learn R Programming?' The answer is, NO. If you want to learn R programming only, Stat is not required. You can be...

Basic R Syntax - R assignment operators
The assignment operators that R Supports are given below -> <- = ->> <<-
S

Use Data Science To Find Credit Worthy Customers
K-nearest neighbor classifier is one of the simplest to use, and hence, is widely used for classifying dynamic datasets. Click on the link to see how easy it is to classify credit-worthy vs credit-risk...

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