Convert data from long to wide format
long2wide(
data,
within = c(),
between = c(),
dv = "y",
id = "id",
sep = faux_options("sep")
)
the tbl in long format
the names of the within column(s)
the names of between column(s) (optional)
the name of the DV (value) column
the names of the column(s) for grouping observations
separator for factor levels
a tbl in wide format
df_long <- sim_design(2, 2, long = TRUE)
long2wide(df_long, "A", "B")
#> id B1 W1a W1b
#> 1 S001 B1a 8.077412e-01 -0.581217084
#> 2 S002 B1a 4.517776e-01 1.243804148
#> 3 S003 B1a -4.718958e-01 1.012568562
#> 4 S004 B1a -2.058473e-01 1.023550845
#> 5 S005 B1a 2.183171e-02 -1.083083606
#> 6 S006 B1a 4.497307e-01 -0.286426316
#> 7 S007 B1a -1.056944e+00 0.371853742
#> 8 S008 B1a -1.558754e+00 -0.316690115
#> 9 S009 B1a 3.355071e-01 0.640686199
#> 10 S010 B1a -1.001162e+00 0.865675380
#> 11 S011 B1a 1.953171e+00 -1.382941479
#> 12 S012 B1a -4.688652e-01 0.443330242
#> 13 S013 B1a 7.961872e-01 -0.903012859
#> 14 S014 B1a -2.467941e+00 0.386563089
#> 15 S015 B1a -2.010783e+00 -0.074733100
#> 16 S016 B1a 1.515847e-02 0.076737148
#> 17 S017 B1a -1.035606e+00 -0.612158018
#> 18 S018 B1a -5.494023e-01 -0.797482004
#> 19 S019 B1a 5.326052e-01 1.336870324
#> 20 S020 B1a 5.291466e-01 0.420631707
#> 21 S021 B1a -7.018714e-02 0.994924674
#> 22 S022 B1a 2.956811e-02 -0.145946071
#> 23 S023 B1a -1.998866e+00 -1.281464793
#> 24 S024 B1a -1.049860e+00 0.234946127
#> 25 S025 B1a 9.384608e-01 -0.318499052
#> 26 S026 B1a 2.262165e-01 0.110414951
#> 27 S027 B1a 7.798941e-01 1.696082977
#> 28 S028 B1a -2.068914e+00 -0.283513441
#> 29 S029 B1a 8.785029e-01 0.130665663
#> 30 S030 B1a -6.340900e-02 1.522733514
#> 31 S031 B1a 4.462148e-03 0.692195485
#> 32 S032 B1a 1.176911e+00 -0.901764515
#> 33 S033 B1a 1.366049e+00 -0.424829586
#> 34 S034 B1a 2.268203e-01 1.354577190
#> 35 S035 B1a -3.565617e-01 1.990365348
#> 36 S036 B1a -1.058355e+00 -0.434197386
#> 37 S037 B1a 1.050287e+00 1.265546731
#> 38 S038 B1a -5.132273e-01 -1.210880952
#> 39 S039 B1a 7.428287e-01 -0.301896211
#> 40 S040 B1a 1.333336e+00 -0.545272068
#> 41 S041 B1a -1.093553e-01 0.162759004
#> 42 S042 B1a -5.153220e-01 -1.583000943
#> 43 S043 B1a 1.255648e+00 -0.480713289
#> 44 S044 B1a -3.477386e-01 -1.581986046
#> 45 S045 B1a 1.025343e+00 -0.636944073
#> 46 S046 B1a 7.960771e-01 -0.753208911
#> 47 S047 B1a -9.410129e-01 -0.059906037
#> 48 S048 B1a 3.100827e-01 -0.494778358
#> 49 S049 B1a -1.571646e-02 -0.448708129
#> 50 S050 B1a 1.626774e-01 1.039739423
#> 51 S051 B1a 1.473397e+00 -1.196918856
#> 52 S052 B1a -1.197973e+00 0.272289640
#> 53 S053 B1a -6.779543e-01 0.255473743
#> 54 S054 B1a 6.975910e-01 0.074014879
#> 55 S055 B1a -1.138864e+00 1.162359433
#> 56 S056 B1a 1.395810e+00 -1.493127776
#> 57 S057 B1a -4.731572e-01 0.844221510
#> 58 S058 B1a -1.026657e+00 0.285206184
#> 59 S059 B1a 4.356335e-01 0.096297876
#> 60 S060 B1a 9.579557e-01 0.812029101
#> 61 S061 B1a -5.395317e-01 -0.648240261
#> 62 S062 B1a -2.291815e-02 -0.279582467
#> 63 S063 B1a 7.374548e-01 0.943122178
#> 64 S064 B1a -1.769470e+00 -0.809459245
#> 65 S065 B1a -2.765730e-01 0.140462380
#> 66 S066 B1a 1.045390e+00 -0.774306686
#> 67 S067 B1a 2.199377e-01 -0.575102706
#> 68 S068 B1a -8.028960e-01 -0.457018772
#> 69 S069 B1a 1.739661e-01 -0.596431083
#> 70 S070 B1a 2.739560e-01 0.236593069
#> 71 S071 B1a 2.211660e+00 -1.610958367
#> 72 S072 B1a 5.358750e-01 0.011896803
#> 73 S073 B1a -9.408054e-01 -0.029681921
#> 74 S074 B1a -1.108482e+00 -1.332575776
#> 75 S075 B1a 1.171698e+00 -0.912644535
#> 76 S076 B1a 1.926754e+00 -0.497066428
#> 77 S077 B1a 5.051597e-01 -1.957798586
#> 78 S078 B1a 1.232668e-01 0.380526535
#> 79 S079 B1a -5.140290e-02 0.137359591
#> 80 S080 B1a 2.467571e-01 0.894819043
#> 81 S081 B1a -1.463863e+00 0.085701847
#> 82 S082 B1a 3.908591e-01 -2.238217301
#> 83 S083 B1a 8.442806e-01 0.674552606
#> 84 S084 B1a -6.520269e-02 1.289863118
#> 85 S085 B1a -8.568898e-01 -0.963013386
#> 86 S086 B1a 8.032664e-01 0.766968833
#> 87 S087 B1a 9.115843e-01 -0.529082527
#> 88 S088 B1a -7.829897e-01 -0.208584175
#> 89 S089 B1a 5.349082e-01 -0.350752934
#> 90 S090 B1a -3.202906e-01 0.689557250
#> 91 S091 B1a -2.347576e-01 -0.371755560
#> 92 S092 B1a 1.574574e+00 0.983346538
#> 93 S093 B1a -9.635837e-01 -0.371554539
#> 94 S094 B1a 1.180980e-01 -0.575957302
#> 95 S095 B1a -8.030915e-01 -0.056495677
#> 96 S096 B1a -1.000103e+00 -0.110067003
#> 97 S097 B1a -1.719856e+00 -1.598010607
#> 98 S098 B1a -3.443556e-02 0.603933388
#> 99 S099 B1a -3.438798e-03 1.041673287
#> 100 S100 B1a -1.351782e+00 -0.014595597
#> 101 S101 B1b -6.688378e-01 1.775000771
#> 102 S102 B1b 2.679074e-01 -1.024403827
#> 103 S103 B1b 3.048742e-01 1.382051177
#> 104 S104 B1b 7.385340e-02 -0.012809868
#> 105 S105 B1b -3.927187e-01 0.624906290
#> 106 S106 B1b -2.510785e-01 -0.176472947
#> 107 S107 B1b -8.513943e-01 2.983694973
#> 108 S108 B1b 1.370550e+00 -0.471012485
#> 109 S109 B1b 2.715398e-01 -0.601762652
#> 110 S110 B1b -6.824851e-01 0.781622315
#> 111 S111 B1b -1.364948e+00 1.100378196
#> 112 S112 B1b 4.922854e-01 0.067295271
#> 113 S113 B1b -1.335447e+00 1.517489933
#> 114 S114 B1b -8.048660e-01 -0.187314771
#> 115 S115 B1b 8.614713e-01 1.471501779
#> 116 S116 B1b -4.863203e-02 1.538623507
#> 117 S117 B1b -5.223774e-01 0.070348894
#> 118 S118 B1b 3.211244e-01 0.289671126
#> 119 S119 B1b -7.140988e-01 0.933937374
#> 120 S120 B1b 1.119743e+00 0.194072367
#> 121 S121 B1b -1.485723e-01 -0.547800821
#> 122 S122 B1b -1.039095e+00 -1.143546517
#> 123 S123 B1b -5.612202e-01 -0.710867326
#> 124 S124 B1b 6.672663e-01 1.872773661
#> 125 S125 B1b -3.926062e-01 -1.368229769
#> 126 S126 B1b 9.284412e-01 -0.417078962
#> 127 S127 B1b -2.132598e+00 0.919250413
#> 128 S128 B1b 3.501099e-01 -0.138050739
#> 129 S129 B1b 6.835580e-01 1.767865139
#> 130 S130 B1b -4.833713e-01 0.997494149
#> 131 S131 B1b -8.990596e-01 -0.282956491
#> 132 S132 B1b 3.972315e-01 -0.950751863
#> 133 S133 B1b 1.378471e+00 -0.608602879
#> 134 S134 B1b -3.000613e+00 -1.625558710
#> 135 S135 B1b 4.001548e-01 0.241521383
#> 136 S136 B1b 7.452236e-01 -0.959390654
#> 137 S137 B1b 2.123030e-01 -0.179318546
#> 138 S138 B1b -1.643672e+00 -0.267291472
#> 139 S139 B1b -5.053204e-01 0.623437299
#> 140 S140 B1b -7.739564e-01 0.299077943
#> 141 S141 B1b -4.011877e-01 -0.391298081
#> 142 S142 B1b -6.418386e-05 0.129754966
#> 143 S143 B1b 1.038349e-01 -0.095143416
#> 144 S144 B1b 1.151010e+00 -0.543897803
#> 145 S145 B1b -5.660412e-01 0.197233971
#> 146 S146 B1b 1.503417e+00 -0.499952802
#> 147 S147 B1b -7.340923e-01 -0.177086117
#> 148 S148 B1b -1.191545e+00 -0.036204824
#> 149 S149 B1b -1.079226e+00 -0.426622088
#> 150 S150 B1b -7.223130e-01 -0.044905773
#> 151 S151 B1b -8.439480e-01 1.167537280
#> 152 S152 B1b 2.363379e-02 1.073160716
#> 153 S153 B1b 5.396128e-01 -1.545286191
#> 154 S154 B1b -3.379071e-01 -2.836524173
#> 155 S155 B1b 1.304862e+00 1.655262536
#> 156 S156 B1b 2.683731e-01 0.750872654
#> 157 S157 B1b -9.065269e-01 1.069104188
#> 158 S158 B1b 5.157836e-01 -1.291261301
#> 159 S159 B1b -2.036517e-02 -0.757140150
#> 160 S160 B1b 1.017588e+00 -0.484465246
#> 161 S161 B1b 3.886355e-01 -0.633954621
#> 162 S162 B1b 3.855307e-02 -1.095454358
#> 163 S163 B1b -6.686390e-01 1.140171104
#> 164 S164 B1b -1.142905e+00 0.011213216
#> 165 S165 B1b 1.430599e+00 0.284061832
#> 166 S166 B1b 9.227215e-02 -0.762637437
#> 167 S167 B1b -2.620999e-01 0.850177325
#> 168 S168 B1b 1.186917e+00 0.839895058
#> 169 S169 B1b -7.207161e-01 -0.793703967
#> 170 S170 B1b 3.430562e-01 -0.056971022
#> 171 S171 B1b 5.219334e-01 -1.986741807
#> 172 S172 B1b 8.703379e-01 1.965476372
#> 173 S173 B1b -3.575842e-01 -1.595974922
#> 174 S174 B1b 3.140156e-01 -1.586937041
#> 175 S175 B1b -6.855989e-01 -0.674694695
#> 176 S176 B1b -7.079976e-01 -1.330725615
#> 177 S177 B1b -1.534007e+00 0.388267902
#> 178 S178 B1b -8.640583e-01 0.195846490
#> 179 S179 B1b 5.698228e-01 -0.328383772
#> 180 S180 B1b 8.853398e-02 0.831331330
#> 181 S181 B1b 1.139111e+00 -0.690700639
#> 182 S182 B1b 3.049735e-02 -0.628212748
#> 183 S183 B1b -6.583132e-01 0.047397096
#> 184 S184 B1b 2.268114e-01 -0.034893586
#> 185 S185 B1b -1.305929e+00 -0.183307220
#> 186 S186 B1b -2.378626e-01 -0.276604166
#> 187 S187 B1b -1.137176e+00 0.245451680
#> 188 S188 B1b 1.401977e+00 1.428902173
#> 189 S189 B1b -1.060917e+00 -0.023318802
#> 190 S190 B1b -1.005037e+00 -0.244019666
#> 191 S191 B1b -8.392970e-01 0.624407597
#> 192 S192 B1b 4.258902e-01 -0.434546036
#> 193 S193 B1b 3.107194e-01 -0.009905706
#> 194 S194 B1b -1.194293e+00 1.773255280
#> 195 S195 B1b -6.329713e-01 0.348273935
#> 196 S196 B1b 7.905550e-01 0.554031572
#> 197 S197 B1b 3.657676e-01 0.666802794
#> 198 S198 B1b 2.049237e+00 -2.135510258
#> 199 S199 B1b 3.245292e-01 -1.167321221
#> 200 S200 B1b -2.168178e+00 0.433295674