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

Using dcast to cast a wide format when the variables per time period are not uniquely specified

I would like to convert this csv file into a long format. It currently look as follows: Every ID is listed 1 time for each years, so a total of 7 times. What I would like to do is to for each ID have one row, where the variables are listed as…
Tom
  • 2,173
  • 1
  • 17
  • 44
1
vote
1 answer

How to reshape a PSPP table into another form of table

I Have a Dataframe that is Mean Tables by PSPP. I would like to reshape it in order to manipulate it easier for plots in calc. What I want to do? This Table contains descriptive statistics such as Mean, SD, N. The levels of Categorical variables…
Estatistics
  • 874
  • 9
  • 24
1
vote
1 answer

Is EJML reshape function efficient in case of sparse matrices?

I would like to change a sparse matrix dimensions dynamically. However, I'm concerned with efficiency. Does this operation copy all the content of the first matrix into a bigger one ? In that case, would it be a better idea to increase matrix…
1
vote
1 answer

Reshape function values for Heatmap plot

I would like to plot a heatmap of y=f(r,phi). The code I use is to get the values, import numpy as np h1=1.7 h2=0.5 inclination=np.pi/6 def power(inclination,phi): h1=1.7 h2=0.5 D = np.arange(0.5, 12.0, 0.1) r =…
user1993416
  • 698
  • 1
  • 9
  • 28
1
vote
3 answers

Reshape from wide to long in R where id and value of id are in the same row

I am having trouble to reshape my data set to a panel data set. My df looks as follows id s1 s2 s3 s4 ct1 ct2 ret1 ret2 ret3 ret4 1 a b c d 0.5 0.5 0.6 0.7 0.8 0.5 2 c b a d 0.6 0.6 0.7 0.6 0.5 0.4 3 a …
Jj Blevins
  • 355
  • 1
  • 13
1
vote
1 answer

Reshape backandforth Wide -> long -> wide

I change my data to xts to do simple calculations, so I first reshape my data from long to wide, do my calculations and want to reshape it back. First my data looks like: date seriesid totret 1912-08-15 57409 …
Bart
  • 317
  • 4
  • 18
1
vote
3 answers

Frequency table for multiselect survey question across several columns

I want to do a fairly common analysis of survey questions in R, but am stuck in the middle. Imagine a survey where you are asked to answer which brands do you associate with certain features (e.g. "brands" could be PlayStation, XBox..., and features…
deschen
  • 10,012
  • 3
  • 27
  • 50
1
vote
2 answers

R: reshape/cast memory error

I have a large table (x) to covert to matrix (y). I used two different commands. x <- reshape(y, direction="wide", v.names="column1", timevar="column2", idvar="column3") or x <- cast(x, column1~column2) After waiting for several…
Sally
  • 13
  • 3
1
vote
1 answer

Transforming column headers to values

I want to transform this dataframe : Name Address Town Central1 Central2 Central3 Central4 Jean blabla blabla2 1 2 3 NaN James BLABLA BLABLA2 5 6 NaN 8 to this…
Saguaro
  • 233
  • 3
  • 12
1
vote
0 answers

"reshape()" function in Eigen tensor does not compile

I want to use "reshape()" fuction in Eigen unsupported tensor, but my source code cannot be compiled. The compilation was done as follows. g++ -std=c++14 -I (path to Eigen) eigen_practice.cpp -o eigen_practice and here is my source code. # include…
Hamcatu
  • 11
  • 1
1
vote
1 answer

R: Reshaping Multiple Columns from Long to Wide

Using following data: library(tidyverse) sample_df <- data.frame(Letter = c("a", "a", "a", "b", "b"), Number = c(1,2,1,3,4), Fruit = c("Apple", "Plum", "Peach", "Pear", "Peach")) Letter Number…
rsylatian
  • 429
  • 2
  • 14
1
vote
1 answer

Efficiently reshaping big datasets

The World Development Indicator looks as follows library(data.table) WDI <- fread("CountryName CountryCode IndicatorName IndicatorCode 1960 1961 2017 ArabWorld ARB A FX.OWN.TOTL.ZS 37.16521072 37.16521072 37.16521072 ArabWorld ARB…
Tom
  • 2,173
  • 1
  • 17
  • 44
1
vote
2 answers

Reshaping 4x1 DataFrame into 2x2 DataFrame

I have a DataFrame as below: import pandas as pd df_testcase = pd.DataFrame( ['16SCSE102014', '15/03/2019', '16SCSE101350', '15/03/2019'] ) 0 0 16SCSE102014 1 15/03/2019 2 16SCSE101350 3 15/03/2019 I need to convert it…
Komal
  • 48
  • 5
1
vote
3 answers

Reshaping a Factor in R

I have the following character string: str(seqN) chr [1:704] "010000100100001010000100010001000100000100101000010001001000001001001000001000010010000100100100010000101000010"| __truncated__ ... Yes they are very long strings (704 strings of…
1
vote
1 answer

reshape and generate new date data in pandas dataframe

I have a pandas dataframe: import pandas as pd import numpy as np d={'ID':['A1','A1','A2','A2','A2'], 'date':['Jan 1','Jan7','Jan4','Jan5','Jan12'],'value':[10,12,3,5,2]} df=pd.DataFrame(data=d) df ID date value 0 A1 Jan 1 10 1 A1 …
frank
  • 3,036
  • 7
  • 33
  • 65
1 2 3
99
100