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

Melt a matrix for a barplot

I have a tibble with the following format: ID fragment1 value1 fragment2 value2 fragment3 value3 1 50 90 45 10 NA NA 2 50 100 NA NA NA NA I…
point618
  • 1,309
  • 2
  • 10
  • 23
0
votes
3 answers

Transform dataframe to binary dataframe in R

I have a dataframe such as Groups Names G1 SP1 G1 SP2 G1 SP3 G2 SP1 G2 SP4 G3 SP2 G3 SP1 And I would like to transform it as : Names G1 G2 G3 SP1 1 1 1 SP2 1 0 1 SP3 1 0 0 SP4 0 1 0 Where…
chippycentra
  • 3,396
  • 1
  • 6
  • 24
0
votes
1 answer

Calculate the weighted mean for a variable, which has two types with R

I have the following dataset with the number of times ("n") the variable "V0220" appears in the data by the "id_municipio", but this variable has two types: 1 and 2. Moreover, I have the weight ("peso_amostral") of each observation. id_municipio…
Mateus Maciel
  • 151
  • 1
  • 1
  • 10
0
votes
1 answer

Sectioning in Heat Map using ggplot

I'm trying to plot a heat map, but I want the heat map in four different vertical sections. The first one shall be for "Proneural", then "Neural", then "Classical" and lastly "Mesenchymal" A sample of my melted data looks something like…
driver
  • 273
  • 1
  • 13
0
votes
1 answer

HeatMap using ggplot R

I'm trying to plot a heatmap in R using ggplot2. A sample of my data is shown below : tdftan1[1:513,] structure(list(Row.names = structure(c("TCGA.02.0003.01", "TCGA.02.0010.01", "TCGA.02.0011.01", "TCGA.02.0014.01", "TCGA.02.0024.01",…
driver
  • 273
  • 1
  • 13
0
votes
1 answer

data.table melt 3 columns into one

After merging several data.tables, I get one that looks somewhat like this: dt<- data.table(age = rep(c("5-16", "17-39"), each = 3), dur = rep(c("short","medium","long"), 2), short.count = rep(c(23,45),each = 3), medium.count = rep(c(12,34), each =…
matto
  • 77
  • 7
0
votes
1 answer

how to melt tibbles?

I have a dataframe where one of the columns has a tibble inside it as a value. It looks like this click here to see it I tried to eexport this dataframe to csv file but then the tibbles can't be read on excel, then I tried to to export to xlsx file…
Akram H
  • 33
  • 4
0
votes
3 answers

Making lists by group

I have data as follows: library(data.table) dat <- structure(list(year2006 = c("1110", "1110", "1110", "1110", "1120", "1120", "1120", "1120"), group2006 = c("1", "2", "3", "4", "1", "2", "3", "4"), min2006 = c("1.35", "2", "3.7", "4.25", "5.6",…
Tom
  • 2,173
  • 1
  • 17
  • 44
0
votes
1 answer

SQL Melt after Mapping Columns

I have the following working query: SELECT postgres."week" AS "week", CASE WHEN (postgres."spent_money_office") = 1 THEN (postgres."weight") WHEN (postgres."spent_time_office") = 1 THEN (postgres."weight") WHEN…
guy
  • 1,021
  • 2
  • 16
  • 40
0
votes
2 answers

reshaping the dataset in python

I have this dataset: Account lookup FY11USD FY12USD FY11local FY12local Sales CA 1000 5000 800 4800 Sales JP 5000 6500 10 15 Trying to arrive to get the data in this format: (below example has 2 years of data but no. of years can…
0
votes
2 answers

Melt a frequency table in order to use ggplot2

I have a "frequency table" similar to this one # Create a matrix df<- matrix(sample(0:10,35,replace=T),nrow=5, ncol=7) # Rename columns and rows colnames(df) <- c("Monday","Tuesday", "Wednesday", "Thursday", "Friday", …
R18
  • 1,476
  • 1
  • 8
  • 17
0
votes
3 answers

How to reshape dataframe with pandas?

I have a data frame that contains product sales for each day starting from 2018 to 2021 year. Dataframe contains four columns (Date, Place, Product Category and Sales). From the first two columns (Date, Place) I want to use the available data to…
Denmla
  • 135
  • 1
  • 8
0
votes
1 answer

Changing a portion of the table from wide to long

I apologize ahead of time if this has been answered. I just can not find anything for this specific situation. Anyways, I have a table that looks like so: Country code Year_1960 Year_1961 Year_1962 Year_1963 Year_1964
LoveMYMAth
  • 111
  • 5
0
votes
0 answers

How to reshape from wide to long format?

I would like to reshape my data frame from wide to long format. I am using reshape but it's not working. My data: mydata = data.frame(number_p = c(1,2,3,4,1,2,3,4,5,6), SpeciesName = c('speciesA', 'speciesA', 'speciesA', 'speciesA', 'speciesB',…
BMT
  • 65
  • 6
0
votes
2 answers

How do I stack multiple columns of a dataframe so data is long and remove any blanks rows before the output dataframe is generated?

My dataframe is currently created to be wide with many columns, after the for statement below is executed. I want to stack multiple columns of data so that the dataframe is long and remove any blank rows from col4 before the output dataframe is…
hector.h2913
  • 41
  • 2
  • 8