Questions tagged [reshape2]

The reshape2 package in R contains functions that allow data to be transformed into more convenient forms.

reshape2 is an package for flexibly restructuring and aggregating data. Its primary use is ing data between wide format with repeated measurements in separate columns of the same record and long format with the repeated measurements in separate records.

reshape2 succeeds the reshape package, and is succeeded by the package.

Repositories

Other resources

Related tags

1177 questions
0
votes
1 answer

Reshape wide data frame to long format in R using column name information

I am having troubles converting a complicated data base output from its wide form to the long format. It has a couple of hundred rows and ~1,000 columns. It looks something like this: The problem is that the variable of df1_long or the columns of…
JollyRoger
  • 473
  • 4
  • 9
0
votes
1 answer

How to graph multiple lines in a single plot ggplot2?

I'm working on a R Shiny program that can take any csv file and output graphs of it. The user who uploads the csv has some guidelines on how the data should look, but I don't want it to be too strict. I'm currently trying to use ggplot2 to graph…
user2522217
  • 345
  • 1
  • 7
  • 20
0
votes
2 answers

Reshape acast() remove missing values

I have this dataframe: df <- data.frame(subject = c(rep("one", 20), c(rep("two", 20))), score1 = sample(1:3, 40, replace=T), score2 = sample(1:6, 40, replace=T), score3 = sample(1:3, 40,…
luciano
  • 13,158
  • 36
  • 90
  • 130
0
votes
0 answers

Melt in reshape2

I have a dataframe for plotting the results of an ordinal regression model. I´d like to melt my dataframe, but the results are not correct. When I create a toy dataframe from the original dataframe with fewer columns I get the correct answers. Any…
Misha
  • 3,114
  • 8
  • 39
  • 60
0
votes
1 answer

Panel Data from Long to wide reshape or cast

Hi i have panel data and would like to reshape or cast my Indicator name column from long to wide format. currently all the columns are in long format, Year(1960-2011), Country Name (all the countries in the world), Indicator name (varying by…
ManafQ
  • 21
  • 3
0
votes
1 answer

how would I get the below answer using melt/cast from reshape2 package

I have two data frames, x and y. I rbind them to get z. Then I use reshape function (not package) to get the below answer. set.seed(1234) x <- data.frame(rp=c(1:5),dmg=1000*runif(5), loss=500*runif(5), model="m1") y <-…
0
votes
3 answers

Transforming a min() and a max() value into a range of values

I would like stretch some of my records that were flattened I have a table like this Store Min(Date) Max (Date) Status NYC1 1/1/2013 2/1/2013 Open NYC1 2/2/2013 2/3/2013 Closed for Inspection Boston1 …
Green Demon
  • 4,078
  • 6
  • 24
  • 32
0
votes
1 answer

custom variable names in R reshape2

Is there a way to change the default way that the dcast function names variables? For example require(reshape2) x = data.frame(id=1:2, t=1:5, v=10:1) m = melt(x, id.vars = c("id", "t")) cx = dcast(m, t ~ variable + id) print(cx) # t v_1 v_2 #1 1 …
Alex
  • 19,533
  • 37
  • 126
  • 195
0
votes
3 answers

R reshape to comparable long

I have a matrix x A B C D 1 11 12 13 14 2 21 22 23 24 3 31 32 33 34 4 41 42 43 44 5 51 52 53 54 and two vetors [,1] [,2] [1,] "A" "B" [2,] "A" "C" [3,] "A" "D" [4,] "B" "C" [5,] "B" "D" [6,] "C" "D" what I want to get is the…
mffap
  • 481
  • 4
  • 11
0
votes
1 answer

which.min within reshape2's dcast()?

I would like to extract the value of var2 that corresponds to the minimum value of var1 in each building-month combination. Here's my (fake) data set: head(mydata) # building month var1 var2 #1 A 1 -26.96333 376.9633 #2 …
baha-kev
  • 3,029
  • 9
  • 33
  • 31
0
votes
1 answer

Reshaping a data.frame

I have the following table structure(list(Compound = structure(c(1L, 2L, 3L, 1L, 1L, 3L), .Label = c("Nap", "Phe", "tre"), class = "factor"), Area = c(17197669L, 19464754L, 35792660L, 10097291L, 348395L, 2576352L), Samples = structure(c(1L, 1L,…
user2048457
0
votes
2 answers

reshaping data in R skipping certain measured variables

I would like to reshape a data.frame that looks like this: permno dte ttm var1 var2 var3 1 123 2012-01-01 20 1 10 100 2 123 2012-01-01 30 -1 10 100 3 124 2012-01-01 20 2 20 200 4 124 2012-01-01 30 …
Alex
  • 19,533
  • 37
  • 126
  • 195
0
votes
3 answers

paste values within categories defined by multiple columns

I want to pivot the result column in df horizontally creating a data set with a separate row for each region, state, county combination where the columns are ordered by year then city. I also want to identify each row in the new data set by region,…
Mark Miller
  • 12,483
  • 23
  • 78
  • 132
0
votes
3 answers

Converting dataframe to partial "wide" and partial summary by group

I have the following data frame id datestamp hrofday val1 val2 val3 a 20120401 0 3.2 0 1 a 20120401 1 3.3 4 0 a 20120401 2 3.4 6 0 ... a 20120401 23 7.3 0 2 It represents a user-id followed by hour of day, val1 val2 & val3. I want to use cast…
broccoli
  • 4,738
  • 10
  • 42
  • 54
0
votes
1 answer

How to pass a premade list of functions to cast

cast, from the reshape2 package, can handle a bunch of functions if passed directly in the call. For example: library(reshape2) d <- data.frame(variable="variable",value=rnorm(100)) cast(d, variable ~ ., c(mean,sd,max,min)) But, this doesn't work…
Brandon Bertelsen
  • 43,807
  • 34
  • 160
  • 255