Note that there are some explanatory texts on larger screens.

plurals
  1. POReshape in the middle
    primarykey
    data
    text
    <p>As part of piloting a survey, I presented each Turker with sets of choices amongst four alternatives. The data looks like this:</p> <pre><code>&gt; so WorkerId pio_1_1 pio_1_2 pio_1_3 pio_1_4 pio_2_1 pio_2_2 pio_2_3 pio_2_4 1 1 Yes No No No No No Yes No 2 2 No Yes No No Yes No Yes No 3 3 Yes Yes No No Yes No Yes No </code></pre> <p>I'd like it to look like this:</p> <pre><code>WorkerId set pio1 pio2 pio3 pio4 1 1 Yes No No No 1 2 No No Yes No ... </code></pre> <p>I can kludge through this by a number of means, none of which seem very elegant:</p> <ul> <li>Swapping the order of the numbers with regexes and backreferencing and then using reshape()</li> <li>Writing my own little function to parse out the first digit between the underscores and then reshape it long</li> <li>Splitting and then stacking the columns (relies on the ordering being right)</li> </ul> <p>But it seems to me that all of these ignore the idea that data in what you might call "double wide" format has its own structure. I'd love to use the reshape2 package for this, but despite the data having been produced with cast() I don't see any options that would help me truly melt this data.frame back.</p> <p>Suggestions welcome.</p> <pre><code>so &lt;- structure(list(WorkerId = 1:3, pio_1_1 = structure(c(2L, 1L, 2L), .Label = c("No", "Yes"), class = "factor"), pio_1_2 = structure(c(1L, 2L, 2L), .Label = c("No", "Yes"), class = "factor"), pio_1_3 = structure(c(1L, 1L, 1L), .Label = c("No", "Yes"), class = "factor"), pio_1_4 = structure(c(1L, 1L, 1L), .Label = "No", class = "factor"), pio_2_1 = structure(c(1L, 2L, 2L), .Label = c("No", "Yes"), class = "factor"), pio_2_2 = structure(c(1L, 1L, 1L), .Label = c("No", "Yes"), class = "factor"), pio_2_3 = structure(c(2L, 2L, 2L), .Label = c("No", "Yes"), class = "factor"), pio_2_4 = structure(c(1L, 1L, 1L), .Label = "No", class = "factor")), .Names = c("WorkerId", "pio_1_1", "pio_1_2", "pio_1_3", "pio_1_4", "pio_2_1", "pio_2_2", "pio_2_3", "pio_2_4"), row.names = c(NA, 3L), class = "data.frame") </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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