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
2
votes
2 answers

Reshaping data with melt

Hi this is my sample data. The data represents a state's area harvested in acres. State 1974 1978 1982 1987 Alabama 0 0 6 149 Alaska 3 4 39 140 Arizona 700 200 3000 …
jyu1992
  • 25
  • 4
2
votes
1 answer

Melt able to remove NA's for some variables but not others?

I have a question regarding the melt function from the reshape2 package in R. I would like to melt a multi-dimensional array, keeping NA's for some of the variables, but removing NA's for the rest. An example to illustrate what I don't…
JP_smasher
  • 981
  • 12
  • 15
2
votes
2 answers

Count occurrences of a value on melted data using dplyr

I am trying to do a simple table after have melt my data, but using dplyr. My data look like this cluster 21:30 21:45 4 c alone alone 6 b % % 12 e partner partner 14 b partner partner 20 b …
giac
  • 4,261
  • 5
  • 30
  • 59
2
votes
2 answers

Set data type of values in melt function in r

I have a nested named list which looks like the following: > data <- list("1"=list(rating=-1,points=190,name="Fernando"),"2"=list(rating=3,points=532,name="Carlos")) > data $'1' $'1'$rating [1] -1 $'1'$points [1] 190 $'1'$name [1]…
A Gore
  • 1,870
  • 2
  • 15
  • 26
2
votes
1 answer

Tidy data Melt and Cast

In the Wickham's Tidy Data pdf he has an example to go from messy to tidy data. I wonder where the code is? For example, what code is used to go from Table 1: Typical presentation dataset. to Table 3: The same data as in Table 1 but with…
2
votes
3 answers

From long to wide form without id.var?

I have some data in long form that looks like this: dat1 = data.frame( id = rep(LETTERS[1:2], each=4), value = 1:8 ) In table form: id value A 1 A 2 A 3 A 4 B 5 B 6 B 7 B 8 And I want it to be in short form and look…
CoderGuy123
  • 6,219
  • 5
  • 59
  • 89
2
votes
1 answer

plotting simulation coverage of a "known" point in ggplot

I have the results of a simulation that involved removing data and refitting a model, and generated the mean and CIs for 5 beta coefficients (AAA:EEE). The sample data are reproducible through dupt(). data <- structure(list(PercentData =…
B. Davis
  • 3,391
  • 5
  • 42
  • 78
2
votes
1 answer

y and x not the same length, scatterplot R

take the following as a simple example: A <- c(1,1,1,2,2,3,3,4,4,4) B <- c(1,0,0,1,0,1,0,1,0,0) C <- c(6,3,2,4,1,2,6,8,4,3) data <- data.frame(A,B,C) data I want to create a scatterplot that looks like so: without the blue and red boarders, they…
lukeg
  • 1,327
  • 3
  • 10
  • 27
2
votes
4 answers

Melting data with several groups of column names in R

I am working some data with repeated measurements for multiple covariates. The sample data format is like this set.seed(123) df <- data.frame(id = 1001:1003, matrix(rnorm(36),3,12), d=runif(3), e=runif(3), f=runif(3)) colnames(df)…
Lerong
  • 536
  • 5
  • 10
2
votes
1 answer

dcast with custom fun.aggregate

I have data that looks like this: sample start end gene coverage X 1 10 A 5 X 11 20 A 10 Y 1 10 A 5 Y 11 20 A 10 X 1 10 B 5 X 11 20 B 10 Y 1 10 B 5 Y 11 …
2
votes
3 answers

R - Melting two Address columns and casting as new column

I have two columns in a data frame that represent addresses. I need to melt the two and recast as a single column and am having trouble wrapping my head around reshape2. Example: A B 123 address st 122…
Connor M
  • 182
  • 2
  • 12
2
votes
0 answers

R - Aggregate 3-Hourly Block Data into Weekly (Melt)

I am trying to compute max, min, and mean from Global Circulation Models (GCM) for the US. The data is in 3-hour blocks for 2026-2045 and 2081-2100. Sample Data: tmp1 <- structure(list(FIPS = c(1001L, 1003L, 1005L), X2026.01.01.1 = c(285.5533142, …
shouro
  • 31
  • 7
2
votes
3 answers

How can I melt columns while keeping two together?

I have data of this wide format that I want to convert to long format Cond Construct Line Plant Tube_shoot weight_shoot Tube_root weight_root 1 Standard NA NA 2 199.95 - - 2 …
riselin
  • 23
  • 1
  • 4
2
votes
1 answer

simplify multiple one to one paired aggregation

I'd like to calculate mean for multiple one to one paired aggregation. For example, I have a data.frame below. I'd like to calculate the mean for for column b1 by sym & a1, and b2 by sym & a2 simultaneously. sym a1 a2 b1 b2 1 a 1 2 1 1 2 …
YYY
  • 605
  • 3
  • 8
  • 16
2
votes
2 answers

In R, plotting wide form data with ggplot2 or base plot. Is there a way to use ggplot2 without melting wide form data frame?

I have a data frame that looks like this (though thousands of times larger). df<-data.frame(sample(1:100,10,replace=F),sample(1:100,10,replace=F),runif(10,0,1),runif(10,0,1),runif(10,0,1),…
Tedward
  • 1,652
  • 15
  • 19