Questions tagged [melt]

In R, the "melt" function from the "reshape2" and "data.table" (and earlier, "reshape") packages converts data into a long form. Melt is also a web application framework written in PHP.

In data processing, reshaping data to a long form where each row represents only one observation of one variable is often called "melting" the data, similar to UNPIVOT in some relational databases such as .

In , the function is part of the and packages (earlier, the "reshape" package).

This functionality is also found in similar data processing tools such as .

Related tags:

840 questions
0
votes
2 answers

How to stop ggplot swapping the order of my samples?

The order of my Genes are being swapped. I would ideally like the mRNA (C or R) to come before the miRNA but as Figure1 (R:miRNA1 Expression) shows in some cases the order is swapped. Below I have added the dataframes and code which were used to…
Krutik
  • 461
  • 4
  • 13
0
votes
1 answer

Error when using reshape to restructure data from wide to long data with multiple column

I am trying to restructure my data using reshape from wide to long format but I keep getting an error. Below I wrote the code I've already tried and the error message I get. current data structure patientid Adh_catv1 Adh_catv2 Adh_catv3 …
Thandi
  • 225
  • 1
  • 2
  • 9
0
votes
1 answer

can there be a possible alternative (code) to reshape given pandas dataframe that is currently using melt function for reshaping?

I have a pandas dataframe which looks like this: Category Sector 1 Blanks Sector 2 Sector 3 Sector 4 Sector 5 Sector 6 Other Sector 7 Blank 0 1 0 0 0 0 …
LeMarque
  • 733
  • 5
  • 21
0
votes
3 answers

Unpivoting dataframe

I have a data frame looking like this : data.frame name cond CONDITION CONT1 CONT2 CONT3 CONT4 result 16.2 2.5 6.5 0.75 Test.ratio 0.23 0.15 2.5 3.5 What I want to do get is: CONDITION Result test.ratio CONT1 16.2 0.62…
0
votes
1 answer

Rotate table in R

How can I melt/reshape/rotate my table from this: profit lost obs fc.mape mean 3724.743 804.1835 427.8899 0.21037696 std.dev 677.171 406.1391 372.5544 0.06072549 To this: mean std.dev profit x lost x obs …
Rstudio123
  • 15
  • 6
0
votes
2 answers

Reshape multiples variables with melt with python, Pandas

I have survey date with 5 main variables f1_, f2_, f3_ ,f4_ and f5_ and each f*_ group variable has up to 10 sub groups, ex: f1_1 , f1_2 ,f1_3 ... or f2_1, f2_2, ... f2_10. I would like to perform a pivot_longer to reshape my dataframe in order to…
DanG
  • 689
  • 1
  • 16
  • 39
0
votes
2 answers

How to melt two dataframe columns into one column

I have this dataframe: df = pd.DataFrame({'Gene': ['419', '1036', '1167', '1629'], 'Myob': [0.261, 1.010, -0.534, 1.412], 'Myob_Ind': [0.901, 0.525, 2.588, 1.825], 'Cluster': [0, 0, 0, 0]}) Which looks…
Cam
  • 111
  • 1
  • 8
0
votes
2 answers

How to melt data.frame with multiple groups and empty suffix

I have a data.frame where multiple columns needs to be melted together based on the suffix of the column. So all columns ending with "from" should be melted into one column, same for columns ending on "to" and all columns without suffix together and…
needRhelp
  • 2,948
  • 2
  • 24
  • 48
0
votes
0 answers

r wide to long erroring row of output must be identified by a unique combination of keys

I am trying to move a long to wide format. ID Col1 Index Value Date 1333 Lateral_mm 0 5.1 1998-04-19 1333 Lateral_mm 1 3.4 1998-04-19 1333 ap_mm_axial …
Rilo Dinga
  • 79
  • 8
0
votes
2 answers

r conditional wide to long with column name pattern

This is a slightly tricky dataset where the columns are laid out like this. ID C.Date T.Date C(Area) T(Area) Level(closet)_1 Venti_1 Level(closet)_2 Venti_2 733 2013.06.18 2013.06.18 65.2 42.1 C6 …
Science11
  • 788
  • 1
  • 8
  • 24
0
votes
1 answer

How to change ColumnB to headers and headers to ColumnB

I don't know if this is a called a melt or unmelt, or pivot or unpivot, but I want to know if I can change my ColumnB to headers, starting in ColumnF (and data points under these headers), and likewise, change the headers, starting in ColumnF, to…
ASH
  • 20,759
  • 19
  • 87
  • 200
0
votes
0 answers

Transpose 24 columns into one column (24 rows) using python and sort values

I have an ascii file which contains in the first column the id of the day and in the following columns it contains values of each hour of the day (24 hours/columns). A sample of the file is shown below. day h1 h2 h3 h4 h5 h6 h7 h8 h9 h10…
Nat
  • 325
  • 2
  • 13
0
votes
2 answers

Reshaping data by appending rows from different groups to the same row

I have data as follows: DT <- structure(list(Area = c("A", "A", "A", "A", "B", "B", "B", "B" ), Year = c(1, 1, 2, 2, 1, 1, 2, 2), Group = c(1, 2, 1, 2, 1, 2, 1, 2), Population_Count = c(10, 12, 10, 12, 10, 13, 10, 11 ), Male_Count = c(5, 7, 5, 4,…
Tom
  • 2,173
  • 1
  • 17
  • 44
0
votes
1 answer

Spreading a single variable/column in a dataset with many columns, aggregating the other variables

I have a dataset as follows (for a more extensive example, please see the edits below): DT <- structure(list(Geo_level = c(50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L ), State_Code = c(1L, 1L,…
Tom
  • 2,173
  • 1
  • 17
  • 44
0
votes
0 answers

Spark solution for below problem (Transform , Pivot, CrossJoin)

This is the input dataframe: df1_input = spark.createDataFrame([ \ ("P1","A","B","C"), \ ("P1","D","E","F"), \ ("P1","G","H","I"), \ ("P1","J","K","L") ],…
gbzygil
  • 141
  • 4
  • 16