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

how to use Melt function to rearrange a given data

I am trying to use the following function here http://www.r-bloggers.com/using-r-two-plots-of-principal-component-analysis/ what I do is as follow: data(iris) df <- iris[,1:4] variable.groups <- c(rep(1,50), rep(2,50),…
user1267127
1
vote
1 answer

Reshape vs. tidyr for repeated measures with multiple dependent variables

I have the following sample data of 10 cases with three repeated measures for two dependent variables "Rapport" and "STRS": structure(list(SubID = structure(1:10, .Label = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14",…
user3594490
  • 1,949
  • 2
  • 20
  • 26
1
vote
1 answer

R: Pivoting using 'spread' function

Continuing from my previous post, I am now having 1 more column of ID values that I need to use to pivot rows into columns. NUM <- c(1,2,3,1,2,3,1,2,3,1) ID <- c("DJ45","DJ45","DJ45","DJ46","DJ46","DJ46","DJ47","DJ47","DJ47","DJ48") …
Sharath
  • 2,225
  • 3
  • 24
  • 37
1
vote
2 answers

Unstacking a data frame

I have a data frame which looks like this: d <- c("a", "b", "c", "a", "b", "c", "a", "b", "c") par <- c("a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9") df1 <- as.data.frame(cbind(id, par)) I would like it to look like this: a <- c("a1", "a4",…
1
vote
1 answer

Easiest way to reshape this dataframe in R?

Say I have the following wide/messy dataframe: df1 <- data.frame(ID = c(1, 2), Gender = c("M","F"), Q1 = c(1, 5), Q2 = c(2, 6), Q3 = c(3, 7), Q4 = c(4, 8)) ID Gender Q1 Q2 Q3 Q4 1 M 1 2 3 4 2 F 5 6 7 8 how can I…
hsl
  • 670
  • 2
  • 10
  • 22
1
vote
2 answers

Complex subsetting data set to data frame

1) I would like to do a subset operation in Gnu R with the data set here to have a resulting data frame only with Brazil, Time and all the Series Name about Income share (like "Income share held by lowest 10%", ""Income share held by lowest 20%" and…
Til Hund
  • 1,543
  • 5
  • 21
  • 37
1
vote
1 answer

Reshaping data with reshape2 in R

I've been trying to figure out how the melt and cast functions works with the reshape2 package. But can't get the results that I'm looking for. Heres the data: data <- read.table(header=T, text=" diagnosis agrp events Period COPD 1 16 …
Heala45
  • 161
  • 11
1
vote
1 answer

Using melt() to convert wide to long data format that requires value lookup

I am having difficulty figuring out how to convert some wide data into long format. I have three columns of string data (A1_R00_FillerNP, A1_R01_ADV, and A1_R02_1stEmbV) which I would like to melt into one column (WordCountRegion) in such a way that…
D T
  • 99
  • 1
  • 12
1
vote
3 answers

How to use melt() in r for my situation?

I have been trying to use melt() function in r to shape my dataframe. Here is the original, group StartX StartY EndX EndY id 18878713 524897 180779 525352 179484 1 18884056 531199 183111 532538 182503 2 I want to shape it to this, …
user3773503
  • 161
  • 2
  • 5
  • 12
1
vote
5 answers

Calculate means of variables in melted dataframe, grouped by name1

I have a problem using melt and mean on a data frame. Maybe it is just a beginner problem. I have a data frame with two conditions and 3 replicates set.seed(1) testdf <-…
drmariod
  • 11,106
  • 16
  • 64
  • 110
1
vote
1 answer

R using Reshape2 to do what reshape (stats package function) was designed for

I'm trying to do exactly what reshape from the stats package is designed for. I have a wide dataset with a series of variables in the form var_name.date. Unfortunately, reshape seems ill-equipped to deal with even medium-sized datasets, so I'm…
user3747260
  • 465
  • 1
  • 5
  • 14
1
vote
1 answer

Separate values in a column of a dataframe and melt

I have a data frame where I want to separate values in the Client.ID column and melt, so each row contains one Client.ID and and the corresponding Account.Name and owner. > head(df) Account.Owner Account.Name Client.ID 1 …
Koba
  • 1,514
  • 4
  • 27
  • 48
1
vote
1 answer

pandas - using the 'melt' function to reshape a table

I have the following table: Site Peril ReturnPeriod Min Max Mean 0 one river 20 0.0 0.1 0.05 1 one river 100 0.0 0.1 0.05 2 one coast 20 2.0 5.3 4.00 3 one coast 100 2.0 5.3 4.00 4…
jramm
  • 6,415
  • 4
  • 34
  • 73
1
vote
3 answers

reshape wide into long while splitting

I am looking for reshaping: ID p2012 p2010 p2008 p2006 c2012 c2010 c2008 c2006 1 1 160 162 163 165 37.3 37.3 37.1 37.1 2 2 163 164 164 163 2.6 2.6 2.6 2.6 into: ID year p c 1 1 2006 165 37.1 2 1 …
nils
  • 23
  • 6
1
vote
2 answers

How to best reshape a data set in R that has a two-row header?

The data set I'm working with is in Excel. It shows sales of products in both unit and revenue terms for the first 26 weeks of availability. Each row of data represents a product. Let's say there are 50 of them. The 2nd header row could…