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

Pivot in R Programing- Convert data frame to pivot melt/cast

I am new to R and I have been trying to pivot a data frame I read from a CSV file. The original CSV contain 5,000 item numbers, in my sample I used the first five. My end result using pivot should present each item number as many times as the…
EP_NYC
  • 13
  • 5
1
vote
3 answers

Multiple boxplots with ggplot2 in the same layer from a melted data frame with a condition

I have some data here [in a .txt file] which I read into a data frame, mydf <- read.table("data.txt", header=T,sep="\t") I melt this data frame next using the following piece of code, df_mlt <-melt(mydf, id=names(mydf)[1], variable = "cols") Now I…
Amm
  • 1,749
  • 4
  • 17
  • 27
1
vote
1 answer

R: How to melt data in R where row values become the column labels?

I have this data RES RANK1 RANK2 RANK3 RANK4 RANK5 1 3 3 5 16 1 2 3 1 2 5 16 3 3 5 15 10 1 how do i melt the data such that values of RANK1 to RANK5 becomes the variable and RANK1 to RANK5 becomes…
dixi
  • 680
  • 1
  • 13
  • 27
1
vote
1 answer

Trouble doing large transpose using reshape2::cast function

I have a large dataset (2.8m rows x 4 columns) in R that I'm trying to transpose. I was attempting to use the reshape2::cast function to do the transpose but it's running out of memory. Question 1: is there a better way to do the…
1
vote
1 answer

Compute t.test between several columns conditioned on an other column

I have a df: df: Uttaxeringskassa Delägare.Totalt Delägare.AndelKvinnor Utgifter.SjukhjälpPerMedlem 6877 0 207 31.400966 10.6908213 3590 1 402 …
user1665355
  • 3,324
  • 8
  • 44
  • 84
1
vote
1 answer

Reshaping block in data.frame to lists is columns uneven length

I would need your help with R to cast this data: STATUS SCORE JOB.ID 1 STATUS1 99 JOB1 2 STATUS1 99 JOB2 3 STATUS1 99 JOB3 4 STATUS1 99 JOB4 5 STATUS2 36 JOB5 6 STATUS2 36 JOB6 7 …
1
vote
1 answer

How to organize and plot multiple series of data out of one data frame using ggplot2?

I have a data frame (df1) in the form: x1 y1 x2 y2 1 0.745779796 0.5728328 2.04029482 -0.71989471 2 0.008949224 0.8318262 1.01426596 1.20956795 3 2.390108913 0.8041999 1.63621459 0.19979352 4 1.478310218…
AndMan21
  • 533
  • 1
  • 4
  • 15
1
vote
1 answer

barplots in ggplot from `mids` object

Despite using ggplot a few times already, I am really struggling to make any headway with this problem. I guess it will be easiest to explain what I want to do without my abominable attempt at using ggplot, The following is quite ugly too, but it's…
Joe King
  • 2,955
  • 7
  • 29
  • 43
1
vote
3 answers

Using reshape package to combine columns

I have data in a dataframe in the following format: id a b c d e f x y z 1 0 0 0 1 1 0 1 0 1 2 1 0 0 1 0 0 1 0 0 What I would like to do is find out how many times a and x have a 1 in the same place, a and y have a 1 in the same row and so on.…
0
votes
0 answers

melt column with differing numbers of elements

I have a dataframe with two columns. The first column contains unique names for clusters of samples (from a network) - one row per unique cluster name. The second column contains the sample names that are members of each cluster, separated by a…
ptenax
  • 141
  • 1
  • 14
0
votes
0 answers

Reshape multiple columns R. Columns inverted

Following this question I got a very strange behaviour with base reshape: Reshaping wide to long with multiple values columns Here, it works: df <- data.frame(id=c("a", "b", "c", "d"), blabla=c("aaa", "bbb", "ccc", "ddd"), …
user3631369
  • 329
  • 1
  • 12
0
votes
0 answers

Reshaping into long format: different values in one of my variable

I was working on R with the following command to bring my data into long format: NewData <- melt(data, id.vars = c("numberofSubject", "ID", "group", "gender", "age", "mmse"), measured.vars = c("CSvol_left", "CSvol_right ", "CSvol_total",…
stella
  • 1
0
votes
2 answers

How to melt data in a data frame with a two-row header in R?

data <- data.frame(Q1_1 = c("abc",1,2,3,4), Q1_2 = c("def",2,3,6,2), Q2_1 = c("ghi",4,5,3,1), Q2_2 = c("jkl",6,3,8,4), ID = c("ID", "AA", "BB", "CC", "DD"), …
Siyu Lin
  • 25
  • 3
0
votes
0 answers

"Weight not found" error comes up when trying to create a social network plot

I am trying to create a social network for the geese I am studying. I have already been given working code by my superiors on the project however, as someone who is not very good at R and has no previous experience conducting a social network…
0
votes
1 answer

How to debug data.table negative length vectors are not allowed error

I am trying to use melt on a data.table, mdoern_gt_melted <- data.table::melt(modern_gt, id.vars = c('chrom', 'pos', 'ref', 'alt')) Error in melt.data.table(gtData, c("chrom", "pos", "ref", "alt")) : negative length vectors are not allowed my…
zhang
  • 185
  • 7