This question already has an answer here: Reshaping multiple sets of measurement columns (wide format) into single columns (long format) 5 answers I have the following data: structure(list(id = c(174L, 187L, 188L, 190L, 213L, 234L), p7 = c(1L, 1L, NA
I am working to translate matlab code to python code. I want to implement reshape like matlab. the matlab code is: reshape(array,size1,[]) I want to reshape 2D shape with one input size. How can I implement it in python?To expand on Ali's answer, you
I have a pandas dataframe with about 100 columns of following type: X1 Y1 X2 Y2 X3 Y3 0.78 0.22 0.19 0.42 0.04 0.65 0.43 0.29 0.43 0.84 0.14 0.42 0.57 0.70 0.59 0.86 0.11 0.40 0.92 0.52 0.81 0.33 0.54 1.00 w1here (X,Y) are basically pairs of values I
I have a time series data: date value 12 2016-08-05 854 13 2016-07-29 1065 14 2016-07-22 878 15 2016-07-15 1145 16 2016-07-08 735 17 2016-07-01 730 18 2016-06-24 726 19 2016-06-17 1011 20 2016-06-10 1019 What I want is a matrix of monthly data: Jan F
I have an array (a) that is the shape (1800,144) where a[0:900,:] are all real numbers and the second half of the array a[900:1800,:] are all zeros. I want to take the second half of the array and put it next to the first half horizontally and push t
FAMILY<- c('FAMILYA', 'FAMILYA', 'FAMILYA', 'FAMILYA', 'FAMILYA', 'FAMILYB', 'FAMILYB', 'FAMILYB', 'FAMILYB', 'FAMILYB', 'FAMILYC', 'FAMILYC', 'FAMILYC', 'FAMILYC', 'FAMILYC') CHILDREN<-c('JAKE', 'PETE', 'JASON', 'KEVIN', 'ALFRED','DALE', 'STEVE', '
I have two arrays x1 and x2, both are 1*14 arrays i am trying to zip them up and then perform reshape. The code is as below ; x1 Out[122]: array([1, 2, 3, 1, 5, 6, 5, 5, 6, 7, 8, 9, 7, 9]) x2 Out[123]: array([1, 3, 2, 2, 8, 6, 7, 6, 7, 1, 2, 1, 1, 3]
I have a dataframe in my R script that looks something like this: ID B C 1539 Blue 8 1539 Blue 4 1539 Red 9 1539 Red 13 1539 Yellow NCAA 3574 Green RA 3574 Green RA 3574 Green RA 3574 Red 1 3574 Red 1 How do I aggregate column C and transform the dat
I have a data frame like this: Month Site1 Site2 Site3 Jan 5 6 8 Feb 2 3 4 Mar 8 2 2 I want to change it to Site Jan Feb Mar Site1 5 2 8 Site2 6 3 2 Site3 8 4 2 How do I do this?We can use recast from library(reshape2) library(reshape2) dfN <- recast
I'd like to combine/pair multiple columns in a data frame as pairs of column cells in the same row. As an example, df1 should be transformed to df2. df1 col1 col2 col3 1 2 3 0 0 1 df2 c1 c2 1 2 1 3 2 3 0 0 0 1 0 1 The solution should be scalable for
I've been working on some data wrangling based on a column including free text. I want to identify a set of particular strings from this text, create a column to designate a match and then replicate a row if there are multiple string matches in a par
I have an array of numbers whose shape is 26*43264. I would like to reshape this into an array of shape 208*208 but in chunks of 26*26. [[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [10,11,12,13,14,15,16,17,18,19]] becomes something like: [[0, 1, 2, 3, 4], [10,1
I have the following example data rankP amount defaulted 1 45925 1 1 369550 1 1 177975 1 1 157850 0 2 30400 1 2 93950 0 2 194075 1 3 30975 0 3 66775 1 3 225850 1 and I would like to transform the data so that I'll have the amount per-rank, per-defaul
Is there a function to collapse several columns values into 1 factor? Every record has exactly 1 TRUE value for columns 2:4. The resulting value for a record should be the column's name which has the true value. input data frame: data <- data.frame(u
I have a long nx3 matrix. For eg, I take a 9x3 matrix A = 8 9 8 9 2 9 2 9 6 9 9 1 6 5 8 1 8 9 3 2 7 5 4 7 9 9 7 Now I want it reshaped, (taking successive 3x3 sub-matrix to the next dimension) such that, out(:,:,1) = 8 9 8 9 2 9 2 9 6 out(:,:,2) 9 9
I have a dataframe that looks like this: >>> x[x.site_num<3] Out[44]: 6890011 site_num item 0 3.226545 0 1 3.226698 1 2 3.221418 2 12 3.231642 0 13 3.226331 1 14 3.221449 2 24 3.231123 0 25 3.226454 1 26 3.226240 2 36 3.226484 0 37 3.226240 1
I'd like to do the following data transformation in R Name Value type1 value1.1 type2 value2.1 type3 value3.1 type1 value1.2 type2 value2.2 type3 value3.2 type1 value1.3 type2 value2.3 type3 value3.3 should become: Name Value1 Value2 Value3 type1 val
I have picked up an awful public data set that needs a lot of work to make it useful. Here is a simplification: Molten<-data.frame(ID=round(runif(100, 0, 50),0), Element=c(rep("Au", 20), rep("Fe", 10), rep("Al", 30),rep(&q
My original data looks like this data id1,id2,value A,1,-1.09 B,1,-1.033 C,1,-1.5 A,2,9.1 B,2,2.006 C,2,-3.95 I tried using reshape package in R to reshape it using the command cast(data, id2 ~ id1) but this is converting all my values from value col
Say I have a data frame where one column is some repeating value (dates, IDs, etc). Is there a way to convert a data frame into a now data frame with columns instead of replicating rows? Basically I want to transpose something like this: col1 col2 co
This question already has an answer here: Reshaping multiple sets of measurement columns (wide format) into single columns (long format) 5 answers I have data from an online survey where respondents go through a loop of questions 1-3 times. The surve
I use R to analyze stock data stored in SQLite database. Currently the stock data is daily and stacked like this: Code,Date,Price A,2013-05-01,100 A,2013-05-02,102 A,2013-05-03,101 ... B,2013-05-01,53 B,2013-05-02,55 B,2013-05-03,56 ... C,2013-05,02,
I have the data set: df <- data.frame(g = c("X", "X", "Y", "Z", "Y", "Z", "Z"), r = c("A", "B", "C", "C", "A", "A", "
I have this matrix(head and tail is given below), and it has lat ,lon and variable for USA for a time period starts from January 1948 to December 2004: # head of matrix lon lat month value 1 -124.5 31.5 1980.1 NA 2 -123.5 31.5 1980.1 NA 3 -122.5 31.5
Lets say I have a data.table with these columns nodeID hour1aaa hour1bbb hour1ccc hour2aaa hour2bbb hour2ccc ... hour24aaa hour24bbb hour24ccc for a total of 72 columns. Let's call it rawtable I want to reshape it so I have nodeID hour aaa bbb ccc fo
So I am sorting a matrix one row at a time in descending that is 130X130, and I want to create a new matrix where the row name is the same, but the each sorted row column names are where the data was and the data in parenthesis next to the according
I have a 40x16 matrix or 8 5x16 one below the other i.e. aligned vertically. I want to get a 5x128 matrix from that such that I align the 8 5x16 matrices horizontally. is there an efficient/quicker (rather than the hardcoded for loops) way to do this
New to MySQL and trying to carry something over from R. I have a data table with two columns, similar to the following, with a level-2 id and a nested id: level2id | nestedid | 1 | 1 | 1 | 2 | 1 | 3 | 2 | 1 | 2 | 2 | ... I want to restructure the dat
Melt and Cast are popular operations to handle data in R. In F# that would be sequences of records of same type or something close to it. Are you aware of any such functions in F#? (If not, who would be interested in making some strongly typed versio
I have a dataset with about 3 million rows and the following structure: PatientID| Year | PrimaryConditionGroup --------------------------------------- 1 | Y1 | TRAUMA 1 | Y1 | PREGNANCY 2 | Y2 | SEIZURE 3 | Y1 | TRAUMA Being fairly new to R, I have