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

Match lists for use with PREDICT: list of lm() objects and list of data

I have 18 dates (e.g. unique DAY, MONTH, YEAR) and 10 variables. I have a lm model (y = mx + b, where y = value and x = pLength) for each date and variable (180 models). These are stored in a list (i.e. models). I want to use these models to…
nofunsally
  • 2,051
  • 6
  • 35
  • 53
0
votes
2 answers

Use list of models to calculate new values in a data.frame

Using dlply (from this post; code below) I am able to generate a list of linear models on subsets of my data.frame. Now that I have this list, I would like to use the models to generate values in another data.frame. The list contains a model for…
nofunsally
  • 2,051
  • 6
  • 35
  • 53
0
votes
1 answer

Formatting to count data

I have the following data.frame: df = data.frame(a = sample(c(rep(1,23),rep(2,22), rep(3,43), rep(4, 12))), b = sample(c(rep(1,10),rep(2,10), rep(3,20), rep(4, 60))), c = sample(c(rep(1,40),rep(2,5), rep(3,30),…
Remi.b
  • 17,389
  • 28
  • 87
  • 168
0
votes
2 answers

R "melt-cast" like operation

I have a file contains contents like this: name: erik age: 7 score: 10 name: stan age:8 score: 11 name: kyle age: 9 score: 20 ... As you can see, each record actually contains 3 rows in the file. I am wondering how can I read in the file and…
B.Mr.W.
  • 18,910
  • 35
  • 114
  • 178
0
votes
2 answers

R transform data frame (group by)

I am an R and Stack Overflow newbie so hope I'm following protocol here. How do I transform a data frame like: FRUIT NUMBER NAME AGE apples 5 Joe 13 oranges 6 Joe 13 apples 2 Mary 10 oranges 4 Mary …
kc2819
  • 1,491
  • 2
  • 10
  • 5
0
votes
3 answers

R: Scatter plot of time series data for multiple points, ggplot?, reshape?

I have data in the following format. Column V1 is the genomic location of interest, and column V4 and V5 are the minor allele frequencies at two different points in time. I would like to make a simple xy scatter plot with a line connecting the…
ONeillMB1
  • 343
  • 6
  • 19
0
votes
1 answer

Multiple paired wilcoxon testing across factors in a data.frame

I find myself often having to do multiple paired comparisons of subsets of a data set (with the subset provided for by one or two factors). Now, I would very much make this a bit easier to do in a comprehensive way, in a function. This is what I…
Fredrik Karlsson
  • 485
  • 8
  • 21
0
votes
2 answers

Expand a single column to a wide/model matrix format

Suppose I have a column in a matrix or data.frame as follows: df <- data.frame(col1=sample(letters[1:3], 10, TRUE)) I want to expand this out to multiple columns, one for each level in the column, with 0/1 entries indicating presence or absence of…
Scott Ritchie
  • 10,293
  • 3
  • 28
  • 64
0
votes
1 answer

Convert datafile from wide to long format to fit ordinal mixed model in R

I am dealing with a dataset that is in wide format, as in > data=read.csv("http://www.kuleuven.be/bio/ento/temp/data.csv") > data factor1 factor2 count_1 count_2 count_3 1 a a 1 2 0 2 a b 3 0 …
Tom Wenseleers
  • 7,535
  • 7
  • 63
  • 103
0
votes
2 answers

R: How to get something like adjacency matrix, but on the intersection value of third column?

I have data frame like this: V1 V2 LABEL 1 83965 891552 A 2 88599 891552 B 3 42966 891552 C 4 83965 891553 D 5 88599 891553 D 6 42966 891553 B How can I convert it to something like adjacency…
andilabs
  • 22,159
  • 14
  • 114
  • 151
0
votes
1 answer

Transform data frame/matrix to a different organized matrix

I have a very similar doubt to my last one (Transform data frame into matrix with counts). Again, I have data files structured like this: OTU1 PIA0 1120 OTU2 PIA1 2 OTU2 PIA3 6 OTU2 PIA4 10 OTU2 PIA5 1078 OTU2 PIN1 …
Ma_fermar
  • 33
  • 2
  • 10
0
votes
1 answer

Convert list to dataframe in R when dataframes in list are named NULL

Following a web scrape with RCurl, I've used XML's readHTMLTable and now have a list of 100 dataframes with 40 observations of two variables. I would like to convert this to a single dataframe of 100 rows and 40 columns. The first column in each of…
Adam Smith
  • 2,584
  • 2
  • 20
  • 34
0
votes
1 answer

Extract data value from the output of melt in reshape2

I have a data set in the following format and want to extract data-value for each combination like A_ALL, B_ALL, A_Part, B_part for stastical analysis. Currently, what I can do is A_ALL <- data[data$variable=="All" & data$Set=="A",1] A_Part <-…
ct586
  • 353
  • 1
  • 4
  • 8
0
votes
1 answer

Why is dcast not working in reshape2?

This paper that was published for reshape package (Wickham 2007) gave this example: library(reshape2) ffm <- melt(french_fries, id = 1:4, na.rm = TRUE) dcast(ffm, variable ~ ., c(min, max)) Similarly, this doesn't work in reshape2 but appears to…
luciano
  • 13,158
  • 36
  • 90
  • 130
0
votes
2 answers

Reshaping data in R without using dcast (reshape2)

my dcast Rcodes are not running anymore. I have the problem discussed here: segfault in R using reshape2 package and dcast The bug has not yet been fixed so I am looking for other ways of achieving my dcast output. Any suggestions would be greatly…
GodinA
  • 1,053
  • 3
  • 17
  • 27