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
1 answer

R Wide to long format for multiple variables with patterns

I have a data set with a single identifier and five columns that repeat 18 times. I want to restructure the data into long format keeping the first five column headings as the column headings. Below is a sample with just two…
user3594490
  • 1,949
  • 2
  • 20
  • 26
0
votes
1 answer

Match in R while disregarding order

I am trying to do a match in R regardless of the order of the columns. Basically the problem I am trying to solve is that if all of the values in the columns of df2, from column 2-to the end, are found in df1 (after Partner), then match df1. Here's…
nak5120
  • 4,089
  • 4
  • 35
  • 94
0
votes
2 answers

manipulating a data frame so that each person has all their relevant values in one row

I am trying to figure out the best way to consolidate my data frame and I seem to be hitting roadblock. How can I combine these two rows so that Michael's trial and purchase date sit on the same row? **user** | **trial_date** |…
msidd2016
  • 1
  • 1
0
votes
2 answers

Pandas Dataframe: melt alternating groups of columns for wide to long conversion

I was hoping someone could help me convert my current dataframe from a wide to long format. I am using Pandas 0.18.0 and I can't seem to find any other solution on stackoverflow that fits my need. Any help would be greatly appreciated! I have 50…
Jeremy L
  • 1
  • 1
0
votes
1 answer

How to prepare data for ggplot2 and stack bar chart with negative values?

Given the following dataset: Output<- read.table(text = "Type 2012-06-30' 2012-09-30 1 Market 2 3 2 Geography 3 -2 3 Industry -1 5 ",header = TRUE,sep = "",row.names = 1) I'm trying to prepare the data in order to use the…
lapioche75
  • 87
  • 1
  • 2
  • 9
0
votes
1 answer

How do you use the melt function in R while keeping 2 columns together?

My name is in the format: V1 V2 V3 V4 V5 V6 V7 NICK PIPE 10 IN PAINT GREEN SCREW 0.5 IN MIKE PAINT RED TOOL HAMMER PIPE 3 IN I want to use the melt function so that the data would appear…
Cimm
  • 17
  • 1
0
votes
1 answer

Problems setting colnames in R (creates numbers random numbers)

Data can be found here : http://www.scb.se/hitta-statistik/statistik-efter-amne/befolkning/befolkningens-sammansattning/befolkningsstatistik/pong/tabell-och-diagram/helarsstatistik--kommun-lan-och-riket2/folkmangd-i-lan-17492015/ library(readxl) scb…
MLEN
  • 2,162
  • 2
  • 20
  • 36
0
votes
1 answer

Importing data files of different lengths into R and melting them

I have 35 files named PXX physiology.txt where XX is 1 to 35. E.g. head(P1) Time SkinTemp HeartRate RespirationRate 1 0 27.412 70 10 2 0 25.608 70 10 3 4 25.609 70 10 4 …
HCAI
  • 2,213
  • 8
  • 33
  • 65
0
votes
0 answers

Converting a data.table with missing or NA-values into a matrix with R

I'm trying to convert a data.table to a matrix in R. The data.table looks like this id timeBin vel 1 NA value 1 10 value 1 20 value 1 30 value 2 20 value 2 30 value 2 …
0
votes
1 answer

Melt is creating Cronenburg monsters out of my data

I have a dataframe: structure(list(diag = structure(list(svm.ca = 0.894598155467721, rpart.ca = 1), .Names = c("svm.ca", "rpart.ca")), kappa = structure(list( svm.ca = 0.838953088986906, rpart.ca = 1), .Names = c("svm.ca", "rpart.ca")), rand…
Travis Heeter
  • 13,002
  • 13
  • 87
  • 129
0
votes
1 answer

R wide to long format with three variables

I have a data frame and want to change it from wide to long format but I have three variables, whereas ref = RR_ref, het = RR_het and hom = RR_hom. df: Number ref het RR_het hom RR_hom RR_ref mary GG AG 0.29 AA 0.0841 1 wayne AA AG …
Peter Chung
  • 1,010
  • 1
  • 13
  • 31
0
votes
1 answer

Casting from Long to Wide format, with each repeat creating a new row

I have a data frame in long format, that I'd like to transform into wide format. The data frame has several repeated identifiers that I'd like to treat as unique instances, and represent them as individual rows in the wide data frame. My question is…
Vinterwoo
  • 3,843
  • 6
  • 36
  • 55
0
votes
3 answers

reshape dataframe from columns to rows and collapse cell values

Here's the challenge i am facing. I am trying to transform this dataset a b c 100 0 111 0 137 17 78 117 91 into (column to rows) col1 col2 a 100,78 b 137,117 c 111,17,91 I know I can do this using…
Jill Sellum
  • 319
  • 2
  • 4
  • 14
0
votes
0 answers

ddply error "unique() applies only to vectors" with data frame

I'm trying to use ddply in a data frame (created using melt) as the following: head(MoP_top50_ftrt_htmp_melt) Taxon variable value 1 K03406;…
André Soares
  • 309
  • 1
  • 13
0
votes
1 answer

Convert ts in data frame

I have this ts: Point Forecast Lo 80 Hi 80 Lo 95 Hi 95 2015.173 1.657143 0.06698996 3.247296 -0.7747861 4.089072 2015.192 1.657143 0.06698996 3.247296 -0.7747861 4.089072 2015.212 1.657143 0.06698996…