Questions tagged [dcast]

267 questions
2
votes
2 answers

r transform dataset from wide to long for column names with patterns

Let us assume a dataset like this below. ID Gender ColA_1 ColB_1 ColC_1__1 ColC_1__2 ColA_2 ColB_2 ColC_2__1 ColC_2__2 1 Male No Yes Yes No No Yes No No 2 Female Yes No Yes No …
Science11
  • 788
  • 1
  • 8
  • 24
2
votes
1 answer

dcast a dataframe not giving correct columns

I am trying to use dcast to spread my data d: It looks like: row_id variable value 1 27 feature1 0.006960242 2 35 feature1 -0.002475289 3 27 feature2 -0.016615848 4 35 feature2 0.010806291 5 27 feature3 0.014437451 6 …
user113156
  • 6,761
  • 5
  • 35
  • 81
2
votes
1 answer

How do I change the column names using dcast?

I'm transforming my data from long to wide. Part of the data are dates. My problem is that I would like to have other colnames. It is formed like eg variable_1-1 and I want 1-1_variable. df: SN specimen_isolate_no isolaat materiaal_lokatie…
AvdH
  • 39
  • 1
  • 6
2
votes
1 answer

Unexpected behavior of dcast with integer64 numbers

I am working with international trade data from Comtrade, which was given to me as csv file. The trade values are stored as integer64. I am aware that I should read a lot more about what can and cant be done when using such a format. A simple…
desval
  • 2,345
  • 2
  • 16
  • 23
2
votes
1 answer

Long to Wide Multiple variables in R

while converting Long data to wide How do I provide multiple columns to timevar argumnet in reshape `reshape(DT, idvar="Cell", timevar = "n1", direction="wide")` like example timevar=c("n1","n2"....) DT<-data.table(Cell = c("A","A","B","B"),…
aprilian
  • 621
  • 3
  • 17
2
votes
1 answer

Reshaping data in R with multiple variable levels - "aggregate function missing" warning

I'm trying to use dcast in reshape2 to transform a data frame from long to wide format. The data is hospital visit dates and a list of diagnoses. (Dx.num lists the sequence of diagnoses in a single visit. If the same patient returns, this variable…
vzste
  • 119
  • 9
2
votes
2 answers

Dcast only one variable into a new column R

I'm trying to dcast my data so that I can split out only the Actual values into a new column. However, the only way that I've managed to do this is to dcast and then melt back. I was wondering if there's a more efficient solution. Step 1: I've done…
Gin_Salmon
  • 837
  • 1
  • 7
  • 19
2
votes
1 answer

Converting a vector into a matrix (in R)

I want to create a "n x 8" Matrix from a "n x 1" vector -- Question: Why do I want to do this? -- Answer: In order to matrix multiply this against an "8 x 8" markov chain probability transition matrix, and return an "n x 8" Matrix of the predicted…
Kunal
  • 23
  • 1
  • 4
2
votes
2 answers

Using proportion as the aggregate function in Data.Table's dcast

When creating a pivot table using data.table, I am using the dcast function: dcast(my_data, var1 ~ var2, length) This gives a table with rows as var1 lables and column as var2 labels and value as count of cells common to particular row and…
skdhfgeq2134
  • 426
  • 1
  • 4
  • 16
2
votes
2 answers

dcast() value.var do not find input

I am trying to use dcast(), but I can't figure out why I get this error: "Error : value.var (mpg) not found in input". Dcast can't seem to find "mpg" which I made a measure.vars in the melt function. Can you guys help me? Here is my…
Willy Mercier
  • 21
  • 1
  • 2
2
votes
1 answer

R: reshape a data frame when more than 2 dimensions

I am trying to cast a dataframe into an other one, see below for the examples: > start = data.frame(Aa = c('A','A','A','A','a','a','a','a'),Bb = c('B','B','b','b','B','B','b','b'),Cc = c('C','c','C','c','C','c','C','c'),v=c(1,2,3,4,5,6,7,8)) >…
Reyflex
  • 23
  • 2
2
votes
1 answer

R - Pivot table with subtotals

How do I get Pivots with subtotals (like in MS Excel Pivot Tables) in R? I am using dcast from reshape2 package to create pivots in R. I also got grand totals working using rowSums and colSums. I admit I do not understand the intricacies in the…
Arani
  • 753
  • 1
  • 9
  • 23
2
votes
1 answer

Why dcast round my float numbers?

I have one data frame as: > head(df) nome Class_Name area_class date 1 Arataca agropecuaria 25.7751 1973-07-26 2 Arataca agua 0.2918 1973-07-26 3 Arataca bosque 0.0207 1973-07-26 4 Arataca bosque …
dogosousa
  • 151
  • 9
2
votes
1 answer

Using dcast.data.table to transform from long to wide only for subset of column values

I'm working on a market basket analysis project and have data that contains a variable that represents an ID, and another that contains only one item in a basket. There are ~50K unique items across users, but I have created a simple table below for…
Julian Hui
  • 31
  • 2
2
votes
1 answer

Transform longitudinal table to wide format efficiently in data.table

I am working in R with a long table stored as a data.table containing values obtained in value changes for variables of numeric and character type. When I want to perform some functions like correlations, regressions, etc. I have to convert the…
Jon Nagra
  • 1,538
  • 1
  • 16
  • 36
1 2
3
17 18