Note that there are some explanatory texts on larger screens.

plurals
  1. POCalculate scores across columns
    text
    copied!<p>First the sample data:</p> <pre><code>bbbv[1:25] &lt;-1 bbbv[26:50] &lt;-2 bbbw &lt;- 1:25 bbbx &lt;- sample(1:5, 50, replace=TRUE) bbby &lt;- sample(1:5, 50, replace=TRUE) bbb &lt;- data.frame(pnum=bbbv, trialnum=bbbw, guess=bbbx, target=bbby) </code></pre> <p>If the target is the same number as the guess then we score 1, else 0.</p> <pre><code>bbb$hit &lt;- ifelse(bbb$guess==bbb$target, 1, 0) </code></pre> <p><img src="https://i.stack.imgur.com/wpmhY.png" alt="enter image description here"></p> <p>This is the problem. I want to calculate four more columns:</p> <pre><code>bbb$hitpone trialnum(n) guess == trial(n+1) target bbb$hitptwo trialnum(n) guess == trial(n+2) target bbb$hitmone trialnum(n) guess == trial(n-1) target bbb$hitmtwo trialnum(n) guess == trial(n-2) target </code></pre> <p>To be clear. For hitmone we look at the trial guess and compare it to the target for the trial before (-1 from the current trial). For hitmtwo we look at the trial guess and compare it to the target 2 back (-2 from the current trial). hitpone and hitptwo are the same but in a positive direction (+1 and +2 from current trial).</p> <p>And just to be clear, as before we're interested in determining If the target is the same number as the guess then we score 1, else 0 (according to our new calculations).</p> <p>Now there is some minor difficulty with this task. Each pnum has 25 trials. For hitpone we cannot calculate a +1 for trial 25. For hitptwo we cannot calculate a +2 for trials 25 nor trial 24. The same follows for the hitmone: we cannot calculate -1 for trial 1, nor -2 for trials 1 and 2.</p> <p>This is how I want the table to look. I have mocked it up by hand, showing the first 1-3 trials and last 23-25 trials. <img src="https://i.stack.imgur.com/c48QE.png" alt="Wanted output"></p> <pre><code>dput(bbb) structure(list(pnum = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), trialnum = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L), guess = c(5L, 1L, 1L, 3L, 1L, 3L, 1L, 5L, 2L, 3L, 1L, 1L, 5L, 3L, 5L, 1L, 2L, 2L, 3L, 1L, 4L, 1L, 4L, 4L, 3L, 4L, 5L, 2L, 4L, 5L, 5L, 5L, 4L, 5L, 2L, 3L, 1L, 1L, 5L, 1L, 1L, 3L, 1L, 2L, 4L, 1L, 2L, 3L, 1L, 1L), target = c(4L, 3L, 4L, 5L, 5L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 2L, 5L, 1L, 3L, 2L, 1L, 4L, 4L, 1L, 1L, 3L, 4L, 4L, 2L, 3L, 2L, 1L, 1L, 5L, 4L, 3L, 5L, 1L, 1L, 1L, 2L, 5L, 2L, 4L, 3L, 1L, 1L, 2L, 5L, 3L, 3L, 3L), hit = c(0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0)), .Names = c("pnum", "trialnum", "guess", "target", "hit"), row.names = c(NA, -50L), class = "data.frame") </code></pre>
 

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