Questions tagged [reshape]

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 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.

Matlab

The 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 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 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.

3858 questions
1
vote
1 answer

expand year values to month in pandas

I have sales by year: pd.DataFrame({'year':[2015,2016,2017],'value':['12','24','30']}) year value 0 2015 12 1 2016 24 2 2017 36 I want to extrapolate to months: yyyymm value 201501 1 (ie 12/12, etc) 201502 1 ... 201512…
frank
  • 3,036
  • 7
  • 33
  • 65
1
vote
1 answer

reshape and rearrange string into specific shape

On the function below, I'm trying to reshape a string into W-like shape, and made a new output with new arrangement based on its totalLevel, check the test case at the end of the script for more clarity. I'm using nodejs, and came up with idea using…
1
vote
1 answer

How to convert huge file with huge number of rows from long to wide format in R?

I have a dataframe ACC which looks like following: The dataframe shows miRNA and Target interactions: ACC: miRNAs Targets MIMAT0000075 HIF1A MIMAT0000449 CXCR4 MIMAT0000421 CYP7A1 MIMAT0000279 STAT5A MIMAT0000076 RASGRP1 I…
beginner
  • 1,059
  • 8
  • 23
1
vote
1 answer

Making a 0 to nxn matrix and reshape it to pairs

Maybe I am wrong and I don't know how to search for it. I need to get a list of pairs (0,0) (0,1) (0,2) ... (0,999) ... (999,999) To put these values into a neural network and get the result - just a vector of length (999*999) Then I can reshape…
fisi
  • 21
  • 3
1
vote
1 answer

How to reshape this data.frame having two variables as identifiers?

Suppose I have a data.frame as follows: data = data.frame(firm = LETTERS[seq( from = 1, to = 9)], industry = seq(1,9), country = c("USA", "CAN", "DEU"), var1_10 = rnorm(9), …
Cristhian
  • 361
  • 3
  • 12
1
vote
2 answers

convert matrix of checkboxes to edgelist of column names

beginning R programmer here! I'm working on some projects for work and i'm trying to familiarize myself with the functions of R. Background in python and C, and have been relying on for- and while-loops a lot. Now with R i notice i should avoid…
JadaLovelace
  • 194
  • 4
  • 16
1
vote
2 answers

restructuring a data frame of co-variances from long to wide

A data frame have contains three variables: from - character - the name of a measure to - character - the name of another measure covariance - numeric - the covariance between the two measures Here's a link to the data. Below is the result of…
J.Q
  • 971
  • 1
  • 14
  • 29
1
vote
2 answers

converting a covariance matrix to a data frame with covariance variables

A matrix cov_mat stores the covariances between variables: a_plane a_boat a_train b_plane b_boat b_train c_plane c_boat c_train d_plane … a_plane 4.419 -0.583 0.446 0.018 -1.291 3.159 -0.954 0.488 3.111 1.100 a_boat …
J.Q
  • 971
  • 1
  • 14
  • 29
1
vote
2 answers

How to rbind reshaped data tables of different column sizes and with different names

I checked similar entries in SO, none answers my question exactly. My problem is this: Let's say, User1 has 6 purchases, User2 has 2. Purchase data is something like this: set.seed(1234) purchase <- data.frame(id = c(rep("User1", 6), rep("User2",…
maop
  • 194
  • 14
1
vote
2 answers

Numpy reshape - automatic filling or removal

I would like to find a reshape function that is able to transform my arrays of different dimensions in arrays of the same dimension. Let me explain it: import numpy as np a = np.array([[[1,2,3,3],[1,2,3,3]],[[1,2,3,3],[1,2,3,3]]]) b =…
Guido Muscioni
  • 1,203
  • 3
  • 15
  • 37
1
vote
2 answers

Reshaping pre-post data

I have a data set df <- data.frame("ID" = c("sue_1","bob_2","nick_3","joe_4"), "1_confidence.x" = c(3,3,1,5), "2_reading.x" = c(4,3,2,5), "3_maths.x" = c(3,2,4,2), "1_confidence.y"…
Gerard
  • 159
  • 1
  • 2
  • 11
1
vote
0 answers

Reshape long to wide time-series data (Unequal number of time-series within each day)

My question is a continuation of the previous questions: Reshape data.frame from long to wide on time series But with variations. It is 1) when numbers of hours within each day are unequal (minor) 2) when the start hour of the date varies(major) For…
1
vote
1 answer

Multidimensional array : Split and put back together

I am trying to turn a 3 dimensional array "upside-down" as: I have tried the inverse function, but if we look at the inverse operation in mathematical terms, it gives us another result. I need to turn without changing the data in the array. How to…
1
vote
1 answer

How to reshape data in custom function with dcast?

I have big sales data.frame with many columns - my future parameters for function (status, payment, delivery, source etc). week / item.type / source / order / payment / delivery 31 / device / desktop / 222-111 / cash / courier 32 / tariff / mobile /…
vecanoyee
  • 13
  • 2
1
vote
0 answers

Fast Fourier transform of 1D and 3D arrays

I'm doing N-body calculations using pyopencl and I need to have my data to be 1D array as input and as output of some kernel. So if I have 2D problem, I do something like this: 1D_arr=numpy.reshape(3D_arr,(LxLy)), where LxLy number of all…
GeorgePhysics
  • 71
  • 1
  • 8