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

Reshape with concatenation to have a single time series for each variable in R

Would like to reshape a data set with the structure below in a way that would help me create a data set for time series analysis The data set below is an example and I have multiple variables as columns and Multiple Brands as rows along with their…
user36176
  • 339
  • 1
  • 2
  • 11
1
vote
1 answer

R: Boxplot how to formulate data in effective way

The data I'm using is > head(df2) Results Capacity Power LDI LDE LB PDC D E1 E2 E3 E4 E5 E6 E7 E8 E9 1 DCNoV2GYesDC C1 PG11 LDI0 LDE0 LB0.045 PDC0 D10 30 NA 20 3 1 5 NA NA NA 20 2 DCNoV2GYesDC C0.95 PG11 LDI0 LDE2…
ima
  • 155
  • 12
1
vote
2 answers

pandas dataframe melt with string values

I have a dataframe that looks like this brand|1 |2 |3 --------------- a |a1|a2|a3 b |b1|b2|b3 And I want the result dataframe to look like this brand|rank|value ---------------- a |1 |a1 a |2 |a2 a |3 |a3 b |1 |b1 b |2…
Yingying Chen
  • 41
  • 2
  • 7
1
vote
3 answers

How to transform a dataframes row into columns in R?

I have a data frame which I need to transform. I need to change the rows into unique columns based on the value of a column. ex: The Input DataFrame | column_1 | column_2 | ----------------------- | A | B | | A | C | | …
PradhanKamal
  • 540
  • 4
  • 18
1
vote
1 answer

Standard Deviation function in ddplyr not returning a value on melted dataframe

I have a dataset that is composed of 3 position values (XYZ) and 3 rotation values (Omega, Phi, Kappa). head(pos.df) looks like this Batch PhotoID X Y Z Omega Phi Kappa 1 1 DSC_7120 -269.6995…
c0ba1t
  • 241
  • 2
  • 15
1
vote
1 answer

Melt:Reshape2 in R returning values as factors?

I have a stacked list in the following format: > Canal $Canal.Nymph 0d 3d 6d 9d 12d 15d 18d 1 50 30 30 40 30 10 0 2 30 50 30 40 40 20 20 3 40 30 20 30 20 0 10 $Canal.Adult 0d 3d 6d 9d 12d 15d 18d 1 20 30 20 10 0 0 0 2 30 20 30 10 …
Scientist
  • 1,061
  • 2
  • 13
  • 30
1
vote
1 answer

ggplot structuring data boxplot of treatment effects in multiple time periods

I have data currently structured like so: set.seed(100) require(ggplot2) require(reshape2) d<-data.frame("ID" = 1:30, "Treatment1" = sample(0:1,30,replace = T, prob = c(0.5,0.5)), "Score1" = rnorm(30)^2, …
slap-a-da-bias
  • 376
  • 1
  • 6
  • 25
1
vote
5 answers

Single row per id to multiple row per id

I'd like to expand observations from single row-per-id to multiple rows-per-id based on a given time interval: > dput(df) structure(list(id = c(123, 456, 789), gender = c(0, 1, 1), yr.start = c(2005, 2010, 2000), yr.last = c(2007, 2012, 2000)),…
Thomas Speidel
  • 1,369
  • 1
  • 14
  • 26
1
vote
1 answer

Creating varaibles based on calculation outputs in pandas data frame

I have a dataframe that looks like this: df = pd.DataFrame( {'ID':range(1,366), 'No_of_Visits': np.random.randint(1,100, 365), 'Date':pd.date_range(pd.datetime.today(), periods=365).tolist() }) I want to count the number of visits for each three…
owise
  • 1,055
  • 16
  • 28
1
vote
1 answer

Restructuring data.frame to long format converts my numerics to NA's?

Problem I have the following table in R which shows one row per salary: > df employee employment start_date end_date salary 1 Ian 1 28Jul2010 28Jul2011 20000 2 Rose 1 28Jul2011 28Jul2012 30000 3 Rose 2 …
Clair Crossupton
  • 1,332
  • 2
  • 10
  • 16
1
vote
1 answer

Count Number of Rows GroupBy within a GroupBy Between Two Dates in Pandas Dataframe

I have a dataframe df, which can be created with the following code: import random from datetime import timedelta import pandas as pd import datetime #create test range of…
clg4
  • 2,863
  • 6
  • 27
  • 32
1
vote
1 answer

Stacked Bar Plot for Showing What Percent of Hits are Singles, Doubles, Triples, and Homers

I am trying to make a stacked bar plot which shows what percent of each team's hits are singles, doubles, triples, and home runs. However, as you can see from the attached picture, I keep getting a weird result. I think I went wrong on the melt step…
Remy M
  • 599
  • 1
  • 4
  • 17
1
vote
1 answer

melt pandas dataframe and divide two rows based on column

I have a dataFrame of the form: 0 college gender Engineering F 117 M 2240 and I want to change it to: college M:F Engineering 19:1 where M:F represents the ratio of Male to Female. Is there…
laila
  • 1,009
  • 3
  • 15
  • 27
1
vote
2 answers

Create a stacked bar using a frequency table

Actually I'm working with two frequency tables who have got the name: identified_modification_table and unidentified_modifications_table The structure of these files are something like that: identified_modification_table Modifications |…
Enrique
  • 842
  • 1
  • 9
  • 21
1
vote
1 answer

Match Dataframes Excluding Last Non-NA Value and disregarding order

I have two dataframes:…
nak5120
  • 4,089
  • 4
  • 35
  • 94