Questions tagged [dcast]
267 questions
1
vote
3 answers
Apply dcast multiple times for different variables
Suppose I have a data frame with id A and a couple of factor variables.
library(data.table)
library(dplyr)
mydf <- data.table(
A = as.factor(c("A", "B", "C", "D","E")),
V1 = as.factor(c("x", "x", "y", "x", "y")),
V2 = as.factor(c("u", "v",…

Y.Olshanskiy
- 115
- 5
1
vote
2 answers
Convert rows into columns taking the names from one variable
I have a dataset of this kind df:
df <- as.data.frame(matrix(c(1,1,1,1,2,2,
2020,2020,2020,2020,2020,2020,
1,2,1,2,3,6,
…

vog
- 770
- 5
- 11
1
vote
1 answer
restructure large data frame with multiple data types
I'm struggling to get my data (xlsx file) in the correct shape. My original database is as follows:
patient when age weight height watchID dateFrom
1 T01 pre …

Ztarrk
- 13
- 2
1
vote
1 answer
summarizing a dataframe and adding column with mean ± SD
I have a dataframe of many variables (soil properties) for 11 legumes in 2 different locations. first few columns of the data is shown below.
SPECIES LOCATION pH NO3 NH4 P Organic_C K Cu Mn Zn BD X.Sand X.Silt X.Clay
1 C.…

ngwoke chukwubuikem
- 37
- 4
1
vote
1 answer
R: Problems with reshaping using dcast or pivot_wider
I am having a trouble reshaping the following data frame:
set.seed(45)
dat1 <- data.frame(
name = rep(c("firstID", "secondID"), each=4),
numbers = rep(1:4, 2),
value = rnorm(8),
Category = rep(c("111", "22"), each=4)
)
dat1
…

annalyst
- 21
- 5
1
vote
0 answers
Row and columns-wise calculation in long format in R
I am struggling with cellwise-calculations in a complex data-set (see below for dput() example).
I need to apply the formula for standardized mean difference (M1-M2/sqrt(s1^2+s2^2) to multiple rows and columns (studies and tests). The M1 & M2…

shizzle
- 89
- 11
1
vote
3 answers
Combination of reshaping and aggregating a data.frame
I'm still somewhat new so please forgive any missteps, but I currently have a data.frame that looks like this.
Outcome1 Outcome2 Num_Occurances Name
False False 2 John Doe
False True 2 John Doe
True …

mkb123
- 63
- 8
1
vote
1 answer
How to make each row a new set of variables and rename them dynamically in r
First, I want to convert this data:
datinput = read.table(header = TRUE, text = "
var1 var2 var3
A 3 10
B 2 6
")
datinput
var1 var2 var3
1 A 3 10
2 B 2 6
into this format:
datoutput = read.table(header = TRUE, text = "
var2.A…

Krantz
- 1,424
- 1
- 12
- 31
1
vote
1 answer
Pivot_table in pandas with a rowid sequence
I have data like this:
ID Cue trial time accuracy
A apple copy 1450 1
A dog copy 2154 1
A apple test1 2121 0
A dog test2 0 1
A …

Kalif Vaughn
- 353
- 2
- 5
- 10
1
vote
2 answers
dcast issue on dataframe consisting two columns
I have a dataframe with two columns and trying to convert it two wide format as shown below. However, I am not able to figure out for a data frame consisting only a numeric and a non numeric…

itthrill
- 1,241
- 2
- 17
- 36
1
vote
1 answer
How to use reshape2's dcast to select only one of several observations(values)
I have the following dataset
> dataset2
ID ATCcode date
1 1 N06AA 2001-01-01
2 1 N06AB 2001-04-01
3 1 N06AB 2001-03-01
4 1 N06AB 2001-02-01
5 1 N06AC 2001-01-01
6 2 N06AA 2001-01-01
7 2 N06AA 2001-02-01
8 2 …

Blue badger
- 47
- 8
1
vote
1 answer
NxN tabluation over columns in R and check duplicacy between columns
I have a dataframe with unique items procured on rows and their corresponding sources on columns (Basically this is a data which I have "dcast" from original data)
Now it looks like this
DF <- data.frame(Food = c("Burger",
…

Vaibhav
- 21
- 6
1
vote
3 answers
Conditional merge, based an event happening between two panel observations
I have a panel dataset: panel and a dataset with a list of events: Events. For the panel dataset, an equal panelID shows that two observations belong together.
panelID = c(1:50)
year= c(2001:2010)
country = c("NLD", "GRC", "GBR")
n <-…

Tom
- 2,173
- 1
- 17
- 44
1
vote
1 answer
How to "fill" a variable with dcast
As part of a study of car-sharing, I'm using tables which look like this one :
The problem here is that there shouldn't be two lines : this is actually one single journey (same driver, same hour of departure) and "C" should be on the first row, in…

Mathieu -
- 53
- 1
- 5
1
vote
1 answer
How to reshape data in custom function with dcast?
I have big sales data.frame with many columns - my future parameters for function (status, payment, delivery, source etc).
week / item.type / source / order / payment / delivery
31 / device / desktop / 222-111 / cash / courier
32 / tariff / mobile /…

vecanoyee
- 13
- 2