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

create multiple variable/value columns with melt - R

> df <- data.frame(g=c(1,2,3,1,2,3), foo_x=c(12,32,14,23,12,34), foo_y=c(32,35,12,12,32,34), bar_x=c(100,233,122,433,122,442), bar_y=c(744,546,236,137,652,235)) I'm trying to create this data frame: g foo bar val_foo val_bar 1 x x 12 …
HappyPy
  • 9,839
  • 13
  • 46
  • 68
1
vote
1 answer

Is it possible to combine columns and rows of a matrix to become one column in R?

I have a matrix formatted like this: EeBi3 EeBi4 EeBi18 EeBi19 EeBi20 EeBi23 EeBi27 EeBi34 KbFk2 KbFk4 KbFk6 PeHa8 PeHa10 EeBi3 0.0000000 0.30663054 0.30939201 0.31964525 0.0159719…
1
vote
3 answers

Arranging and mapping dataframe in R using melt function for line plot

I have dataframe, there are 4 timepoints (rows) and 18 genes (columns), and in one of the row's there is an ID associated with each gene which would be helpful during plotting a line plot in ggplot2. I import the data, then use the melt() function…
1
vote
2 answers

Reformat dataframe in R

I have multiple cols and would like to reformat dataframe to have less cols. Here is my cucrent df: # Dataframe df <- data.frame( ~Location, ~Product_Name, ~Category, ~Machine1, ~Machine2 ~Machine1_adds, ~Machine2_adds, ~Sales1, ~Saless2,…
Dinho
  • 704
  • 4
  • 15
1
vote
2 answers

pandas wide_long vs (stack and melt) for data-frame transformation

I have a data-frame like as shown below df =…
The Great
  • 7,215
  • 7
  • 40
  • 128
1
vote
1 answer

R how to reshape data as a column variable to become rownames and extract specific other variable data?

I have some trouble to convert my melted data from long to wide and also filter at the same time. I can proceed to subset before but I would like to do them at the same time and save them as different…
mel099
  • 23
  • 4
1
vote
1 answer

python pandas - transforming table

I would like to transform a table which looks similiar to this below: X|Y|Z| 1|2|3| 3|5|2| 4|2|1| The result, I want to achive, should look like that: col|1|2|3|4|5| X |1|0|1|0|0| Y |0|2|0|0|1| Z |1|1|1|0|0| So, after…
guddy_7
  • 13
  • 2
1
vote
1 answer

stacking/melting multiple columns into multiple columns in R

I am trying to melt/stack/gather multiple specific columns of a dataframe into 2 columns, retaining all the others. I have tried many, many answers on stackoverflow without success (some below). I basically have a situation similar to this post…
KNN
  • 459
  • 4
  • 19
1
vote
1 answer

How to reshape this data.frame having two variables as identifiers?

Suppose I have a data.frame as follows: data = data.frame(firm = LETTERS[seq( from = 1, to = 9)], industry = seq(1,9), country = c("USA", "CAN", "DEU"), var1_10 = rnorm(9), …
Cristhian
  • 361
  • 3
  • 12
1
vote
1 answer

How to plot multiple variables on the same plot in ggplot in geom_line after melting?

I have a tibble where the column names of original df were given by values in variable col that i melted into long format using id.vars=Country to get this using melt. This is to plot the different values of AGR_LogLabProd, MIN_LogLabProd,…
Shipra
  • 47
  • 6
1
vote
1 answer

Turn specific indexes into their own rows

Trying to convert the indices of one column, into their own columns. From: [country, series, year, value] [USA, A, 1994, 700000] [USA, B, 1994, 701231] [UK, A, 1994, 600000] [UK, B, 1994, 601231] [China, A, 1994, 6512312] [China, B, 1994,…
Alex
  • 188
  • 11
1
vote
1 answer

Issues reshaping data.frame from wide to long format

I'm trying to reshape the below data frame into a long format, but I'm not having much luck writing the code using reshape() or melt(). pH SO4 Lake Lat Long 1976 1977 1978 1981 1976 1977 1 …
Sarah
  • 13
  • 3
1
vote
2 answers

How to melt your data

For most of you this is an easy question so apologise for asking this. I would like to melt my data. My data structure structure(list(PersonalCare = c(2, 2, 2, 2, 2, 2), Sleep = c(28, 60, 54, 58, 80, 78)), row.names = c("04:00", "04:10", "04:20",…
1
vote
1 answer

Unexpected results when passing the name of a dataframe using a list

There are total 17 dataframe and I have them stored in a list: req_dfs "data_Apr-18" "data_Apr-19" "data_Aug-18" "data_Aug-19" "data_Dec-18" "data_Feb-19" "data_Jan-19" "data_Jul-18" "data_Jul-19" "data_Jun-18" "data_Jun-19" "data_Mar-19"…
Toros91
  • 303
  • 2
  • 11
1
vote
1 answer

R melting/gathering file with 2 heading rows into attributes

I need to read in a datafile with 2 levels of headers, the data looks like this: | | Jone Doe | | | | | | | Jane Doe | | | | | | |…
zaza
  • 892
  • 1
  • 18
  • 37