Skip to contents

Convert data from long to wide format

Usage

long2wide(
  data,
  within = c(),
  between = c(),
  dv = "y",
  id = "id",
  sep = faux_options("sep")
)

Arguments

data

the tbl in long format

within

the names of the within column(s)

between

the names of between column(s) (optional)

dv

the name of the DV (value) column

id

the names of the column(s) for grouping observations

sep

separator for factor levels

Value

a tbl in wide format

Examples

df_long <- sim_design(2, 2, long = TRUE)

long2wide(df_long, "A", "B")
#>       id  B1         W1a         W1b
#> 1   S001 B1a -1.57757002 -0.57122493
#> 2   S002 B1a -1.40381594  0.24210169
#> 3   S003 B1a  0.57783908  0.64267442
#> 4   S004 B1a -0.16065780  0.40290325
#> 5   S005 B1a -0.09313352  0.92877549
#> 6   S006 B1a -1.91998674 -0.35870674
#> 7   S007 B1a -1.04383424  0.05522385
#> 8   S008 B1a  0.12614993  1.34644468
#> 9   S009 B1a -0.61226380  0.12799747
#> 10  S010 B1a  0.68487208  1.70852471
#> 11  S011 B1a -0.36708994  1.05579535
#> 12  S012 B1a -0.91623348 -0.96808938
#> 13  S013 B1a  1.38803934 -0.02299383
#> 14  S014 B1a  0.37691744 -0.04241202
#> 15  S015 B1a  2.26772231  1.03995317
#> 16  S016 B1a  0.83171445  1.73945508
#> 17  S017 B1a -0.51890359  0.73378127
#> 18  S018 B1a -1.64065533 -1.13506774
#> 19  S019 B1a -0.43645725  0.74311781
#> 20  S020 B1a -0.18590812  0.28095067
#> 21  S021 B1a  0.66683470 -1.63309616
#> 22  S022 B1a  0.96142249  1.01029215
#> 23  S023 B1a -0.80416044  0.20503120
#> 24  S024 B1a  0.64622400 -0.79338565
#> 25  S025 B1a  0.50234321 -0.64310794
#> 26  S026 B1a  1.24521538 -1.35911277
#> 27  S027 B1a  0.21950465  0.85737541
#> 28  S028 B1a -0.97335159 -0.71853189
#> 29  S029 B1a -0.27413908  0.36125064
#> 30  S030 B1a -0.27066018  1.20098587
#> 31  S031 B1a -1.99706537 -1.14481428
#> 32  S032 B1a  0.65850341  0.92482680
#> 33  S033 B1a -1.67425858 -0.86976724
#> 34  S034 B1a  1.39901931 -0.21930741
#> 35  S035 B1a -0.95692547 -0.53842236
#> 36  S036 B1a -0.89647807  0.12188877
#> 37  S037 B1a -1.43659663  0.14329839
#> 38  S038 B1a -0.95932776 -1.40157579
#> 39  S039 B1a  0.75571971 -1.19387219
#> 40  S040 B1a -1.29929157 -1.18240685
#> 41  S041 B1a -0.48602293 -1.05593807
#> 42  S042 B1a  0.95615847 -0.12471988
#> 43  S043 B1a  0.08442225 -0.58779907
#> 44  S044 B1a -0.74492249  0.57089605
#> 45  S045 B1a -0.66728315  0.70145256
#> 46  S046 B1a -0.72640523  1.49914776
#> 47  S047 B1a -1.81715522  0.44250255
#> 48  S048 B1a -0.71728218 -0.50703298
#> 49  S049 B1a -2.53186656 -0.51876514
#> 50  S050 B1a  1.20904827 -0.30325994
#> 51  S051 B1a  1.35894406  0.83165260
#> 52  S052 B1a -1.16533487 -1.26195972
#> 53  S053 B1a  2.24146681 -1.15492708
#> 54  S054 B1a -0.46755860  0.16216992
#> 55  S055 B1a -1.55570433 -0.87002263
#> 56  S056 B1a  0.21703977 -0.20468617
#> 57  S057 B1a -0.90074847 -0.17209063
#> 58  S058 B1a -0.58883578 -0.36261721
#> 59  S059 B1a -0.56689754 -0.41547894
#> 60  S060 B1a  0.61721694 -0.25539270
#> 61  S061 B1a -0.19807118  0.29492070
#> 62  S062 B1a  0.42025575  0.70984497
#> 63  S063 B1a  0.02146401 -0.78340306
#> 64  S064 B1a -0.90983281  0.44525536
#> 65  S065 B1a -0.91357314 -1.00087905
#> 66  S066 B1a -0.01609905 -1.08971023
#> 67  S067 B1a  2.94860580  0.45192599
#> 68  S068 B1a  0.42901622  1.05110081
#> 69  S069 B1a -1.30311564  0.51617074
#> 70  S070 B1a -0.40212041  1.43583590
#> 71  S071 B1a  0.61088448 -0.82678614
#> 72  S072 B1a -1.76395185  0.29214457
#> 73  S073 B1a  0.49713798  1.27834127
#> 74  S074 B1a -0.62639972 -0.13166606
#> 75  S075 B1a -0.24662844 -0.52789908
#> 76  S076 B1a -0.47510636  1.55080415
#> 77  S077 B1a -1.14326777  0.57183627
#> 78  S078 B1a -0.11259405  1.27739326
#> 79  S079 B1a  1.51710272  0.61425508
#> 80  S080 B1a -0.70495776 -0.86882473
#> 81  S081 B1a -1.88226849 -0.76366761
#> 82  S082 B1a -0.84239900  0.29111342
#> 83  S083 B1a -1.61491537  1.10769113
#> 84  S084 B1a -0.52678711 -0.72894584
#> 85  S085 B1a  0.31987320  1.12052955
#> 86  S086 B1a -0.95017597  1.14387190
#> 87  S087 B1a  0.47220748  1.74507783
#> 88  S088 B1a -1.07403139  1.19450182
#> 89  S089 B1a  0.38492639 -0.79965940
#> 90  S090 B1a -0.59568552 -1.75013649
#> 91  S091 B1a -0.49385894  0.29293944
#> 92  S092 B1a  0.13502681  0.42110138
#> 93  S093 B1a  2.06469638 -0.48618564
#> 94  S094 B1a  0.27165766 -0.43318813
#> 95  S095 B1a -0.13390082  0.95675071
#> 96  S096 B1a -0.59312179 -2.65613935
#> 97  S097 B1a -0.16977153  0.26724134
#> 98  S098 B1a  0.53827313  0.37297357
#> 99  S099 B1a -1.84067989  0.66227885
#> 100 S100 B1a  0.88029881 -0.19456706
#> 101 S101 B1b  1.02075718 -0.21356893
#> 102 S102 B1b -0.32111374 -0.96258419
#> 103 S103 B1b  0.77927884  0.64593809
#> 104 S104 B1b -0.79717300 -0.45637106
#> 105 S105 B1b  1.04909136  0.93857063
#> 106 S106 B1b  0.42034187  0.33840242
#> 107 S107 B1b -0.39164373  0.63785120
#> 108 S108 B1b  1.11894240  1.16474872
#> 109 S109 B1b -1.59374568 -0.71394092
#> 110 S110 B1b -0.35629011  1.43173320
#> 111 S111 B1b  0.40078339  0.47953178
#> 112 S112 B1b  0.02035913  1.41666806
#> 113 S113 B1b  0.05282962 -1.29352978
#> 114 S114 B1b  0.44740122 -0.58304078
#> 115 S115 B1b -1.40930375 -0.30291975
#> 116 S116 B1b  0.36411440  0.32240156
#> 117 S117 B1b -0.51894714  0.22216601
#> 118 S118 B1b -1.25515560 -0.37686379
#> 119 S119 B1b -0.63473576  0.67575072
#> 120 S120 B1b  1.05251066 -0.96581268
#> 121 S121 B1b  0.33380037 -0.30648184
#> 122 S122 B1b  1.20878338 -1.05994421
#> 123 S123 B1b -0.66594203  0.50570717
#> 124 S124 B1b  0.48269865 -0.86546242
#> 125 S125 B1b  0.49881132 -0.53620965
#> 126 S126 B1b -0.51784210  0.66209729
#> 127 S127 B1b  1.27270301  2.31606818
#> 128 S128 B1b -0.36017852 -1.54110626
#> 129 S129 B1b  0.64280856  1.09995172
#> 130 S130 B1b  0.77459551  0.12183599
#> 131 S131 B1b  1.02643615  1.32841217
#> 132 S132 B1b -0.69164445 -2.24454732
#> 133 S133 B1b -0.52571117  0.79113207
#> 134 S134 B1b  0.73152775  0.75927956
#> 135 S135 B1b  0.20793456  0.17518092
#> 136 S136 B1b  1.86557551 -0.42014570
#> 137 S137 B1b -2.78219892 -0.13149521
#> 138 S138 B1b  0.48630303 -0.35307762
#> 139 S139 B1b  0.15208469  1.53719279
#> 140 S140 B1b  1.12074755 -1.97385316
#> 141 S141 B1b  1.34202763 -1.18526262
#> 142 S142 B1b -0.72864445  0.66329933
#> 143 S143 B1b -2.15096867 -3.17300073
#> 144 S144 B1b -0.49882575 -0.69986984
#> 145 S145 B1b  0.28812844 -0.01416760
#> 146 S146 B1b  0.68617163  0.61054395
#> 147 S147 B1b -1.28895757 -0.26912671
#> 148 S148 B1b  0.78407422 -0.77083413
#> 149 S149 B1b  0.08136542 -1.54332532
#> 150 S150 B1b  0.38377113 -1.05589165
#> 151 S151 B1b -2.04288033  0.63803603
#> 152 S152 B1b -0.52905932 -0.48794932
#> 153 S153 B1b -2.24280226 -1.50091694
#> 154 S154 B1b -0.44586824  0.73576005
#> 155 S155 B1b  0.68885168  1.99050907
#> 156 S156 B1b -0.37165053 -0.40482055
#> 157 S157 B1b -1.40664583  1.79050794
#> 158 S158 B1b -1.67971884 -0.34266209
#> 159 S159 B1b  1.33054179  1.06430387
#> 160 S160 B1b -0.27699626  0.05416025
#> 161 S161 B1b  1.68594159 -0.38827422
#> 162 S162 B1b -0.97419204 -0.19188892
#> 163 S163 B1b  1.03789738 -0.12394474
#> 164 S164 B1b  0.29602019 -0.93241707
#> 165 S165 B1b  1.59007312  0.12207656
#> 166 S166 B1b -0.52720997  0.46406504
#> 167 S167 B1b  1.31807424  0.37245397
#> 168 S168 B1b  1.13732874 -0.24329887
#> 169 S169 B1b  0.33035420 -2.18532565
#> 170 S170 B1b  2.39558325 -0.10226523
#> 171 S171 B1b -0.48586697  1.22642111
#> 172 S172 B1b -0.33638170  1.03744200
#> 173 S173 B1b  0.32829142  0.16370607
#> 174 S174 B1b  0.13293795 -1.23227282
#> 175 S175 B1b  1.87868330  0.22591115
#> 176 S176 B1b -1.04464051 -0.80051325
#> 177 S177 B1b -0.63150401  0.36898574
#> 178 S178 B1b  0.32153305 -2.64567760
#> 179 S179 B1b  1.36959580 -2.02402823
#> 180 S180 B1b  0.33658531 -0.89967364
#> 181 S181 B1b  0.68197707  0.60911917
#> 182 S182 B1b  0.26267279 -1.67720109
#> 183 S183 B1b -0.18201122  1.76698692
#> 184 S184 B1b  0.42257978 -1.54168047
#> 185 S185 B1b -0.32567327 -0.10222726
#> 186 S186 B1b -1.67921649  0.88770236
#> 187 S187 B1b -0.31575952  1.10326746
#> 188 S188 B1b -0.76818424 -0.10835834
#> 189 S189 B1b  0.60101925 -0.84090277
#> 190 S190 B1b -2.00222706  0.04493288
#> 191 S191 B1b  1.69857871 -1.46980661
#> 192 S192 B1b -2.04393970 -1.65200722
#> 193 S193 B1b  0.66396346 -0.30444167
#> 194 S194 B1b  0.72307438  1.19035527
#> 195 S195 B1b -1.46272471  0.62558029
#> 196 S196 B1b -1.98983426 -1.13384253
#> 197 S197 B1b  1.45595380 -1.18351359
#> 198 S198 B1b -0.31496022 -1.25406136
#> 199 S199 B1b -0.90814496  1.62099878
#> 200 S200 B1b -0.66243743  0.43974153