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

Barplots in pairs for each row of a dataframe

i'm fairly new to R so please excuse me for the noob question. I have a dataframe that looks like this: gene ctrl treated gene_1 100 37.5 gene_2 100 20.2 ... ... ... For each row (ie each gene) in the df, I want to plot the…
OliverBit
  • 11
  • 1
0
votes
0 answers

reshape the dataframe with the duplicated values as Ids

can anyone please help me out with the R melt function for reshaping the data. I am trying to convert the df from long to wide, but when I do, I loose most of my data while reshaping. input data dd <- data.frame( Time.point = c(4L, 4L, 2L, 6L, 4L,…
newbe
  • 1
  • 2
0
votes
2 answers

pandas: melt 100+ variables into 100+ new dataframes

Pretty new to stackoverflow, please bear with me if the format looks odd.. I have a big set of data with 100+ columns of data structured like: countrya countryb year variable1 variable2 ...... varaible100 I want to have the 100 variables separated…
js3933
  • 15
  • 2
0
votes
2 answers

Grouped or stacked bar in r using the following data

I want to draw a stacked or grouped bar plot saying against each individual what is valid/real_valid and Invalid. I tried so many things googling but could not conclude that. My real data look like: name valid real_valid…
0
votes
1 answer

Aesthetics must be either length 1 or the same as the data (138): fill

I'm trying to create a geom bar from a subset previously created to compare different behaviours in terrories with and without wolves present. It worked fine on the complete dataset (wolf): dataall <-data.frame(wolf$Behaviour, territory="SAND",…
0
votes
1 answer

Pandas Melt row into a column

I have a data frame which current reads per the below: df_new = pd.DataFrame({'Week':['nan',14, 14, 14, 14, 14], 'Date':['NaT','2020-04-01', '2020-04-02', '2020-04-03', '2020-04-04', '2020-04-05'], …
Jman88
  • 55
  • 7
0
votes
2 answers

Melting dataframe in R

I have the following R dataframe : foo <- data.frame("Department" = c('IT', 'IT', 'Sales'), "Name.boy" = c('John', 'Mark', 'Louis'), "Age.boy" = c(21,23,44), "Name.girl" = c('Jane',…
Louis GRIMALDI
  • 101
  • 1
  • 12
0
votes
2 answers

how to extract column name for melt function? Python

I have a data set that has the following columns. data.columns[1:] Index(['Fraud (i.e. fabricated or falsified results)', 'Pressure to publish for career advancement', 'Insufficient oversight/mentoring by lab principal investigator…
Luke
  • 15
  • 2
  • 7
0
votes
3 answers

Pivot Key-Value Table to Tidy Data Frame in R

I have a dataframe formatted like this: df_before <- tibble( key = rep(c('rank', 'name', 'metric'), 5), value = c( 1, 'name1', 4352, 2, 'name2', 2181, 3, 'name3', 1399, 4, 'name4', 1087, 5, 'name5',…
Frank B.
  • 1,813
  • 5
  • 24
  • 44
0
votes
0 answers

R, get column names, reshaping

I'm trying to reshape wide DB to long. I want to get all column names and make them to the year column. How can I get all column names from 1961 to 2016 nsoil <- melt(soil, id.vars = c("CountryName", "Country.Code"), measure.vars =…
Mozzy_Tron
  • 1
  • 1
  • 1
0
votes
2 answers

Stack/Melt Sets of Columns

I'm trying to take a single table with 10 columns and merge/union/stack into 2 columns. The current layout is like this ID_1 | Name_1 | ID_2 | Name_2 | ID_3 | Name_3 I'm trying to get this into the format with column headers "ID" and "Name" ID |…
0
votes
1 answer

Merging Data into a long data frame

I am consolidating data to put it into a new data base and I am having some issues with replacing the old columns with the new Foreign Key (FK) variables. I am consolidating all my data into a long format and then cast it again to create the new…
Max M
  • 806
  • 14
  • 29
0
votes
1 answer

MS Access version of a Python melt

Assuming a table organized thus: Row | School | LocationCode2011 | LocationCode2012 | LocationCode2013 001 ABC 1000A 1000B 2000X 002 DEF 2000A 2000B 4000X With…
DCUFan7
  • 385
  • 1
  • 3
  • 10
0
votes
1 answer

How to transform a data frame with identical column names

I have a df like: df <- data.frame( name = c("mouse", "rat"), cont = c(27L, 83L), cont = c(43L, 45L), cont = c(18L, 54L), treat = c(49040L, 53522L), treat = c(48570L, 22235L), treat = c(138888L, 345667L)) name cont cont cont treat treat …
Apex
  • 1,055
  • 4
  • 22
0
votes
2 answers

Melt dataset based on two rows using R

I have a dataset with two rows as columns, I would like to melt the dataset in order to have just 6 columns (country , date, var1, var2, var3, var4). Below a sample code to understand. Thanks for the help. # what i have date_or <- c("2001 q1",…
Jordan_b
  • 305
  • 1
  • 8