title: In R , a question about change variable type to 'factor'
body: <p>I use the code below to change the variable 'period' from 'character' to 'factor' (and factor levels sequence to match the order contained in 'period' text).</p>
  <p>Below is the current code. Is there an available function for it ?</p>
  <pre><code>library(tidyverse)
  
  raw_data &lt;- 
    data.frame(
      period=c('Q2','Q1','8','7','40','41'),
      amount=c(1:6)
    ) 
  
  
  arranged_data &lt;- raw_data %&gt;% arrange(match(parse_number(period),c(1:41))) %&gt;% 
    mutate(period=fct_inorder(period))
  </code></pre>