Questions tagged [dcast]

The tag has no usage guidance.

0
votes
1answer
30 views

R long to wide format categorial variables and dates

I want to make a dataset with long format with a categorial variabel (medication) that has a start and end date to wide format. As the result there should be one line per ID and for each medication a ...
2
votes
1answer
39 views

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: ...
-2
votes
0answers
27 views

Reshape data.table using multilevel index?

I have this data.table: data.table(Playlist = c("micrhouse","micrhouse","attlas","attlas"), Track = c("make a move","mango","ryat","further"), Spotify_URI= c("5nUS4bSN0cFZB0knxyM4LZ","...
1
vote
1answer
19 views

Recast in R gives different value

I have the following dataframe in R DF2<-data.frame("ID"=c("A", "A", "A", "B", "B", "B", "B", 'B'), 'Freq'=c(1,2,3,1,2,3,4,5), "Val"=c(1,2,4, 2,3,4,5,8)) The datframe has the following ...
1
vote
1answer
21 views

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 ...
0
votes
1answer
52 views

how to specify ID variables in dcast?

Following is a sample of the data I have datahave # A tibble: 6 x 6 YEAR SCHOOL_NAME CONTENT_AREA BELOW_BASIC_PCT BASIC_PCT ADVANCED_PCT <dbl> <chr> ...
1
vote
2answers
27 views

Customise the aggregate function inside dcast based on the max value of a column in data.table?

I've got a data.table that i'd like to dcast based on three columns (V1, V2, V3). there are, however, some duplicates in V3 and I need an aggregate function that looks at a fourth column V4 and ...
1
vote
0answers
25 views

using dcast (reshape2) to mold data to wide format populates cells with count instead of value

I have a dataframe in long format (https://docs.google.com/spreadsheets/d/15jDW1pCYs7VD6MAH9GHmYrP-zf8WjsGj9F3qVXGijDM/edit?usp=sharing) that looks like this: objectid timestamp ...
0
votes
1answer
38 views

I have a long data set. How do I convert to wide format while using a rank function to limit the number of columns created?

I have a data set in a long format. Some records only have one manufacturer, some records are duplicated because there are multiple manufacturers associated with each record. For example, I have the ...
1
vote
2answers
28 views

how to dcast in pandas with more than one columns for columns argument

I have the following dataframe import pandas as pd df = pd.DataFrame({'id':[1,2,3,4,5,6], 'id_2':[6,5,4,3,2,1], 'col_1':['A','A','A','B','B','B'], 'col_2':['X','Z','X','Z','X','Z'], 'value':[10,20,30,...
0
votes
1answer
26 views

reshape a matrix in R and converting every n rows into one row

I have a data frame df like: year location 1 A 2 B 3 C ------------------ 1 X 5 A 10 F ------------------ 3 F 5 x 2 ...
1
vote
2answers
43 views

Calculate value with two columns based on four conditions in R

I have a large dataset uploaded in r (see below for a short version): I want to calculate a value for each Cruiseid, Samplenr, Species and Age (so based on four conditions): Cruiseid Samplenr ...
0
votes
0answers
26 views

Plotting model predictions of logistic regression with two categorical variables in an additive model?

For my graduate work, I'm examining the effects of forest management on the nesting success of breeding songbirds. I've built a combination of models to predict the effects of edge density (meters/...
0
votes
0answers
19 views

Remove the column with same value and added as a new column after transform the data in R [duplicate]

Here is my original data format (the datatype is data frame): I want to achieve the follow format: The code is written in R, so any suggestions to achieve the goal in R is appreciated. Currently, I ...
0
votes
1answer
35 views

Calculate different sets of functions passed as text strings for different columns by factor

In my R shiny App, I want to allow the user, by means of check boxes, to choose columns (instrument parameters in data), and for each of those which functions to apply (i.e. which statistics to apply):...
1
vote
1answer
116 views

r data.table::dcast cross product fails on large data set

i have a dcast() application whose cross-product exceeds .Machine$integer.max. is there a recommended alternative to dealing with this situation? i could break up w into smaller pieces, but was ...
1
vote
2answers
69 views

Long to wide with different number of rows for each group/ID

I have the following data frame: df <- data.frame(stringsAsFactors=FALSE, ID = c(2016070707, 2016070707, 2016070707, 2017080808, 2017080808, 2017080808, ...
0
votes
0answers
10 views

Transforming long dataframe to wide. Using loops, apply family, dcast, or reshape on large datasets with metadata

I have one large long data frame where every chemistry constituent (20+) is listed in a single column "Analyte" and corresponding numerical values in a "Results" column. The data frame also has ...
0
votes
1answer
43 views

Spread data based on multiple key variables

My data: df <- as.data.frame(cbind(Bilagstoptekst = c("A", "A", "A", "B", "B", "C", "D", "E", "E", "F", "F", "F", "F", "F"), AKT=c("80", "80", "80", "80", "80", "25", "80", "80", "...
1
vote
5answers
85 views

How can I merge three columns into one column according to the order of in the three columns [closed]

Could you give me an advice, please? I have three columns, e.x.: x y z 0.2 0.5 0.26 0.75 0.58 0.25 0.78 0.86 0.95 0.56 0.75 0.52 0.45 0.47 0.57 0.2 0.58 0.98 Result: And I ...
0
votes
0answers
30 views

Reshaping long to wide with multiple key pairs and aggregating based on multiple column values

I have a dataframe that looks like this: df <- data.frame(value =c(2,3,1,3,5,2), renew =c(2,2,3,2,4,1), renewFreq = c(.02,.12,.13,.12,.40,.04), recommend = c(1,3,5,4,2,...
0
votes
0answers
558 views

Unable to get dCast to work - Aggregate function missing: default to length

I have tried solutions from multiple posts on stackoverflow, but haven't had any success. If you think this is a duplicate, it's not. I have already referred to this post and this post. > head(t) ...
0
votes
0answers
44 views

Reshape2 dcast with multiple columns in R

I am trying to use the dcast function in R on a dataframe but I see something is weird in my output. x <- dcast(DT,COUNTRY + DESCRIPTION ~ DATE + MACRO_ECONOMIC_FACTOR_VALUE) Output- Instead of ...
0
votes
1answer
51 views

R long to wide format factor levels as binary variables and dates

I want to make a long to a wide format and use the factor Levels as binary variables. This means, if the factor Level is existing at least once, then there should be a 1 in the variable. Otherwise a 0....
2
votes
1answer
54 views

dcast not retaining variable type as character, error in vapply when a variable is NA

In attempting to reshape data using resphape2::dcast, I am encountering an error involving NA entries. Sample data are at the end. The data are reshaped from long to wide, but on occasion some ...
0
votes
3answers
57 views

Prevent dcast from aggregating data

I have data like: rating title 5 Bean 5 Bean 4 Bean 5 Bean 5 Egg 4 Egg 3 Bacon 2 Bacon And I want to ...
1
vote
1answer
51 views

ggplot2: can geom_point work in melted dataframes?

I am kind of beginner in ggplot2. I have this dataframe: df <- data.frame(testno = 1:4, y1 = c(1.2,3.1,4.6,6.7), y2 = c(5,3.2,9.6,8.8)) df$testno <- factor(df$testno) from which I can easily ...
1
vote
1answer
24 views

Monthly Dummy Variables in dataset

I have a dataset with 10 columns. One of those columns is the date. I want to create dummy variables for every month. How do I go about doing this? Date Col1 Col2 2017-01-09 v ...
0
votes
1answer
92 views

R Conditionally transform data frame from long to wide based on multiple unique variables

I know this is a very common post on SO but I have been spending a little too much time researching a way to transform a data frame from long form to wide form and haven't quite found a post(s) to ...
0
votes
1answer
17 views

aggregating data during convert vertical data into horizontal data( like R's dcast function)

Input: x y z a b wkn year S1 S2 A 1 6 121 1066 18 2015 10 5 A 1 6 121 1066 18 2015 20 6 A 1 6 121 1066 19 2015 5 3 Expected ...
2
votes
1answer
214 views

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"....)...
1
vote
1answer
41 views

melt data.frame in r and store unused columns in a column (separated by commata) [duplicate]

old problem, for new one see below I have a data.frame df<-data.frame("name" = c("A","A","B","C"), "class" = c("ab","cd","cd","ef"), "type" = c("alpha","beta","...
0
votes
0answers
44 views

R: dcast inside a function does not find passed variable

I have the following data.frame: > mydata <- data.frame(gene=rep(paste(sample(LETTERS, 10, replace=TRUE), sample(1:1000, 10, replace=FALSE), sep=''), each=5), + clus=rep(...
1
vote
3answers
91 views

dcast fails to cast character column when the data size is large

I'm using the dcast function in the library(reshape2) package to cast a simple table of three columns df = data.table(id = 1:1e6, var = c('continent','subcontinent',...), ...
-2
votes
1answer
54 views

Undefined columns selected, how to solve?

When I try to run the following code I get an error: value <- as.matrix(wsu.wide[, c(4, 3, 2)]) Error in [.data.frame(wsu.wide, , c(4, 3, 2)) : undefined columns selected How do I get ...
1
vote
2answers
115 views

Order columns in dcast

How do I specify the column order, based on column 'Col' when using dcast? df <- dcast(x, ID ~ ColumnName, value.var = "Answer") I need the solution to be non specific to the data as x can be the ...
0
votes
3answers
341 views

R Pivot table with columns converted to only rows

I basically do reporting on marketing data and am trying work on some automation in R. In excel we can drag and select columns into the "Rows" area of a pivot table to summarise the data. I have a ...
2
votes
1answer
82 views

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 ...
2
votes
2answers
155 views

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 ...
1
vote
2answers
48 views

Moving data long to wide with dcast

I've been on Stack Overflow for the past few days trying to get a solution to this issue I'm having. I'm analyzing data received from the National Student Clearinghouse, specifically the graduations....
0
votes
0answers
45 views

rounding all entries in a dcast data.frame using mutate_at only rounds some of the observations as expected

I have 3835 observations: tramp[sample(nrow(tramp), 40), ] A B C 2313 Polyodon spathula Aci_CR_R02 0 3544 Scaphirhynchus ...
0
votes
0answers
29 views

What does split_indices works for?

what does Error in split_indices(.group, .n) : n must be a positive integer In addition: Warning message: In split_indices(.group, .n) : NAs introduced by coercion to integer range means? This ...
0
votes
0answers
18 views

How do I loop through a dcast function where i loop through the variables [duplicate]

I am trying to loop using the following code: tax.class <- c("Phylum", "Order", "Class", "Family", "Genus") for (k in 1:length(tax.class) { phy2 <- tax_glom(phy, taxrank = tax.class[k]) ...
0
votes
1answer
112 views

Reshape2: dcast() returning - ‘sum’ not meaningful for factors

dataset: I will call it CAR Car_Type | Cyl | Miles | State | Color | Tires ..... My data can have NULL for Miles I'm trying to run dcast() on a data set that shows all variables as numeric. sapply(...
1
vote
1answer
47 views

Reshape data in R using dcast

I have the following data library(reshape2) d <- data_frame( Quart = c("Q1", "Q2", "Q3", "Q4", "Q4", "Q1","Q4","Q1", "Q2", "Q3"), var1 = c(1,0,1,1,1,0,2,3,0,1), ...
1
vote
1answer
31 views

How to do a plotly graph after a dcast table?

I have a database including day and places, with other relevant information. I am currently using the dcast function in order to count each occurence in a day and place (that in the real database are ...
0
votes
0answers
31 views

dcast to change long data to wide data + replacing values

My data is set up like this: PUBLISH_DATE SORT_ORDER Problems 12/01/11 1 Persistent Slabs 12/01/11 2 Wind Slabs 12/02/11 1 Storm Slabs ...
0
votes
1answer
28 views

Dcast Function -> Reorder Columns

I used the dcast function to show the spendings per month of different companies. Of course I want January first, then February etc. and not the alphabetical order. Spendings <- data %>% ...
2
votes
1answer
623 views

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 ...
0
votes
1answer
107 views

Using an multiple input from Shiny in Reshape2 dcast()

Taking reference from Using an input from Shiny Widget in Reshape Cast(), I am able to create dynamic summary table by Shiny input with single row variable. However, when I wish to create multiple ...