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
0 answers

Melting data frame to produce scatter plot

I have the following data structure. library(MASS) mu1 <- c(2, -3) mu2 <- c(2, 5) rho <- 0.5 s1 <- 1 s2 <- 3 Sigma <- matrix(c(s1^2, rho * s1 * s2, rho * s1 * s2, s2^2), byrow = TRUE, nrow = 2) n <- 50 X1 <- mvrnorm(n, mu = mu1, Sigma = Sigma) X2…
Andrej
  • 3,719
  • 11
  • 44
  • 73
1
vote
1 answer

Melt grid data in TidyR

I have a very simple data-set that is organized as a grid/raster/table: 1,2,3 4,5,6 7,8,9 I'd like to read it in tidyR (and cognates) into: x,y,value 1,1,1 1,2,2 1,3,3 ..... It seems like a straightforward problem but I can't figure out how to…
CarrKnight
  • 2,768
  • 2
  • 23
  • 25
1
vote
0 answers

melt dataframe with multiple IDs

My data.frame a<-sample(12) b<-sample(-100:100, 12) d<-c(-11:0) O<-rep(c("N","H"), each=6) H<-rep(c("In+", "In-"), each=3, times=2) ID<-rep(c("bo","co", "do", "fo"), each=3) mydata_1<-data.frame(ID, a, b, d, O, H) I want to melt the dataframe…
Al14
  • 1,734
  • 6
  • 32
  • 55
1
vote
1 answer

Subset of a melt dataframe

My dataframe a<-c(2, 4, 6, 6, 8, 10, 12, 13, 14) c<-c(2, 2, 2, 2, 2, 2, 4, 4,4) d<-c(10, 10, 10, 30, 30, 30, 50, 50, 50) ID<-rep(c("no","bo", "fo"), each=3) mydata<-data.frame(ID, a, c, d) gg.df <- melt(mydata, id="ID", variable.name="variable") I…
Al14
  • 1,734
  • 6
  • 32
  • 55
1
vote
0 answers

R, ggplot, Aesthetics must either be length one, or the same length as the dataProblems

I want to visualize data from an acceleration sensor. I have a data frame with four columns: time (PosiXlt), AccX, AccY, AccZ (all as numeric) and around 33 million rows. Here is the head of my file: "time" "AccX.in.G" "AccY.in.G"…
Pedde
  • 11
  • 3
1
vote
1 answer

Combine JSON rows with different number of columns, some unlabled, using either melt or dplyr in R

This is related to a previous question. However, the problem has evolved. I have JSON data that is in three columns: "Left", "Kwic", and "Right". Columns "Left" and "Right" are sometimes further subdivided. This subdivision is denoted in the JSON…
1
vote
1 answer

R - Plot multiple columns as years on x-axis, plot rows as different lines

Here's my data frame: 2010 2011 2012 2013 2014 2015 A 0 100 164 75 154 110 B 71 77 136 58 138 136 C 0 0 132 53 83 0 I'd like to…
rob
  • 13
  • 2
1
vote
1 answer

how to use melt and dcast on tough data frame

I have a data frame that has one value in each cell, but my last column is a list. Example. Here there are 3 columns. X and Y columns have one value in each row. But column Z is actually a list. It can have multiple values in each cell. X Y …
kay
  • 1,851
  • 3
  • 13
  • 14
1
vote
2 answers

How do I melt or reshape binned data in R?

I have binned data reflecting the width of rivers across each continent. Below is a sample dataset. I pretty much just want to get the data into the form I have shown. dat <- read.table(text = "width continent bin …
Jason Matney
  • 552
  • 6
  • 24
1
vote
0 answers

melt and crosstab on a heavy file

I am fairly new to Python and I'm trying to use the crosstab function on a very heavy file (around 19,500,000 rows, 30 columns). Here is the exemple of what I'm trying to do: This is the data I have, minus a few 19.5 millions rows and 30 columns >>>…
Hugo
  • 63
  • 6
1
vote
1 answer

Reshaping data in R using melt

I have tried to apply what people have suggested to reshape data, but somehow I am failing to get my data reshaped like I want it. I would really appreciate it if someone can help: My data looks like this: AB LP PD1 PD2 PY1 …
jss
  • 51
  • 3
1
vote
0 answers

How to collapse (melt) a data frame with pre specified columns

I have the following data frame: df <- structure(list(Setno = structure(c(1L, 1L, 1L), .Label = "set4", class = "factor"), Organ = structure(c(1L, 1L, 1L), .Label = "LN", class = "factor"), Adjn = structure(c(1L, 1L, 1L), .Label = "FOO",…
neversaint
  • 60,904
  • 137
  • 310
  • 477
1
vote
1 answer

R: melting a data.frame to use in ggplot2 for multiple y-value plot

I would like to plot multiple Y-values against a time-variable. I don't have a complete data frame, as I didn't collect all the Y-values to start with. I believe I need to melt() the data frame before passing it to ggplot2, but that seems to fail…
davis
  • 45
  • 1
  • 8
1
vote
2 answers

reshape data with non-unique id and varying time frames

I have a dataset with the following format: name1 year name2 profits2010 profits2009 count AA 2009 AA 10 15 20 AA 2010 AA 10 15 3 BB 2009 BB 4 NA 34 BB 2010 BB 4…
user3570187
  • 1,743
  • 3
  • 17
  • 34
1
vote
1 answer

How to aggregate big data?

I have a big data set of sales data like this: Ordernumber Category Sold_Items 1 123 A 2 2 123 B 1 3 234 C 1 4 345 D 1 5 456 A 2 6 456 …
Siruphuhn
  • 111
  • 1
  • 8