Note that there are some explanatory texts on larger screens.

plurals
  1. POModify values in a column subject to condition?
    text
    copied!<p>I know that this is a very silly question but I cannot work out how to do it. I want to subtract 300 from the values on each row on the trial1 column if they are larger than 299. </p> <p>I tried: </p> <pre><code>sums[sums$trial1 &gt; 299, ][,"trial1"] -= 300 </code></pre> <p>but didn't work. SO far the only way I managed to get it to work is by splitting the data.frame using <code>subset</code> and then modifying it with : </p> <pre><code>sums$trial1 = sums$trial1 - 300 </code></pre> <p>and then using <code>rbind()</code>. I am pretty sure that using subset and rbind is overkill, but I haven't been able to find a direct way yet...</p> <p>I used dput to get a sample of my data.frame.</p> <pre><code>structure(list(part_no = c(10L, 10L, 10L, 10L, 10L, 10L), trial1 = c(294L, 296L, 298L, 300L, 302L, 304L), trial2 = c(295L, 297L, 299L, 301L, 303L, 305L), id1 = c(1.5, 1.5, 1.5, 2, 2, 2), id2 = c(1.5, 1.5, 1.5, 2, 2, 2), dist1 = c(141L, 141L, 115L, 126L, 177L, 141L), width1 = c(77L, 77L, 63L, 42L, 59L, 47L), dist2 = c(143L, 135L, 146L, 255L, 327L, 369L), width2 = c(78L, 74L, 80L, 85L, 109L, 123L), ttime1 = c(1752L, 1681L, 1664L, 1798L, 1664L, 1697L), ttime2 = c(2563L, 1849L, 2067L, 1933L, 2118L, 2245L), no_clicks1 = c(8L, 8L, 8L, 8L, 8L, 8L), no_clicks2 = c(8L, 8L, 8L, 8L, 8L, 8L), no_ontarget1 = c(7L, 8L, 8L, 8L, 8L, 8L), no_ontarget2 = c(8L, 8L, 8L, 4L, 7L, 8L), e1 = c(1L, 0L, 0L, 0L, 0L, 0L), e2 = c(0L, 0L, 0L, 4L, 1L, 0L), rating = c(252, 252, 252, 252, 252, 252), prat = c(0.8, 0.8, 0.8, 0.8, 0.8, 0.8), ptim = c(-46.2899543378995, -9.9940511600238, -24.21875, -7.5083426028921, -27.2836538461538, -32.2922804949912), ptdiff = c(-47.0899543378995, -10.7940511600238, -25.01875, -8.3083426028921, -28.0836538461538, -33.0922804949912), pdist = c(-1.41843971631206, 4.25531914893617, -26.9565217391304, -102.380952380952, -84.7457627118644, -161.702127659574), pddiff = c(-2.21843971631206, 3.45531914893617, -27.7565217391304, -103.180952380952, -85.5457627118644, -162.502127659574), perr = c(100, NaN, NaN, -Inf, -Inf, NaN), pediff = c(99.2, NaN, NaN, -Inf, -Inf, NaN)), .Names = c("part_no", "trial1", "trial2", "id1", "id2", "dist1", "width1", "dist2", "width2", "ttime1", "ttime2", "no_clicks1", "no_clicks2", "no_ontarget1", "no_ontarget2", "e1", "e2", "rating", "prat", "ptim", "ptdiff", "pdist", "pddiff", "perr", "pediff"), row.names = 148:153, class = "data.frame") </code></pre> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload