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

melt multiple id.vars as all columns excluded from a list

df1<-data.frame(id=c("a","b","c","d"), var1=c(2,4,4,5), var2=c(5,6,2,6), var3=c(5,3,2,1)) msr<-c("var1", "var2","var3") melt(df1, id.vars = -c(msr), #problem here measure.vars = c(msr)) I have a…
1
vote
0 answers

Convert a data frame or events into frequency

testData <- data.frame("player" = c(1,2,1,2,2,3,3,2,3,1), "event" = c(rep("shot",3),rep("pass",5),rep("score",2))) testData # player event #1 1 shot #2 2 shot #3 1 shot #4 2 pass #5 2 pass #6…
1
vote
2 answers

Getting mean value of set of variables after grouping by date using R

Here is my dataset: https://app.box.com/s/x5eux7mhdc0geyck4o47ttmpynah0wqk Snapshot: I'd like a create a data frame in which the average value of the sentiments would be present in a group of 2 months. I tried the following…
user709413
  • 505
  • 2
  • 7
  • 21
1
vote
1 answer

Pair each item with the last non-null value in a row

I'm trying to make a function where I feed it a list of URLs which go through a 301 hop and it flattens it for me. I want to save the resulting list as a CSV so I can hand it to the developers who can implement it and get rid of 301 hops. For…
jceg316
  • 469
  • 1
  • 9
  • 17
1
vote
1 answer

facet_grid with multiple line colours

I have the following data frame resulting from simulations of ODEs with different parameter sets, e.g. df <- data.frame(t = rep(seq(0,4), 4), x1 = c(1.2*seq(1,5), 1.3*seq(1,5), 1.4*seq(1,5), 1.5*seq(1,5)), x2 =…
Pascal
  • 563
  • 1
  • 3
  • 15
1
vote
2 answers

How to un-pivot a dataframe with pandas

For example, I have a dataframe like this df = {'name':['Jennifer','Vivian','Trisha'], 'married':[1,1,0], 'Mon': [0, 0,1], 'Tu':[1,0,0], 'Wed':[0,1,0]} How can I melt the dummy variables into one column like this: I tried to…
1
vote
1 answer

R: Detect and discard variable with always the same value in long format data frame

Say I have a data frame like the following, where one of the columns has always the same value: > set.seed(1) > mydf <- data.frame(name=LETTERS[1:10], treatment1=rnorm(10, 2, 1), treatment2=1.35, treatment3=rnorm(10, 5, 2)) > mydf name treatment1…
DaniCee
  • 2,397
  • 6
  • 36
  • 59
1
vote
2 answers

Dcast aggregate from melted data to long format

I did this successfully with one subset of a data frame but I can't seem to get it to work with my other subset. There is info for about 4000 orders with a range of 0 - 8 months and sentiment of 0-5. The goal is to melt the data with id's of 'order'…
ILikeWhiskey
  • 551
  • 5
  • 12
1
vote
2 answers

Managing duplicate entries in one column while keeping other columns intact in r

I have count data of species at multiple sites with information of site, year, month and day. Within this data, for several species there are multiple entries on certain days. For example, on 3rd of January, 2016, for species A1 there are two…
Gull
  • 107
  • 8
1
vote
0 answers

Transposing the data frame with particular column as id

df45 = data.frame( Tag = c(1,1,1,1,1,2,2,2,2,2), clus = c("L1","L2","L3","L4","L5","L1","L2","L3","L4","L5"), long = runif(1:10,1,2), medium = runif(1:10,1,2), short = runif(1:10,1,2), urgent =…
Nabi Shaikh
  • 787
  • 1
  • 6
  • 26
1
vote
1 answer

Expanding data by month

I have the following dataframe with 2 columns: address, startdate, latitude and longitude. It is a listing of the month a given address was cleaned. df = data.frame(address = c("1 ex St", "2 ex St"), year = (c(2011,2011)), …
Ajjit Narayanan
  • 632
  • 2
  • 8
  • 18
1
vote
1 answer

Transform columns to row without create "variable" and "value"

I´ve seen a lot of example of transformations similars but not the same yet. Hope not to be wrong. I wopuld like to transform this DF: Reference Amount Reference.2 Amount.2 1: 20171201 100,00 € 20171204 110,00 € To…
1
vote
1 answer

Pandas Dataframe - How to stack two column values into one list?

I have a dataframe with three columns (from, to, w): from to w 0 0 1 0.670820 1 0 5 0.612372 2 0 2 0.612372 3 0 3 0.577350 4 0 4 0.408248 How can I get the values in a list from the two columns (from, to)…
kitchenprinzessin
  • 1,023
  • 3
  • 14
  • 30
1
vote
1 answer

Convert some columns into rows based on column value in R

I know the subject is widely covers but I didn't find the code working for my case... I have a dataframe of this type: V1 V2 V3 1: label1 alias_fr alias_fr 2: label1 triplet …
Tau
  • 173
  • 1
  • 8
1
vote
0 answers

file input from http (url) in melt plugin

I'm using MELT plugin for generating crossfade animation using series of images. I found the corssfade animation script from here. and the script is melt -verbose \ -profile atsc_720p_25 \ 001.png out=50 \ 002.png out=75 -mix 25 -mixer luma…
Anuj TBE
  • 9,198
  • 27
  • 136
  • 285