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

How to Melt Data Frame

I have a data frame, dratiodf: Date D10 D21 D63 D126 D252 2019-09-23 0.1557585 0.3977892 0.8583822 0.7153107 0.7517688 2019-09-24 0.1513844 0.2142586 0.7501128 0.6736790 0.7275896 2019-09-25 0.5314460 0.4254800…
L.Zingg
  • 85
  • 1
  • 10
-2
votes
2 answers

complex data restructuring - wide to long (multiple columns)

I want to do a restructuring as above, and I'm struggling with just using gather() as there are multiple columns to make... does anyone know a way to do this?
llbia
  • 123
  • 2
-2
votes
1 answer

r reshape2 melt returns Warning in if (drop.margins) { : the condition has length > 1 and only the first element will be used

I have a piece of code that returns a warning message: Warning in if (drop.margins) { : the condition has length > 1 and only the first element will be used from deep inside the reshape2 melt function as shown in the error message. How do I…
-2
votes
1 answer

R: How to split a string into values and map the resultant broken pieces as columns to the dataset?

As shown in the above pic, I've a column, genres, with a list of genres the corresponding movie belongs to. There are in total 19 unique genres. I'd like to know if I can manipulate this data into appending 19 columns to the data set each…
bb5kb
  • 51
  • 1
  • 8
-2
votes
1 answer

How to convert a frequency table to a vector of the actual data?

I have a frequency table: # a b # x 1 # y 2 # z 3 and I want to create a vector [x, y, y, z, z, z] based on the counts in b. What's the most efficient way of doing this? Thanks!
pau
  • 51
  • 1
  • 1
  • 5
-2
votes
1 answer

r Using dcast in for loop to find mean of multiple columns and compile them in a new dataframe

I have a dataframe (DF_melted) which I obtained by melting some other dataset. The DF_melted dataframe has columns "month","A","B","C","D","E","F". From the following code using dcast, I am able to get a dataframe which contains value of mean of the…
Sinha
  • 431
  • 1
  • 5
  • 12
-2
votes
1 answer

R Reshaping Data from long to wide by aggregating on a variable

I have row-wise transaction data in the following long format TransactionId ItemCode 101 123 101 521 102 423 103 871 103 982 103 131 I want to reshape this to get all items in one transaction in one row, so the new reshaped table looks…
SuhrudL
  • 21
  • 1
  • 5
-2
votes
1 answer

R Manipulate data frame with multiple information in columns

How can I reshape this dataframe regarding the multiple information of the columns 2:7 (day_rep), obtaining this new "datlong" dataframe with the coumns: "trat" "day" "rep" "value" dat <- read.table(header=T, text=' trat 5_1 5_2 6_1 6_2 7_1…
Juanchi
  • 1,147
  • 2
  • 18
  • 36
-2
votes
1 answer

Matrix function

How can I get a function which takes a matrix and a vector as input and does the following v<-c(1,2,4) [,1] [,2] [1,] 1 4 [2,] 2 5 [3,] 3 6 The outout shall be: [,1] [,2] [1,] 1 4 [2,] 2 5 [3,] 2 5 [4,]…
sdji
  • 1
  • 4
-2
votes
2 answers

How to ensure that when melting data, all possible variables are demonstrated?

Edit 2: Updated with starting data Edit 1: I would like to know how to modify the data or parameters in melt function (might have overlooked or not understood) before melting it to the long form. I started with the following data: …
Michael
  • 3
  • 2
-3
votes
2 answers

How do I reshape my pandas dataframe with melt?

I am trying to remodel my dataframe that looks like this: I would like to reshape my dataframe to look like this:
-3
votes
2 answers

r transform dataset from long to wide

I am dealing with a dataset which is in a long format as shown below. id Name FluidTotal 60718 Rocuronium 11.069175 07860 Rocuronium 5.967500 90389 Rocuronium 200.000000 01536 …
Jill Sellum
  • 319
  • 2
  • 4
  • 14
-4
votes
1 answer

Python using melt how to frame this data

Having data like as follows - I need to group with respect address and Trans into 2 columns - can help using melt or any other function in python? Id name address1 tran1 address2 tran2 address32 tran3 1 Vasu chennai …
-4
votes
1 answer

When I try to convert my data from long to wide but I'm getting "Aggregation function missing: defaulting to length" error

My data is state prod_year num_oil_wells AK 2009 10 AK 2008 8 AK 2007 16 AK 2006 17 AK 2005 15 AK 2004 11 AK 2003 9 AK 2002 14... I want it to be in the following format; state 2009 2008 2007 AK 10 8 …
1 2 3
55
56