Spread data.frame

spread_array(data, value, ...)

Arguments

data

a dataframe with integer indexed positions in an array

value

data to be spread into the array

...

unquoted dimnames used to build array

Value

multidimensional array

Details

make sure all colnames supplied to ... are consecutive interger indexed positions

See also

gather_array

Examples

a <- array(1:100, dim=c(10, 5, 2)) ga <- gather_array(a, sequence, A, B, C) head(ga)
#> A B C sequence #> 1 1 1 1 1 #> 2 2 1 1 2 #> 3 3 1 1 3 #> 4 4 1 1 4 #> 5 5 1 1 5 #> 6 6 1 1 6
spread_array(ga, sequence, A, B, C)
#> , , 1 #> #> [,1] [,2] [,3] [,4] [,5] #> [1,] 1 11 21 31 41 #> [2,] 2 12 22 32 42 #> [3,] 3 13 23 33 43 #> [4,] 4 14 24 34 44 #> [5,] 5 15 25 35 45 #> [6,] 6 16 26 36 46 #> [7,] 7 17 27 37 47 #> [8,] 8 18 28 38 48 #> [9,] 9 19 29 39 49 #> [10,] 10 20 30 40 50 #> #> , , 2 #> #> [,1] [,2] [,3] [,4] [,5] #> [1,] 51 61 71 81 91 #> [2,] 52 62 72 82 92 #> [3,] 53 63 73 83 93 #> [4,] 54 64 74 84 94 #> [5,] 55 65 75 85 95 #> [6,] 56 66 76 86 96 #> [7,] 57 67 77 87 97 #> [8,] 58 68 78 88 98 #> [9,] 59 69 79 89 99 #> [10,] 60 70 80 90 100 #>