Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I had to do it in two <code>reshape</code> steps. The row headings may not be exactly what you needed, but can be renamed easily.</p> <pre><code>id &lt;- as.numeric(rep(1, 16)) time &lt;- rep(c(5,10,15,20), 4) varname &lt;- c(rep("var1",4), rep("var2", 4), rep("var3", 4), rep("var4", 4)) value &lt;- rnorm(16) tmpdata &lt;- as.data.frame(cbind(id, time, varname, value)) first &lt;- reshape(tmpdata, timevar="time", idvar=c("id", "varname"), direction="wide") second &lt;- reshape(first, timevar="varname", idvar="id", direction="wide") </code></pre> <p>And the output:</p> <pre><code>&gt; tmpdata id time varname value 1 1 5 var1 -0.231227494628982 2 1 10 var1 -1.80887236653438 3 1 15 var1 -0.443229294431553 4 1 20 var1 1.33719337048763 5 1 5 var2 0.673109282347586 6 1 10 var2 -0.42142267953938 7 1 15 var2 0.874367622725874 8 1 20 var2 -1.19917678039462 9 1 5 var3 1.13495606258399 10 1 10 var3 -0.0779385346672042 11 1 15 var3 -0.126775240288037 12 1 20 var3 -0.760739300144526 13 1 5 var4 -1.94626587907069 14 1 10 var4 1.25643195699455 15 1 15 var4 -0.50986941213717 16 1 20 var4 -1.01324846239812 &gt; first id varname value.5 value.10 value.15 1 1 var1 -0.231227494628982 -1.80887236653438 -0.443229294431553 5 1 var2 0.673109282347586 -0.42142267953938 0.874367622725874 9 1 var3 1.13495606258399 -0.0779385346672042 -0.126775240288037 13 1 var4 -1.94626587907069 1.25643195699455 -0.50986941213717 value.20 1 1.33719337048763 5 -1.19917678039462 9 -0.760739300144526 13 -1.01324846239812 &gt; second id value.5.var1 value.10.var1 value.15.var1 value.20.var1 1 1 -0.231227494628982 -1.80887236653438 -0.443229294431553 1.33719337048763 value.5.var2 value.10.var2 value.15.var2 value.20.var2 1 0.673109282347586 -0.42142267953938 0.874367622725874 -1.19917678039462 value.5.var3 value.10.var3 value.15.var3 value.20.var3 1 1.13495606258399 -0.0779385346672042 -0.126775240288037 -0.760739300144526 value.5.var4 value.10.var4 value.15.var4 value.20.var4 1 -1.94626587907069 1.25643195699455 -0.50986941213717 -1.01324846239812 </code></pre>
    singulars
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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