Questions tagged [dcast]

267 questions
1
vote
0 answers

Factors being converted / displayed as integers in R after dcast

In the question presented here, sample data was converted from wide to long format using dcast. However, when attempting to apply the same approach to the actual data set (or an abbreviated form thereof): dcast(melt(smallz, 1:2), behavior_num +…
d-cubed
  • 1,034
  • 5
  • 30
  • 58
1
vote
1 answer

Specify order of columns of dcast output

I have the following data table: df = data.frame(id=c(1,1,1,1),timepoint=c("3 months","6 months","9 months","12 months"), date=c("date1","date2","date3","date4"),bool=c("Y","Y","N","Y"), name=c("abc","def","ghi","jkl"),…
Impossible9
  • 101
  • 7
1
vote
0 answers

dcast running out of memory - alternatives?

I am trying to reshape a (very) long table into a wide (very sparse) table. The dimensions: dim(data) [1] 16146436 3 If i attempt the standard dcast operation it fails due to running out of memory: datac <- dcast(formula=gene ~ sample,…
1
vote
1 answer

why is dcast so impossible to pass a non-aggregate function?

I am using the data.table package for a table like this: DT <- data.table(id=rep(1:100, each=50), grp=rep(letters[1:4], each=1250), time=rep(1:50,100), outcome=rnorm(5000), …
michel
  • 282
  • 2
  • 17
0
votes
0 answers

Error in trying to change my data from long to a wide format using data.table::dcast()

I have a couple of files that I am trying to convert to a wide format. However, I got it to work but I then realized that the way the data is displayed when was a little confusing for what I needed to use it for. For example, all of the data under…
H_0814
  • 1
  • 1
0
votes
3 answers

reshaping data using reshape() to wide format instead of dcast or pivot functions

I am having some problems understanding reshape function and would like to specifically use it as it uses base r. Consider the following code month <- c("jan", "feb", "mar", "apr") hours <- c(40, 40, 35, 37) days <- c(31, 28, 31, 30) dat <-…
TheBoomerang
  • 109
  • 5
0
votes
1 answer

R transform data wid while keeping date format - reshape or dcast

Trying to do something so simple and transpose this data wide so for each ID I have the VisitNum {1,2,3} as the column header and the CollectionDate as the value. At my starting point Collection date was a character variable and VisitNum was…
0
votes
0 answers

Is there an efficient way to combine dcast, melt and merge on large dataset in R?

I have 4 csv files of 63290 obs and 6 columns each. I transform them into datatable format. I am trying to use dcast and melt on each to create a count variable. But I am getting this error message: cannot allocate vector of size 8.0Gb I will then…
Guyle
  • 1
0
votes
0 answers

how to merge dataset after applying dcast and melt for occurrence count purposes?

I have a panel dataset of firms with multiple variables. I create one dummy variable treat2 which equals 1 when a given firm takes one action in two consecutive months within a given year and 0 otherwise using dcast. I am looking for a way to…
Guyle
  • 1
0
votes
0 answers

Can I separate a numeric column in r into separate individual columns conditional on the value of another variable, ending with a reduced length

I wish to separate a column of numeric data in R into 3 individual columns based on an additional variable in the data frame. Here is some code to produce an example of the kind of data I am working with. bus_reg_no <- c('G01', 'G01', 'G01', 'G02',…
daisy
  • 61
  • 1
  • 6
0
votes
0 answers

how to split up a numeric column in r into 3 separate columns conditional on the value of another variable, with aim of reducing the final dimension

I have a very basic R question but I am having a hard time trying to get the right answer. I am trying to translate SAS code to R. Below is a snap shot of a subset of some data I am working with. What I wish to do is split up the column market_test…
daisy
  • 61
  • 1
  • 6
0
votes
1 answer

Long to wide format using dcast in r

can anyone help me figure out the code for transforming the following data in long format (Figure 1) to wide format (Figure 2)? I would like to use the wide format to make a heatmap. Thank you so much. I've tried dat_wide <- dcast(dat1, …
0
votes
2 answers

Join based on a concatenated 'origin-destination' variable and consecutive individual sites

I have two data frames, d1 and d2: d1 <- data.frame(ID=c("x1", "x1", "x1", "x1", "x1", "x2", "x2", "x2", "x2", "x2", "x2", "x2"), stat=c("A", "B", "C", "D", "E", "H", "I", "J", "J", "K", "L", "M"), OD=c("AE",…
0
votes
2 answers

Reshape long to wide with dcast

I need to reshape a dataframe csf_antibio (sample below) from long to wide format, separating all values per patient by…
0
votes
0 answers

How do I deal with this weird error function using dcast?

I am using dcast in order to widen my data table: df <- dcast(setDT(dt),locus ~ Indiv,value.var = 'x') I have a data table that is 1254840 observations and 3 variables, I need to make it 3270 observations and 373 variables. But every time I try to…