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

Loop through variables to melt in R

My current data set has a lot of variables, each looking like year place1 place2 1999 1.1 7.8 ... And I want each variable to be melted by year. I wonder why the following code is not working. # define function my.melt <-…
Shane
  • 11
  • 2
0
votes
1 answer

Data frame reshaping in R based on number of unique values

I'm working with job application data where each prior job held is a row in an excel file. I want to transform the data set such that there are columns for each past employer 1,2,3,4 etc... I think the problem is best explained with an example. How…
andrea
  • 117
  • 10
0
votes
2 answers

How to melt or reshape a data frame by retaining a desired column

I have the following data frame: df <- structure(c("0.1620678925564", "-0.0609851972808482", "-0.101082695275552", "0.184268723991321", "-0.0899021067853178", "-0.0943666172060028", "-0.0531973808347148", "0.0213528550009522",…
neversaint
  • 60,904
  • 137
  • 310
  • 477
0
votes
1 answer

Reshaping, melting & casting on large dataframes in R

I've got a bunch of dataframes that I want to make a few changes to using packages tidyr, reshape/reshape2. Y C S A B_B_m B_B_p C_m C_p D_m D_p 2000 "AUSTRIA" "total" "no" 33 44 55 66 77 99 2001 "AUSTRIA"…
Oscar
  • 41
  • 2
  • 9
0
votes
0 answers

could not find function "melt" even though "reshape" is installed and loaded

I'm running a simple script using the melt function, but I get an Error: could not find function "melt" I have used the function before and it worked fine. The reshape package is installed and loaded. I removed it and reinstalled it, but still it…
NRuecker
  • 3
  • 1
  • 3
0
votes
2 answers

Melting & reshaping in R

I have a case where the variable names in my dataframes contain information about more than one variable. For example, "cs_ta_p50". I used melt to melt the data. So now I have |variable value | |cs_ta_p50 ... | To fix this I need to create a…
Oscar
  • 41
  • 2
  • 9
0
votes
1 answer

How to more efficiently reshape my dataframe into a new form (R)?

I have a dataset like this (df1) ID 2 4 6 8 10 12 14 16 18 20 22 24 Day 1 0 0 0 0 2 0 0 0 1 0 1 0 Sunday 1 0 0 0 0 0 4 0 0 0 0 0 0 Monday 1 0 0 0 0 0 0 0 0 2 …
Meixu Chen
  • 61
  • 4
0
votes
0 answers

Why do 'X' and 'Y' lengths differ when plotting distance?

I am trying to plot my biological data values against their unifrac distances in R. However, I got an error that the classes of data were different, and thats why I subsequently had errors with my plot, so I converted both to matrices, but am still…
user4476006
  • 21
  • 1
  • 6
0
votes
1 answer

How to plot data.frame with multiple columns in ggplot2?

I have a data frame that looks roughly like this: aa <- c(1:7) bb <- c(11:15) df1 <- expand.grid(aa, bb) val1 <- rnorm(nrow(df1)) val2 <- runif(nrow(df1)) df <- data.frame(df1, val1, val2) names(df) <- c("aa", "bb", "val1", "val2") What I want to…
user3825755
  • 883
  • 2
  • 10
  • 29
0
votes
0 answers

Run multcompLetters on data.frame with 2 grouping columns

I am running a Tukey's test on sub-groups in a melted data.frame. The result shows pairwise comparisons that are grouped by two columns: CLASS and comparison. I am now trying to use multcompLetters to obtain a compact letter display, however this…
J.Con
  • 4,101
  • 4
  • 36
  • 64
0
votes
3 answers

melting df into 3 columns

I am trying to melt the following dataset into 3 columns - 'hour', 'variable', and 'cluster' > head(kpitdur) hr_0 hr_1030 hr_1130 hr_160 hr_180 hr_190 hr_200 hr_630 hr_830 1 79.08333 63.06667 63.06667 63.06667 63.06667 63.06667…
iskandarblue
  • 7,208
  • 15
  • 60
  • 130
0
votes
2 answers

Reshaping a data frame by reverse melt

I have a dataset with two sets of observations for 830 and 930. My objective is to reshape my data frame so that there is one originID column, one 830 column, and one 930 column, keeping the values under walking in their respective hour column. It's…
iskandarblue
  • 7,208
  • 15
  • 60
  • 130
0
votes
0 answers

sort x axis in melted frame R

I have a data frame and I am binding the rowids to the frame. When I try to plot the graph with rowIds on X axis, I see the values sorted alphabetically. How to plot the graph with Ids sorted numerically and display on X axis …
Twinkling Star
  • 135
  • 2
  • 14
0
votes
1 answer

returning matched value using melt

Input listofstring <- c("Mac","Windows","Linux","Android") test <- data.frame(query = c("I love Mac","I love Ubuntu","I love Android","I love both Android and Linux"), numerical_val = c(20,30,40,50)) I am currently using following method which is…
vk087
  • 106
  • 12
0
votes
1 answer

How to use melt() from the reshape2 package to stack categorical labels of data to produce multiple side-by-side boxpots

I am trying to use the melt() function from the “reshape2” package in R to stack a dataframe while keeping categorical labels for the individual observations. My question is how do I adapt Eric Cai's code Code to produce multiple side-by-side…
Alice Hobbs
  • 1,021
  • 1
  • 15
  • 31