title: How to use stringr and forcats package in R more efficiently?
body: <p>I am confused that how to combine <code>stringr</code> package in a pipline data analysis process. The <code>stringr</code> project is a string vector (single column), the origin data (multi-column) convert into single column, the output can not be directly used in later process with <code>%&gt;%</code> for function like <code>summarise</code> in <code>dplyr</code>, and have to re-assign to new project, the way seems not so gentle, is there any smooth way to process the data?</p>
  <p>Here is an example code, and can the <code>str_replace</code> procedure be combind with <code>sum</code> procedure with pipeline  <code>%&gt;%</code></p>
  <pre><code># prepare dara
  library(tidyr, dplyr)
  name &lt;- c('D', 'E', 'F', 'G', 'd', 'e', 'f' )
  room &lt;- rep(c('A','B'),c(4,3))
  goal &lt;- c(rnorm(7,mean=60,sd=10))
  test &lt;- data.frame(name,goal,room)
  
  # replace 'G' in name to 'H'
  test$name &lt;- str_replace(test$name, 'G', 'H') 
  
  # SUM (calculate)
  test %&gt;% group_by(name) %&gt;% summarise(sum(goal))
  </code></pre>
  <p>I just want to know how to connect <code>stringr</code>  with other data processes, can it be or be not? I know there it can be solved in a factor way (<code>forcats</code>): change the string vector into factor vector and  relevel the factor, and here is another problem: how to process partly factor vetor more gently, and here is an example:</p>
  <pre><code>library(dplyr,forcats,dplyr)
  name1 &lt;- c('D', 'E', 'F', 'G', 'D', 'E', 'F' )
  room &lt;- rep(c('A','B'),c(4,3))
  goal &lt;- c(rnorm(7,mean=60,sd=10))
  test1 &lt;- data.frame(name1,goal,room)
  
  ## split and recombine the test1 data, I just want to change the name level of room B ##, but just change name directly in data test1 will change the level of room A at ##the same time
  test1A &lt;- test1 %&gt;% filter(room == 'A') 
  test1B &lt;- test1 %&gt;% filter(room == 'B') 
  test1B %&gt;% mutate(name1 = fct_recode(name1, 'DD'='D','EE'='E','FF'='F'))
  test1 &lt;- bind_rows(test1A, test1B) 
  </code></pre>
  <p>Can the partly recode purpose be more gentle?</p>