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

how to Cast part of the df but still keeping some other columns

What I want to do is create a new column that split task billable and allocate taskHRS to that columns (cast) and allocate the hours into true and false without affecting the other columns. Code that I am using but doesn't get the desired outcome: …
luis vergara
  • 131
  • 1
  • 9
0
votes
2 answers

Is there a way to summarise my questionnaire data to show the number of each response for each question?

My data looks a bit like this: Q1 Q2 Q3 Q4 S NS S S NS . S PMI S S TMI S PMI S S NS The only options are S, TMI, PMI, NS (or missing, which is a .). I would like it to look like this (df called PCP): Q1 Q2 Q2 Q4 S 2 …
morgan121
  • 2,213
  • 1
  • 15
  • 33
0
votes
2 answers

melt() is using all column names as id variables

So, with ths dummy dataset test_species <- c("a", "b", "c", "d", "e") test_abundance <- c(4, 7, 15, 2, 9) df <- rbind(test_species, test_abundance) df <- as.data.frame(df) colnames(df) <- c("a", "b", "c", "d", "e") df <- dplyr::slice(df, 2) we get…
Snowfaerie
  • 23
  • 1
  • 10
0
votes
1 answer

casting and melting data.table in r

I have the following data.table: CASEID VISIT AVWEIGHT med.corrected DLYDOSE DLYFREQ 1: 1004 10 55.5 LISINOPRIL 20.00 2 2: 1004 20 53.9 LISINOPRIL 10.00 1 3: 1004 30 60.4 LISINOPRIL 10.00 …
attambomb
  • 1
  • 1
0
votes
3 answers

R Pivot table with columns converted to only rows

I basically do reporting on marketing data and am trying work on some automation in R. In excel we can drag and select columns into the "Rows" area of a pivot table to summarise the data. I have a similar situation where I would like to group or…
0
votes
0 answers

Python Pandas: combine dataframes in stack

I have two pandas DataFrames of coordinates: df1 and df2. I would like to create a long DataFrame of the pairs of coordinates from each DataFrame. For example, given import pandas as pd df1 = pd.DataFrame({'a_x':[1,2,3],'b_y':[4,5,6]}) df2 =…
Docuemada
  • 1,703
  • 2
  • 25
  • 44
0
votes
0 answers

Python Pandas merge, melt, pivot_table for data pipeline

I have a data pipeline that I'm writing in Python with Pandas. It's working, and I mostly like it. Pretty good with Python. Less good with Pandas at this point. As a student of Python, however, I'm always looking to be more idiomatic and not…
Adam Larsen
  • 85
  • 1
  • 7
0
votes
1 answer

reshape data.table using by

I have a data.table where the data I want is structured in a diagonal fashion. library(data.table) month <- c(201406, 201406, 201406, 201406, 201406, 201406, 201406, 201406, 201406, 201406, 201406, 201406) code <- c("498A01", "498A01", "498A01",…
jvalenti
  • 604
  • 1
  • 9
  • 31
0
votes
2 answers

How can I melt four columns together in R

I need to reshape this data below in long format stacking four columns A C G and T columns together. I have found many answers for two columns, but could not find for more than two columns. mydata<- structure(list(Pos = 1:18, A = c(1.22050447518308,…
MAPK
  • 5,635
  • 4
  • 37
  • 88
0
votes
2 answers

How to melt/mutate a dataframe?

I know there are plenty of question specifically asking about melting or altering dataframes but after a bit of research I could not find any that directly related to my question. Each month, our company uploads a data file that has sales data from…
0
votes
1 answer

How can I melt multiple columns in R

I have this data called my.data. I want to melt all columns together and get the result in three columns. The final data should have three columns- 1. key.related column 2. IBS values from all three columns (IBS_2_samples IBS_4_samples…
MAPK
  • 5,635
  • 4
  • 37
  • 88
0
votes
2 answers

R: reshape dataframe with duplicated variable names labeled var.1, var.2

I'm hoping to reshape a dataframe in R so that a set of columns read in with duplicated names, and then renamed as var, var.1, var.2, anothervar, anothervar.1, anothervar.2 etc. can be treated as independent observations. I would like the number…
ksw
  • 313
  • 3
  • 11
0
votes
1 answer

Mov file playback error using MLT Melt on OSX

I'm trying to playback a Mov file on OSX using the command: $melt MVI_3001.mov However, there's a momentary flash and the following error: libc++abi.dylib: terminating with uncaught exception of type NSException Abort trap: 6 What does this…
0
votes
1 answer

Convert list to dataframe in R

I have a very unfriendly list and need to convert it into a df (res) for further processing. The structure of the columns is always the same with value, count, value.1,count.1......etc. Ideal form of the dataframe: value count value.1 count.1…
Lucas
  • 1
0
votes
2 answers

Excluding variables and those near them- r dplyr

I have a dataset which is the output of multiple data loggers measuring temperature and lux (strength of light) at 1-hour intervals. There are approx. 250,000 data points. I'm having trouble with temperature readings from 'sun flecks' where a shaft…