Convert a Vector into Factor in R Programming – as.factor() Function

function in R Language is used to convert the passed object(usually Vector) into a Factor.**as.factor()**

Syntax:as.factor(object)

Parameters:Object:Vector to be converted

**Example 1:**

`# Creating a vector ` `x<` `-` `c(` `"female"` `, ` `"male"` `, ` `"male"` `, ` `"female"` `) ` ` ` `# Using as.factor() Function` `# to convert vector into factor` `as.factor(x)` |

**Output:**

[1] female male male female Levels: female male

**Example 2:**

`# Creating a vector ` `x<` `-` `c(` `"North"` `, ` `"North"` `, ` `"East"` `, ` `"West"` `) ` ` ` `# Using as.factor() Function` `# to convert vector into factor` `as.factor(x)` |

**Output:**

[1] North North East West Levels: East North West