text: user4595: I have a data frame
  > head(custom.cn.data)
        Gene       Sample_name         CN
  1: DDX11L1          F02         0.6788844
  2: DDX11L1          C02        -0.9924524
  3: DDX11L1          A07        -2.3833559
  > 
  
  I want to convert values in CN column < 0 to Del and >0 to Amp
  But I am getting error
  > a %>% mutate(q = replace(CN, which(CN<0), Del))
  Error in replace(CN, which(CN < 0), Del) : object 'Del' not found
  
  > a$CN <- replace(a$CN, which(a$CN < 0), Del)
  Error in replace(a$CN, which(a$CN < 0), Del) : object 'Del' not found
  
  Any help?
  
  user131: Try to stay within one package (paradigm) for one problem. This will make the code more readable, easier to debug.
  At the moment you have data as a data.table object from data.table package, then trying to add a new column using mutate from dplyr package, and within mutate using base replace function.
  Solutions:
  data.table
  # update by row index
  custom.cn.data[ CN < 0, NewColumn := "Del" ]
  custom.cn.data[ CN >= 0, NewColumn := "Amp" ]
  
  or use ifelse
  custom.cn.data[, NewColumn := ifelse(CN < 0, "Del", "Amp") ]
  
  base 
  see @DavyCat's and @haci's answers.
  dplyr
  Note, this will change the data.table into data.frame.
  # ifelse
  custom.cn.data <- custom.cn.data %>%
    mutate(NewColumn = ifelse(CN < 0, "Del", "Amp"))
  
  or use case_when
  custom.cn.data <- custom.cn.data %>%
    mutate(NewColumn = case_when(
      CN < 0 ~ "Del",
      CN >= 0 ~ "Amp"))
  
  
  user6955: The following code would create a new column with the desired values, 0 values will have NA in this new column.
  custom.cn.data[custom.cn.data$CN < 0, "CN_string"] <- "Del" 
  custom.cn.data[custom.cn.data$CN > 0, "CN_string"] <- "Amp"
  
  
  user3541: custom.cn.data$new_column <- ifelse(custom.cn.data$CN < 0, "Del", "Amp")
  
  In this scenario CN == 0 would be Amp
  
original_text: 4595: <p>I have a data frame</p>
  
  <pre><code>&gt; head(custom.cn.data)
        Gene       Sample_name         CN
  1: DDX11L1          F02         0.6788844
  2: DDX11L1          C02        -0.9924524
  3: DDX11L1          A07        -2.3833559
  &gt; 
  </code></pre>
  
  <p>I want to convert values in CN column &lt; 0 to Del and >0 to Amp</p>
  
  <p>But I am getting error</p>
  
  <pre><code>&gt; a %&gt;% mutate(q = replace(CN, which(CN&lt;0), Del))
  Error in replace(CN, which(CN &lt; 0), Del) : object 'Del' not found
  
  &gt; a<span class="math-container">$CN &lt;- replace(a$</span>CN, which(a<span class="math-container">$CN &lt; 0), Del)
  Error in replace(a$</span>CN, which(a$CN &lt; 0), Del) : object 'Del' not found
  </code></pre>
  
  <p>Any help?</p>
   131: <p>Try to stay within one package (paradigm) for one problem. This will make the code more readable, easier to debug.</p>
  
  <p>At the moment you have data as a <em>data.table</em> object from <strong>data.table</strong> package, then trying to add a new column using <em>mutate</em> from <strong>dplyr</strong> package, and within <em>mutate</em> using <strong>base</strong> <em>replace</em> function.</p>
  
  <p>Solutions:</p>
  
  <p><strong>data.table</strong></p>
  
  <pre><code># update by row index
  custom.cn.data[ CN &lt; 0, NewColumn := "Del" ]
  custom.cn.data[ CN &gt;= 0, NewColumn := "Amp" ]
  </code></pre>
  
  <p>or use <em>ifelse</em></p>
  
  <pre><code>custom.cn.data[, NewColumn := ifelse(CN &lt; 0, "Del", "Amp") ]
  </code></pre>
  
  <p><strong>base</strong> </p>
  
  <p>see <a href="https://bioinformatics.stackexchange.com/a/11264/131">@DavyCat's</a> and <a href="https://bioinformatics.stackexchange.com/a/11263/131">@haci's</a> answers.</p>
  
  <p><strong>dplyr</strong></p>
  
  <p>Note, this will change the <em>data.table</em> into <em>data.frame</em>.</p>
  
  <pre><code># ifelse
  custom.cn.data &lt;- custom.cn.data %&gt;%
    mutate(NewColumn = ifelse(CN &lt; 0, "Del", "Amp"))
  </code></pre>
  
  <p>or use <em>case_when</em></p>
  
  <pre><code>custom.cn.data &lt;- custom.cn.data %&gt;%
    mutate(NewColumn = case_when(
      CN &lt; 0 ~ "Del",
      CN &gt;= 0 ~ "Amp"))
  </code></pre>
   6955: <p>The following code would create a new column with the desired values, 0 values will have <code>NA</code> in this new column.</p>
  
  <pre><code>custom.cn.data[custom.cn.data$CN &lt; 0, "CN_string"] &lt;- "Del" 
  custom.cn.data[custom.cn.data$CN &gt; 0, "CN_string"] &lt;- "Amp"
  </code></pre>
   3541: <pre><code>custom.cn.data<span class="math-container">$new_column &lt;- ifelse(custom.cn.data$</span>CN &lt; 0, "Del", "Amp")
  </code></pre>
  
  <p>In this scenario <code>CN == 0</code> would be <code>Amp</code></p>
  