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
1 answer

Using melt() function from data.table for multiple columns in R

I have a composite score (BASFI) which consists of components Q1-Q10 and a bunch of variables I want unchanged. I wanted to go from a wide format to a long format. The composite score and components have been measured at 4 time points. Please see…
Pashtun
  • 123
  • 7
0
votes
0 answers

Reshape unbalanced data from wide to long using reshape function

I am currently working on longitudinal data and trying to reshape the data from the wide format to the long. The naming pattern of the time-varying variables is r*variable (for example, height data collected in wave 1 is r1height). The identifiers…
zjppdozen
  • 63
  • 5
0
votes
0 answers

How to convert columns into rows but with respect to specific column?

How to convert columns into rows but with respect to specific column using python? for example i have a data like this enter image description here and i want result like this. enter image description here I used melt, transpose and some other…
0
votes
2 answers

Chain df.str.split() in pandas dataframe

Edit: 2022NOV21 How do we chain df.col.str.split() since this returns the split columns if expand = True I am trying to split a column after performing .melt(). If I use assign I end up using the original column and the melted column actually does…
manny
  • 317
  • 1
  • 2
  • 9
0
votes
0 answers

stacking columns in R

I have a dataframe like this : | A_replicate_1 | A_replicate_2 | B_replicate_1 | B_replicate_2 | How can I modify this dataframe to something like this by stacking A replicates into one column and B replicates into the other column? | A …
0
votes
0 answers

Running ANOVA test after melt function

I am trying to run an ANOVA test after using melt and the error keeps popping up. I do not know what I'm doing wrong Error in eval(predvars, data, env) : object 'W' not…
0
votes
1 answer

Why do I have this result: SyntaxError: positional argument follows keyword argument

sub4 = sub4.melt(id_vars = 'Sort_order','year' ,var_name= 'sex' ,value_name= "International_migrant_stock_at_mid-year") I try to melt the dataframe to separate sex and migrant stock. I think my…
0
votes
1 answer

How to calculate percentage value for two binnary columns and one nominal column in DataFrame ine Python Pandas?

I have DataFrame in Python Pandas like below: data type: ID - int64 X1 - int64 X2 - int64 CH - int64 ID X1 X2 CP CH 111 1 0 10-20 1 222 1 0 10-20 1 333 0 1 30-40 0 444 1 1 30-40 1 555 0 1 30-40 1 And I need to create new…
unbik
  • 178
  • 9
0
votes
1 answer

How to do aggregation based on 3 binary columns and range column to calculate percentage participation in thet combination in Python Pandas?

I have DataFrame in Python Pandas like below: ID U1 U2 U3 CP CH 111 1 1 0 10-20 1 222 1 0 1 10-20 1 333 0 1 0 20-30 0 444 0 1 1 40-50 0 555 1 0 0 10-20 0 And I need to create column with percent of '1' in column 'CH' per…
unbik
  • 178
  • 9
0
votes
1 answer

Melt/ reshape dataframe to combine columns and fill rows with NAs

Apologies that there is a wealth of information on this site about melting and reshaping data, however, I cannot find the answer to my question on any of the pages I've visited. I have a data set which looks something like: A Year | A Mean Temp | A…
0
votes
0 answers

Split plot legend per group of variables

I would like to split the legend that is generated by ggplot based on the variables that are taken from the data frame. I'm starting from melted data. Using the Iris data set, I'd like to get this: What I'm looking for is to obtain a legend box…
Gerlex
  • 53
  • 5
0
votes
1 answer

How can I groupby index and pivot columns in pandas

I have this dataframe: And I'd like to unstack (or melt? or pivot?) the dataframe so that for every Coupon in the index, the SMM_diff gets its own column. Something like: SMM_diff_2.0 SMM_diff_2.5 ... rest of…
hulio_entredas
  • 675
  • 1
  • 12
0
votes
1 answer

How to construct a grouped boxplot including 6 groups ( expression levels of 6 different genes) and 2 subgroups (Control & Cancer) in R using ggplot2

The data is similar to that indicated as below. It would greatly be appreciated if somebody can help me in this case. Gene Control expression Cancer expression BAX 12 34 BID 18 …
0
votes
1 answer

Correlation plots and bar plots to visualize four datasets in R

I've got some scores post-ssGSEA score calculation into four data frames in r. The data frame looks something like this: dput(t_ssgsea_OPC[1:250,]) structure(list(Classical = c(0.170108215263314, 0.114886799846454, -0.0433822339467479,…
driver
  • 273
  • 1
  • 13
0
votes
1 answer

Reshape wide data to long with multiple columns in R

I have the following data: country <- c("afg", "alb", "aus") gdp_2018 <- c(123, 532, 555) gdp_2019 <- c(233, 531, 621) gdp_2020 <- c(112, 231, 323) inf_2018 <- c(0.1, 0.2, 0.3) inf_2019 <- c(0.01, 0.01, 0.2) inf_2020 <- c(0.5, 0.4, 0.4) df <-…
Muhammad Kamil
  • 635
  • 2
  • 15