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

R normalize a dataset

I have a dataset that looks like this > dput(events.seq) structure(list(vid = structure(1L, .Label = "2a38ebc2-dd97-43c8-9726-59c247854df5", class = "factor"), deltas = structure(1L, .Label =…
Nir Regev
  • 135
  • 1
  • 2
  • 7
0
votes
1 answer

R melt subcategories

I'm trying to melt a table (csv) with subcategories but for some reason cannot get the desired result with melt.array I have: Region,Sender,Afghanistan,,,, ,,Adult,,Minor,, ,,Male ,Female,Male,Female, EEA,Austria,165,8,6,10, .... need: Reg Send …
Thomas
  • 1
  • 2
0
votes
2 answers

Reshaping a grouped data frame with large sets of several successive columns of variables

I'm using a data frame similar to this one: set.seed(1) test.df <- data.frame(Treatment= "CI", period = seq(1, 3), subject= 1, X.1. = rnorm(6), X.2. = rnorm(6), …
Homayoon
  • 45
  • 1
  • 7
0
votes
1 answer

Wide to long format in R

Below is a snippet of my dataset: > head(df) Product Region Sector Type Date Value Product A Capital Primary Continued 2012-01-01 395 Product C Capital Primary Continued 2012-01-01 37 Product D Capital Primary Continued…
marcopah
  • 826
  • 2
  • 7
  • 25
0
votes
0 answers

Drawing a line between groups in ggplot2

I have a problem with turning my data into a nice figure. I already turned it into long form, now it looks like this: Group ID variable value 1 AD TAS1R2 -0.000833344 1 FB TAS1R2 -0.073365073 1 KG …
Patrick
  • 1
  • 2
0
votes
0 answers

R Splitting a column by chunks and regrouping

I have a data.frame > blah Col1 Val1 Col2 Val2 1 A 1 B 10 2 A 2 B 20 3 A 3 B 30 structure(list(Col1 = structure(c(1L, 1L, 1L), .Label = "A", class = "factor"), Val1 = structure(1:3, .Label = c("1", "2", "3"),…
Shuo
  • 491
  • 1
  • 6
  • 16
0
votes
1 answer

data rearrangement / similar to pivot table?

I am severly struggling with a data-rearrangement problem. The data below contains agreements (rows) which collapsed or were stable (column "collapse") and feature provisions which were reduced, kept, added or absent (columns…
zoowalk
  • 2,018
  • 20
  • 33
0
votes
4 answers

reshape data and coerce missing to zero

EDIT: The original dataset can be found here: link I have a matrix like: data <- matrix(c("a","1","10", "b","1","20", "c","1","30", "a","2","10", "b","2","20", "a","3","10", …
chopin_is_the_best
  • 1,951
  • 2
  • 23
  • 39
0
votes
1 answer

Add year, month, day variable to data.frame after melt

I've got wide formatted data that I would like to melt and add a new variable for the year, month, and day. The for loop I've written is kind of slow and I'm looking for something a bit faster. dput: df <- structure(list(id = c("USC00030150",…
Vedda
  • 7,066
  • 6
  • 42
  • 77
0
votes
1 answer

R Data Restructuring - Melt2

V1 V2 V3 V4 Control Control Unknown Unknown 0 2 0 2 66 10 90 70 The rows mean: Experiment, Time, Length, respectively How would you restructure the above data to look so it looks like the below…
Nicholas Hayden
  • 473
  • 1
  • 3
  • 24
0
votes
1 answer

transform values in data frame, generate new values as 100 minus current value

I'm currently working on a script which will eventually plot the accumulation of losses from cell divisions. Firstly I generate a matrix of values and then I add the number of times 0 occurs in each column - a 0 represents a loss. However, I am now…
Jordan
  • 131
  • 8
0
votes
1 answer

R comparing by a data frame attribute across observations

I am currently trying to analyze different strategies for a processing method. There are 4 quantities of 2 options (2^4) and 1 quantity of 4 options (4) for a total of 64 different rows of the dataframe. For example, the data frame would be…
Eric
  • 946
  • 2
  • 12
  • 25
0
votes
2 answers

How do you convert a dataset with two headers in the wide format to a long format?

I have a dataset in the wide format which looks like this: header 1 x x x y y z z header 2 1 2 3 1 2 1 2 2015 3.0 4.0 2.0 3.1 2.1 2.3 2.1 2016 2.0 4.4 1.0 2.1 3.1 5.3 0.1 …
Piyush Ahuja
  • 181
  • 3
  • 7
0
votes
1 answer

In R transpose and combine multiple dataframes with missing data and blank column names / rename melted columns prior to dcast

I have searched and found many solutions that came close, but never quite worked in the end. This is probably something very simple, for those with experience... Here is a snippet of my data. This was created automatically from a JSON import by the…
0
votes
0 answers

Melt data.frame containing list to long format (efficiently)

I would like to convert an R data.frame containing a list of uneven length to long format as in the example below. testdf <- data.frame(a=1:3,b=I(list(letters[1:2],letters[2:7],letters[1:3]))) tesdf a b 1 1 a, b 2 2 b, c,…
supersambo
  • 811
  • 1
  • 9
  • 25