In R, Matlab, NumPy and APL, reshape functions allow data to be transformed into more convenient forms.
Reshape functions allow data to be transformed into more convenient forms.
R
The r function reshapes a data frame between ‘wide’ format with repeated measurements in separate columns of the same record and ‘long’ format with the repeated measurements in separate records.
- The reshape package
- The reshape2 package, by same author, who says it "improves speed at the cost of functionality".
- Reshaping Data at Quick-R
- The tidyr package, also by Hadley Wickham, is a new package for reshaping data, which relies on the piping format introduced by magrittr.
Matlab
The matlab function allows a vector or array to be transformed into a new array with the specified dimensions.
Note that reshape
does not change the order of the elements or the number of elements in the array. reshape
only affects its shape.
NumPy
The numpy function gives a new shape to an array without changing its data. The returned array will be a new view object if possible; otherwise, it will be a copy.
APL
The apl function ⍴
allows any array to be transformed into a new array with the specified shape.
Note that ⍴
does not change the order of the elements, however it can change the number of elements in the array, recycling elements if they are insufficient to fill the requested shape, or truncating trailing elements if the requested shape cannot hold them all.