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

Row combination to remove NA's based on common ID's

I recently asked a question regarding database managemen in R packages tidyr, dplyr or similar in this link (Reorganizing columns by two column combination). It was helpful, I managed to do the proposed code, but I was wring in the final format I…
gfmg1992
  • 99
  • 2
  • 8
1
vote
2 answers

Reshaping rows to lists by variable in R

I have a data frame that looks like this: class id 1 foo 1 2 bar 1 3 baz 1 4 baz 2 5 bar 2 6 foo 2 7 foo 3 8 foo 3 9 foo 3 My goal is to reshape it into a data frame that gathers the classes into a list, in the order…
iskandarblue
  • 7,208
  • 15
  • 60
  • 130
1
vote
1 answer

Is there a way where i can rearrange a dataframe and turn it into a 3 column dataframe

I am having trouble figuring out how to move around my variables/data in order to achieve a 3 column data frame. the original data frame contains 200+ columns and I want move the data around so that it looks like the example i have shown below. Do…
Felix Chan
  • 21
  • 4
1
vote
1 answer

Difficulty with Long to Wide to Long Format in R

I am trying to make a graph similar to a correlation plot. However, my data was in long format and I wanted to only show the lower triangle of the matrix. Therefore, I took my data and reshaped it using the…
Jack Armstrong
  • 1,182
  • 4
  • 26
  • 59
1
vote
1 answer

How Do I Correctly Shape my Data for my NN Model?

I am trying to create a basic neural network model in Keras that will learn to add positive numbers together and am having trouble with shaping the training data to fit the model: I have already tried numerous configurations for the "input_shape"…
Aalok Borkar
  • 153
  • 3
  • 12
1
vote
2 answers

Reshape list according to tags

Update: The data above doesn't really mirror my data, so here is an update: tag <- c("\\ID", "\\a", "\\b", "\\ID", "\\b", "\\ID", "\\a", "\\b", "\\ID", "\\ID") content <- c("ID_x", "text2", "text3", "ID_y", "text6", "ID_z", "text7", "text8",…
1
vote
0 answers

How do I customize the format of data results in R

I have get lots of result from my model and I need to copy the results to MS word. But it's too much!! I'm going to copy over 30,000 results! my result just like down here. I want to every disease in every sheet. I can do this with code like…
ZW.Lee
  • 33
  • 2
1
vote
1 answer

Unblundle (weird reshape long) id-"dump-var" data into a long data.frame/table in R

In this toy reproducible example below, I have a data.frame with two columns. id dump: a string variable that acts as a "dump" for a bunch of characteristics of id and can have an arbitrary number of elements in each row. In dump, characteristics…
LucasMation
  • 2,408
  • 2
  • 22
  • 45
1
vote
1 answer

Reshaping database using reshape package

I would like to reshaping some rows of my database. In particular I have some row that it replicate for the Id column. I would like to convert this row in column. I provide a code that it represent a example of my database. I'm trying with t() and…
matte85
  • 35
  • 3
1
vote
3 answers

Reshape the data from long to wide format

I am looking for swift way of reshaping the data from long to wide format. Right now I have tried a code with nest for loops, though the job gets done, it takes a long time to generate the output. SN NN EE Service_tier A B C economy B C C …
Vasuki Rao
  • 37
  • 3
1
vote
0 answers

Does Keras Reshape maintain data structure and order through multiple reshape layers to and fro?

I am relying on multiple layers of Keras Reshape but have no ability to check that they are working together properly. I start with a preprocessed tensor of (BatchSize, 50, 100, 300). Where 5 news articles a day for 10 days (50) are represented by…
Joshua Clancy
  • 121
  • 1
  • 9
1
vote
2 answers

Getting Data in a single row into multiple rows

I have a code where I see which people work in certain groups. When I ask the leader of each group to present those who work for them, in a survey, I get a row of all of the team members. What I need is to clean the data into multiple rows with…
LordVoldemort
  • 107
  • 1
  • 7
1
vote
1 answer

I want to change a order for reading array in python, do I have to use reshape?

I read a tif image(3D stack), and its original size is 100 X 120 X 150(example). But, when I imported this, this size was 150 X 120 X 100. I tried to reshape this by using matrix.reshape, but I figured out that if I used this reshape, its element…
Newbie0105
  • 119
  • 1
  • 12
1
vote
0 answers

How to interpolate one image matrix into another one?

I've got two image matrices. Both contain radar information about the same area, with different units and values. But, these circles are not fit onto each other. One is like it's zoomed in. I would like to do some element operations in these…
Kaveh P. Yousefi
  • 165
  • 1
  • 2
  • 13
1
vote
2 answers

Reshape to long and complete with NAs

I need to reshape a df, complete it with missing years and create a variable tracking status change. The issue is that some values are missing and the code I wrote brakes down on those. Toy example: library(data.table) df <-…
MCS
  • 1,071
  • 9
  • 23
1 2 3
99
100