Difference between factor and as factor in R programming

+1 vote

I recently got into these lines

x <- as.factor(rep(1:4, 2))
x
# [1] 1 2 3 4 1 2 3 4 
# Levels: 1 2 3 4

But if I do

x <- factor(rep(1:4, 2)) 

that gives me the same result. So what is the difference between factor and as.factor? I get how factor is pulling same numbers out and making them levels, but I don't get what the exact differences are between factor and as.factor.

Oct 29, 2018 in Data Analytics by Ali
• 11,360 points

edited Oct 29, 2018 by Ali 4,519 views

1 answer to this question.

0 votes
Hey @Ali, as.factor is a wrapper for factor, but it allows quick return if the input vector is already a factor:
answered Oct 29, 2018 by Maverick
• 10,840 points

Related Questions In Data Analytics

0 votes
2 answers

What is the difference between %% and % in R programming?

HI, %% returns remainder in case of numeric ...READ MORE

answered Aug 26, 2019 in Data Analytics by anonymous
• 33,030 points
2,004 views
0 votes
1 answer

Difference between [[1]] and [1] in R Programming

Hey Latha, The difference between them is that ...READ MORE

answered Jun 29, 2019 in Data Analytics by anonymous
• 33,030 points
5,883 views
0 votes
1 answer
0 votes
1 answer

What is the difference between library () and require () functions in R ?

 library() require() Library () function gives an error message ...READ MORE

answered Sep 5, 2018 in Data Analytics by zombie
• 3,790 points
2,351 views
0 votes
1 answer

By using dpylr package sum of multiple columns

Basically here we are making an equation ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
2,025 views
0 votes
1 answer

How to convert a text mining termDocumentMatrix into excel or csv in R?

By assuming that all the values are ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,641 views
0 votes
1 answer

In a dpylr pipline how to use sample and seq?

For avoiding rowwise(), I prefer to use ...READ MORE

answered Apr 6, 2018 in Data Analytics by DeepCoder786
• 1,720 points

edited Jun 9, 2020 by Gitika 918 views
0 votes
1 answer

How to create a list of Data frames?

Basically all we have to do is ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,032 views
0 votes
1 answer

What is the difference between R and SPSS?

One of the main difference is R ...READ MORE

answered Dec 11, 2018 in Data Analytics by Maverick
• 10,840 points
932 views
0 votes
1 answer

What is active binding in R programming

Active bindings in R are much like ...READ MORE

answered Oct 30, 2018 in Data Analytics by Maverick
• 10,840 points
1,109 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP