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

Translate R reshape into dcast

Hello and sorry if I am repeating myself, but I simply cannot wrap my head around moving from reshape to dcast. I have a small dataset: Val relation t 1 621.4035 unrelated 34 2 626.4485 unrelated 50 3 633.3349 unrelated 67 4…
striatum
  • 1,428
  • 3
  • 14
  • 31
0
votes
2 answers

How to convert a 'by' [list] output into a dataframe

data= data.frame(col1=c('m1','m1','m1','m2','m2', 'm2','m3', 'm3'), class=c('a','b','c','a','b','c', 'a', 'b'))I have a data.frame with 2 columns, the 1st column is a list of models, the 2nd column a list of model attributes. I need to show…
LuluPor
  • 165
  • 1
  • 11
0
votes
1 answer

Reshape matrix in R

I am struggling to find an automated way to reshape my matrix below. Please see my example output on how I would like it to be reshaped. Change Position1 Position2 Position3 Position4 Gene1 2.3 1 1 …
user3741035
  • 2,455
  • 4
  • 15
  • 20
0
votes
3 answers

Getting every combination in a data frame when data already exist in some rows (R)

I recently just used dcast (in the reshape2 package) to condense my data frame from long format to wide (since I needed counts). Now, I need to fill in the combination that do NOT exist with a 0. I imagine I could do something with expand.grid in…
HFBrowning
  • 2,196
  • 3
  • 23
  • 42
0
votes
2 answers

convert long dataset to wide dataset using R

I'd appreciate some assistance in what R code to use in the following situation: This is the top 11 rows of the dataset: Sa1_main11 Sa1_main11_2 20401106101 20401106101 - 20401106101 21105128609 - 20401106101 21105128653 20601110501…
Graham
  • 13
  • 1
  • 3
0
votes
3 answers

Widening data with ordinal subgroupings

I have a data set (~200K rows) similar to this mock data: mydf <- read.csv(url("http://pastebin.com/raw.php?i=YWTW98Pu"), header=T) I am trying to widen it from its current form to what I fully understand is an untidy, bad schema (external…
0
votes
2 answers

How to "stack" and "unstack" in R, for summary statistics with 2 factors

I'm attempting to calculate two summary statistics (mean and standard error) from the following data set, where both Location and Adult should be factors. Location Adult OverComp F 1 7 P 1 8 P 0 …
M.A.Kline
  • 1,697
  • 2
  • 19
  • 29
0
votes
0 answers

How to update formula containing a dot?

I am using the formula conventions in ?dcast, namely the use of a . (dot), and I've run into trouble when having to update the formula. Consider this: require(reshape2) x.form <- formula(Species ~ .) dcast(iris, x.form) From ?dcast: There are a…
landroni
  • 2,902
  • 1
  • 32
  • 39
0
votes
5 answers

Extracting columns from dataframes in a list to produce a final, combined dataframe

Apologies, returning to lists and dataframes in R after a while, so have forgotten my way about. Suppose that I have several dataframes in a list: d2<- data.frame(week=c("12th","13th","14th"),value=c(1,20,100)) d1<-…
info_seekeR
  • 1,296
  • 1
  • 15
  • 33
0
votes
2 answers

colsplit to split into individual characters

colsplit in package reshape2 can be used to split character data: colsplit(c("A_1", "A_2", "A_3"), pattern="_", c("Letter", "Number")) Letter Number 1 A 1 2 A 2 3 A 3 In his paper "Rehaping data with the Reshape…
peter2108
  • 5,580
  • 6
  • 24
  • 18
0
votes
1 answer

How to test for an absent row/value in a dataframe to help transpose part of it?

I have a dataframe containing data on repeatedly sampled individuals and days alive. Some individuals were not sampled on every day alive. I want to move the data from being row oriented (each individual&day alive being a row) to column oriented…
DirtStats
  • 559
  • 9
  • 29
0
votes
1 answer

Reshape multivariate time series in R

I have time series T(1), T(2), T(3), T(4)...Tn in addition I have 2 other time-dependent parameters P(1), P2(2), P(3)... and R(1),R(2),R(3)... Therefore the data looks like T(1) P(1) R(1) T(2) P(2) R(2) T(3) P(3) R(3) T(4) P(4) R(4) T(5) P(5)…
blast00
  • 559
  • 2
  • 8
  • 18
0
votes
1 answer

Data manipulation in csv using R

I'm currently working with data generated by eyelink. The csv (transformed from asc) is basically one large sequential list, i.e. columns are not created, so for example a row will have 'trial 1' and the following row will have x and y coordinates…
Docconcoct
  • 2,040
  • 4
  • 28
  • 52
0
votes
1 answer

R: Creating long dataset when rows are variables and columns are years

I have data that looks like this: Country.Code Indicator.Code X1960 X1961 X1962 X1963 X1964 X1965 AFG allsi.bi_q1 NA NA NA NA NA NA AFG allsp.bi_q1 NA NA NA NA NA NA AFG …
Kenji
  • 571
  • 4
  • 20
0
votes
1 answer

R: reverse reshape2's melt() on n-dimensional arrays

I've got a 3-dimensional array in R that I can use melt() on to produce a long data.frame: library(abind) library(reshape2) a = matrix(1:4, nrow=2, ncol=2) x = abind(a, a, along=3) y = melt(x) y which yields: Var1 Var2 Var3 value 1 1 1 1…
Michael Schubert
  • 2,726
  • 4
  • 27
  • 49