Questions tagged [dcast]
267 questions
1
vote
2 answers
Dcast multiple observation in a 1 cell in R
I have one R dataframe
Customer Month BaseVolume IncrementalVolume TradeSpend
10 Jan 11 1 110
10 Feb 12 2 120
20 Jan 21 7 …

Ajay jadhav
- 143
- 1
- 9
1
vote
1 answer
How to split one column into different columns with dcast without aggregating?
I'm trying to reshape my data using dcast. I'm working with samples where each sample has 10-30 sample units. I can't have my data aggregate.
My data is in this format:
ID total
sample_1 1
sample_1 0
sample_1 2
sample_1 1
sample_1 …

Daniela Pezzini
- 13
- 4
1
vote
1 answer
Embedded Ifelse Statement
I have a dataset as follows:
Source Rev_Diff Cost_Diff Price_Diff Sales_Diff
A -10 10 11 12
B 11 -10 -10 11
C -12 …

nak5120
- 4,089
- 4
- 35
- 94
1
vote
2 answers
R dcast fill with a sample number
I wonder if there is a way to fill with random numbers each individual missing value when using dcast (library reshape2 or data.table). Example:
ID = c('AA', 'AA', 'BB', 'BB', 'CC', 'CC', 'CC', 'DD', 'DD')
Replica =…

David JM
- 351
- 1
- 3
- 11
1
vote
2 answers
Casting multiple value.var controled by fun.aggregate
I have the following dataset
client_id <- c("A", "A", "B", "B", "B", "B", "B", "A", "A", "B", "B")
value <- c(10, 35, 20, 30, 50, 40, 30, 40, 30, 40, 10)
period_30 <- c(1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0)
period_60 <- c(1, 1, 1, 1, 1, 0, 0, 0, 0, 0,…

Prometheus
- 1,977
- 3
- 30
- 57
1
vote
1 answer
Delay calculated per group for different splits
I want to calculate the average delay between transactions for different splits. I already have a solution, but I need the delay calculated through a different method.
The dataset looks like this:
customer_id transaction_date type …

Prometheus
- 1,977
- 3
- 30
- 57
1
vote
1 answer
R: Melt and Dcast
I have a dataset like this:
CASE_ID = c("C1","C1", "C2","C2", "C2", "C3", "C4")
PERSON_ID = c(1,0,7,8,1,20,7)
PERSON_DIVISION = c("Zone 1", "NA", "Zone 1", "Zone 3", "Zone 1", "Zone 5", "Zone 1")
df <- data.frame(CASE_ID, PERSON_ID,…

Natalia P
- 97
- 1
- 7
1
vote
0 answers
R dcast duplicating first subject when creating wide-format data
I am trying to move from long format data to wide format in order to do some correlation analyses.
But, dcast seems to create to rows for the first subject and splits the data across those two rows filling the created empty cells with NA.
The first…

JLC
- 661
- 7
- 16
1
vote
1 answer
R dcast: applying value/conditional exclusions to sub-totals
I have a two-parter question. In creating a dataset similar to what I have, we can start with the airquality dataset:
myaqm <- melt(airquality, id=c("Month", "Day"), na.rm = TRUE)
myaqm_dcast <- dcast(myaqm, Day+variable~Month,
value.var…

Belinda-Jane Netan
- 527
- 6
- 12
1
vote
2 answers
Converting Columns to Rows with two summary values in R
I have a data.frame like this:
P Stat V Points
1 Goals 2 10
1 Assists 1 3
2 Goals 1 5
2 Assists 1 3
and I would like to convert it to something like this:
P Goals Assists Points
1 2 1 13
2 1 1 …

sjhuk
- 313
- 2
- 7
1
vote
2 answers
Turn unique values into new columns and check for all other values
Thanks to @hrbrmstr I got a real good solution for the "Scraping a xml document (nested url-structure)" problem.
But as a result from that insight, it emerged another problem:
Now I have got the following data-structure...
$Vorname : chr "Jan"…

Peter Noah
- 25
- 4
1
vote
1 answer
R dcast: How do I perform dcast value calculations?
I have a large data frame, with which I run this:
dcast(mydata, People ~ Categories, value.var = "Answer Count", **sum**)
and this is the result:
People category1 category2
Marge 3,648 6,402
Homer 3,586 6,684
Bart 3,469 7,119
Lisa …

Belinda-Jane Netan
- 527
- 6
- 12
1
vote
3 answers
Proper way of calculating means when aggregating data in long format
For a simple data frame:
client_id<-c("111","111","111","112","113","113","114")
transactions<-c(1,2,2,2,3,17,100)
transactions_sum<-c(5,5,5,2,20,20,100) ##precalculated sums of transaction counts for each…

kkgery
- 431
- 6
- 13
1
vote
0 answers
R ffdfdply appending error
I want to cast my data (data.frame) from long to wide format with the values of "ITEM" as columns and values ("ITEM2") (see below):
Long format
Wide format
Therefore I use the dcast-function from the package reshape2:
df <= dcast(df,SEQUENCEID +…

silem
- 21
- 7
1
vote
1 answer
add more multiple columns based on value in other columns in R
i have a data table, which contains three variables:
hours: format is int, value in the range of [0,23], and it is increased
mins: format is int, value is (10,20,30,40,50,60), it is also increased
x: format is int
below is a simple…

ZAWD
- 651
- 7
- 31