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
1
vote
2 answers

PostgreSQL: Melt table and calculate percentages for different groups

I am trying to create a funnel chart, but my data is in a wide format right now. It has a couple groups that I want to compare (e.g., A and B in the example below) and they are on different scales, so I want to use proportions as well as the raw…
NLR
  • 1,714
  • 2
  • 11
  • 21
1
vote
1 answer

R: how to plot data from two separate data.frames

dat.x <- data.frame(var1 = 1, var2 = 1.5, var3 = 3) dat.y <- data.frame(var1 = 3, var2 = 1.5, var3 = 3) plot(dat.x$var1, dat.y$var1, col = "red", xlim = c(0.6, 3.5), ylim = c(0, 4), xlab = "x", ylab = 'y') points(dat.x$var2, dat.y$var2, col =…
Adrian
  • 9,229
  • 24
  • 74
  • 132
1
vote
1 answer

How to reduce & melt dataframes inside a list together

UPDATED: I have dataframes inside a list that looks like this: v1 <- data.frame(time = c(1, 3, 5, 9, 33), X = c(4, 3, 2, 3, 12), SE = c(1, 2, 3, 2, 1)) v2 <- data.frame(time = c(1, 3, 5, 9, 33), …
Drew
  • 563
  • 2
  • 8
1
vote
2 answers

"Un-melt" Dataframe and keep rest of columns? Python Pandas

I have a table in this format, which I would like to transform with the "opposite" of melting. There is another question that addresses this but it doesn't work with so many other columns that I'd like to keep. The original: COUNTRY STATE …
awks987
  • 45
  • 6
1
vote
2 answers

Melting in pandas loses index

I have the following dataframe: Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Year 2010 9.8 9.8 9.9 9.9 9.6 9.4 9.4 9.5 9.5 9.4 9.8 9.3 2011 9.1 9.0 9.0 9.1 9.0 9.1 9.0 9.0 9.0 8.8 8.6…
user2629628
  • 161
  • 1
  • 3
  • 11
1
vote
1 answer

Using R. I need to Melt or Reshape my Horse Racing dataframe

I am new to the group and R. I posted a question earlier, and am very grateful for the help provided, but realised that I was not very clear. So here is hopefully a better attempt to clarify my problem. Thanks in advance to anyone that can assist. I…
Bookie
  • 81
  • 3
1
vote
1 answer

Melting columns with mutually exclusive values and adding an origin column

I have a dataframe that looks like this (m): a <- rep(c("one","two"),6) b <- c(1,2,3,4,NA,NA,NA,NA,NA,NA,NA,NA) c <- c(NA,NA,NA,NA,5,6,7,8,NA,NA,NA,NA) d <- c(NA,NA,NA,NA,NA,NA,NA,NA,9,10,11,12) (m <- cbind(a,b,c,d)) I would like to reduce it to a…
1
vote
1 answer

How to bind columns based on character string

I am trying to convert my data frame from wide to long form based on a column's character string. In the example below, I want O2_222.coefficients.x1 and O2_217.coefficients.x1 in a single column, O2_222.R-squared and O2_217.R-squared in a single…
user12150823
1
vote
1 answer

Convert columns into rows and rearrange table in R

I currently have a table that looks like this: table <- data.frame("Season" = c("Winter", "Winter", "Winter", "Winter", "Winter", "Winter", "Summer", "Summer", "Summer", "Summer", "Summer", "Summer"), …
Sarah
  • 411
  • 4
  • 14
1
vote
1 answer

How to bind every n columns one under the other as rows (wide to long)?

Here is a dataset that I have without column names: ADNAC TI 0.09 ADNAC TI 0.09 ADNAC TI 0.09 ADNAC TI 0.08 AEFES TI 3.76 AEFES TI 3.48 AEFES TI 3.74 AEFES TI 3.24 AGHOL TI 0.43 AGHOL TI 0.37 …
Emir Dakin
  • 148
  • 5
1
vote
2 answers

Pivoting dataframes with pd.melt() on time series data

I have some data here: Country/Region 1/22/20 1/23/20 1/24/20 1/25/20 1/26/20 1/27/20 0 Afghanistan 0 0 0 0 0 1 Albania 0 0 0 0 0 …
Nathan Thomas
  • 260
  • 1
  • 8
1
vote
2 answers

Pandas: pivoting rows to columns with columns as column-row

I have a data frame that looks like this df = pd.DataFrame({'A': [1,2,3], 'B': [11,12,13]}) df A B 0 1 11 1 2 12 2 3 13 I would like to create the following data frame where the columns are a combination of each column-row …
finstats
  • 1,349
  • 4
  • 19
  • 31
1
vote
3 answers

R Reshape Wide To Long Using Column Stub Strings

data1=data.frame("School"=c(1,1,2,2,3,3,4,4), "Fund"=c(0,1,0,1,0,1,0,1), "Total_A_Grade5"=c(22,20,21,24,24,26,25,22), "Group1_A_Grade5"=c(10,6,6,10,9,9,9,10), …
bvowe
  • 3,004
  • 3
  • 16
  • 33
1
vote
1 answer

python pandas dataframe Melt multiindex multi-levels

I have a DF with the following structure: | Level | Rate | Indicator | AAA | BBB | CCC | XXX | YYY | location variable | One 2017 0.69 0.22 0.71 0.02 0.98 2018 0.31 …
Matteo
  • 165
  • 1
  • 11
1
vote
2 answers

Adding values to a new column based on other two columns

I have a data frame that looks like this. I have created 3 new columns that will take the value from other columns.I want function columns separate column and grab total hours for each user for each function. User Function Total…
Learner
  • 335
  • 3
  • 16