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

How to do Multi Index Pivot when index and values are in the same column?

I have this frame: regions = pd.read_html('http://www.mapsofworld.com/usa/usa-maps/united-states-regional-maps.html') messy_regions = regions[8] Which yields something like this: |0 | 1 --- |---| --- 0| Region 1 (The Northeast)| nan 1|…
Nick
  • 101
  • 7
1
vote
2 answers

Stacking columns without melting by id

I imported a json file using rjson and converted it to a data.frame but all of the data is spread widthwise and the column names contain the key information. stations <- fromJSON(file = "station_information.json") test <-…
iskandarblue
  • 7,208
  • 15
  • 60
  • 130
1
vote
2 answers

Reshaping multiple groups of columns in a data frame from wide to long

I am working with air-quality data. I tried to reshape the data frame from wide to long using melt function. Here is the data: Elev stands for Elevation, Obs for observation and US3, DK1, DE1 are models, where lm and ul represents first and third…
G1124E
  • 407
  • 1
  • 10
  • 20
1
vote
1 answer

R: Melt and Dcast

I have a dataset like this: CASE_ID = c("C1","C1", "C2","C2", "C2", "C3", "C4") PERSON_ID = c(1,0,7,8,1,20,7) PERSON_DIVISION = c("Zone 1", "NA", "Zone 1", "Zone 3", "Zone 1", "Zone 5", "Zone 1") df <- data.frame(CASE_ID, PERSON_ID,…
Natalia P
  • 97
  • 1
  • 7
1
vote
2 answers

R: plot multiple curves vs one var but for 4 factors

I have a DF that looks like: id app vac dac 1: 1 1000802 579 455 2: 1 1000803 1284 918 3: 1 1000807 68 66 4: 1 1000809 1470 903 5: 2 1000802 407 188 6: 2 1000803 365 364 7: 2 1000807 938 116 8: 2 1000809 699 570 I need to…
Alexey Ferapontov
  • 5,029
  • 4
  • 22
  • 39
1
vote
0 answers

Pandas Pivot Table - Add New line with Melt Function

I hope somebody can tell me how to conclude the following step : I have the following dataframe: df = [{'Failed by Fraud' : 3, 'Failed by Bot': 7, 'Failed by Geography':4, 'Failed by Suspicious Activity' : 2, 'Impressions': 22, 'Clicks':12, 'Date':…
Matteo M
  • 137
  • 2
  • 8
1
vote
1 answer

Melt a array and make numeric values character

I have a array and I want to melt it based on the dimnames. The problem is that the dimension names are large numeric values and therefore making them character would convert them to a wrong ID see the example: test <- array(1:18, dim = c(3,3,2),…
Tobias Dekker
  • 980
  • 8
  • 19
1
vote
1 answer

Extract rows as column from pandas data frame after melt

I'm working with pandas and I have this table: ID 1-May-2016 1-Jun-2016 20-Jul-2016 Class 1 0.2 0.52 0.1 H 2 0.525 0.20 0.01 L ... and I'd like to obtain this table: ID Date Value Class 1 …
Titus Pullo
  • 3,751
  • 15
  • 45
  • 65
1
vote
3 answers

How to "melt" row wise instead of column wise in R?

I have a data frame A that I would like to melt row wise instead of column wise to look like B (which also excludes observations with NA in them). Can this be accomplished with the "melt" function? A <- read.table(text=" Id1 Id2 Var1 Var2 …
RTrain3k
  • 845
  • 1
  • 13
  • 27
1
vote
1 answer

pandas reshape date sequence

I have table with factor and time interval. What I want to do is to get long table with each date in interval between START_DATE and END_DATE. dt_in = pd.DataFrame({'factor':['A','B'], …
BiXiC
  • 933
  • 3
  • 9
  • 29
1
vote
1 answer

Extract only significant rows from TukeyHSD output

After generating a very large TukeyHSD table, I want to only see the rows that are <0.05 in the adj.p.value column. I have tried the IF and ifelse functions, but they only produce a TRUE/FALSE table. I want to see the whole data row for the…
J.Con
  • 4,101
  • 4
  • 36
  • 64
1
vote
1 answer

One-way ANOVA for each sub-group in a melted data frame

I have a very large data set that requires individual one-way ANOVAs for multiple species on 4 different treatments with several measurements. Usually I just make separate excel spread sheets for each species and run ANOVAs on each, looping through…
J.Con
  • 4,101
  • 4
  • 36
  • 64
1
vote
1 answer

Publication-ready summary table from SummarySE function, R

I am trying to create a summary table of the mean ± standard error. So far I have managed to extract the mean and se columns from the SummarySE function, however I am now stuck and can't figure out how to get the column and row…
J.Con
  • 4,101
  • 4
  • 36
  • 64
1
vote
1 answer

Plotting multiple columns of df using ggplot

This question is similar to r - data frame of lists into a data frame but no answer was really sufficient. I have a df of time series data, comparing modeled to gage data. See below for a sub-section of the data: Date GageFlow base0 1a…
LauraR
  • 181
  • 1
  • 2
  • 12
1
vote
2 answers

R - Can't reverse melt

Simple question that I couldn't solve myself (or find a solution): df <- data.frame(A1 = sample(1:100, 10, replace = TRUE), A2 = sample(1:100, 10, replace = TRUE)) molten <- melt(df) How can I reverse this and get the original df back? Neither…
Geo Vogler
  • 63
  • 1
  • 8