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

How to gather/ reshape incomplete dataframe across multiple columns

I have a large dataframe with 3 blocks of incomplete data. I want to convert this dataframe from a wide to long format using R. Example df <- structure(list(V1 = 1234:1240, V2 = structure(1:7, .Label = c("text1","text2", "text3", "text4", "text5",…
AudileF
  • 436
  • 2
  • 10
0
votes
1 answer

Replace values in multiple columns, on condition from another variable, with R data.table

A bigish data.table with 750k rows and almost 200 columns, but this will do: dt <- data.table(id = 1:15, outcome = factor(c(0, 0, 0, 1, 1, 3, 3, 3, 3, 3, 0, 3, 1, 1, 3), labels = c("F0","F1","F3")), …
504aldo
  • 57
  • 6
0
votes
1 answer

How to unpivot pandas dataframe to create datetime column

I have a pivoted pandas dataframe that looks like the one below. I need to unpivot it into a dataframe indexed by datetime, and the variables (columns) reduced to only one of each. I tried using melt but I am struggling to reshape it because of the…
Cleyson Shingu
  • 203
  • 1
  • 3
  • 9
0
votes
1 answer

wide to long multiple columns issue

I have something like this: id role1 Approved by Role1 role2 Approved by Role2 1 Amy 1/1/2019 David 4/4/2019 2 Bob 2/2/2019 Sara 5/5/2019 3 Adam 3/3/2019…
Ellie
  • 415
  • 7
  • 16
0
votes
1 answer

Plotting contour plots from melted dataframes

I have a dataset which is a function of time and frequency. When I melt it I want to retain actual time (date) and frequency values as I want a 2d plot with y axis as frequency and x axis as time. I tried to retain a column of desired axis values…
0
votes
2 answers

reshape only 2 columns keeping multiple columns same

My sample data looks like: time state district count category 2018-01-01 Telangana Nalgonda 17 Water 2018-01-01 Telangana Nalgonda 8 Irrigation 2018-01-01 Telangana Nalgonda …
riyan
  • 75
  • 1
  • 10
0
votes
3 answers

How to reduce aligned sequences to start and end coordinates?

I have a data table of labelled coordinates that are aligned between two groups (A and B). For example: dt_long <- data.table(LABEL_A = c(rep("A", 20), rep("A", 15), rep ("A", 10), rep ("A", 15), rep ("A", 10)), SEQ_A = c(11:30,…
Powege
  • 685
  • 5
  • 12
0
votes
1 answer

Reshape a multi-index dataframe

arrays = [['indcator_1', 'indcator_1', 'indcator_2', 'indcator_2', 'indcator_3', 'indcator_3', 'indcator_4', 'indcator_4'], ['2018', '2019', '2018', '2019', '2018', '2019', '2018', '2019']] tuples = list(zip(*arrays)) index =…
dhaval
  • 23
  • 4
0
votes
0 answers

Transform table

I have one data set with 61 variables.Last column have name Weight.So my intention is to replicate each row by the value of last column. For example if value is two, code need to copy this row by two times, if value is three then should copy three…
silent_hunter
  • 2,224
  • 1
  • 12
  • 30
0
votes
0 answers

dcast(melt..) message "Aggregation function missing: defaulting to length"

My data looks as follows: RNR RoundNR X Y Z Etc. 1 1 13 19 0.0 1 2 23 23 0.0 2 1 34 17 0.3 2 2 33 20 0.4 I wish to format this so that for every…
R. Iersel
  • 89
  • 9
0
votes
0 answers

Reshape data using melt and cast (reshape / reshape2 in R)

I have the following data. data <- matrix(c(13.54576,"B","B","B","A","B","A","A", 12.48550, "B","A","B","NA","B","B","B", 12.57386, "B","A","B","B","B","NA","A", 12.11360, "B","A","A","B","B","A","B", 13.51943, "B","A","B","B","B","A","NA",…
Sylvia Rodriguez
  • 1,203
  • 2
  • 11
  • 30
0
votes
0 answers

Plot several distribution and color it with a gradient

I would like to make a distribution plot like in this publication : https://www.nature.com/articles/s41598-018-35738-0.pdf for this I have a table consisting of 24 col each col representing a chromosome and each row a sample And I have a 25th col…
D Prat
  • 352
  • 4
  • 16
0
votes
1 answer

Python: Add aggregated columns to DataFrame based on the Key and additional conditions

I have 2 dataframes in the following view: dogs dataframe is: DogID PuppyName1 PuppyName2 PuppyName3 PuppyName4 DogWeight Dog1 Nick NaN NaN NaN 12.7 Dog2 Jack Fox Rex NaN …
Cindy
  • 568
  • 7
  • 20
0
votes
2 answers

How to melt and plot multiple datasets over different ranges on the same set of axis?

This is my first time posting here, I hope my question is clear and appropriate. I have a set of data the head of which looks like this: wl ex421 wl ex309 wl ex284 wl ex347 1 431 0.6168224 321 0.1267943 301 0.06392694 361…
bvok
  • 13
  • 2
0
votes
1 answer

How to create a heatmap matrix in R with preserving the structure of the matrix?

I want to create a correlation heatmap matrix. I followed this tutorial. Here is the code: mydata <- mtcars[, c(1,3,4,5,6,7)] cormat <- round(cor(mydata),2) # Get upper triangle of the correlation matrix get_lower_tri <- function(cormat){ …
Patris
  • 167
  • 2
  • 11