search for: dcast

Displaying 20 results from an estimated 145 matches for "dcast".

Did you mean: cast
2012 Apr 12
1
Using dcast with multiple functions to aggregate
Dear R communitiy, I am trying to use multiple functions for aggregation within a function call for dcast. However this seems to result in an error. Also I have not managed to make dcast() work with fun.aggregate=sd. Please find attached some example code using the ChickWeight data. Many thanks for your help! Jokel #Chick weight example names(ChickWeight) <- tolower(names(ChickWeight)) sd(Chic...
2011 Oct 31
1
reshape2: Lost Values Between melt() and dcast()
Working with 5 subset streams from my source data frame, three of them successfully call dcast(), but two fail: jerritt.cast <- dcast(jerritt.melt, site + sampdate ~ param) Aggregation function missing: defaulting to length and winters.cast <- dcast(winters.melt, site + sampdate ~ param) Aggregation function missing: defaulting to length Yet both data frames have the values in t...
2012 Aug 07
3
reshape2's dcast() Adds NAs to Data Frame
I need to understand how and why dcast() adds NAs to a data frame that contained no missing values. The database table of chemical concentrations has all missing values removed because they cannot contribute to data analyses. The structure of the R data frame of these data have no NA values, and neither does the data frame resulting...
2012 Dec 03
2
Excluding all missing values with dcast ("reshape2" package)
Hello--I'm doing a simple crosstab using dcast: rawfreq <- dcast(nh11brfs, race3~CHCCOPD, length) with the results race3 Yes No NA 1 White non-Hispanic 446 5473 21 2 Other non-Hispanic 29 211 0 3 Hispanic 6 81 1 4 <NA> 10 83 1 How would I modify this call to exclude all missing v...
2016 Feb 11
2
Invertir dcast
Hola a todos, Queria preguntaros si conoceis alguna manera para invertir la funcion dcast. Quiero transformar una matriz en un data frame de tres columnas que indiquen solo los casos donde la combinacion fila-columna sea diferente de NA. Se me habia ocurrido hacer un bucle que fuera seleccionando todos los valores para cada combinacion de fila y columna, pero el problema es que con una...
2012 Oct 17
1
Comparing dcast and reshape
I'm in the middle of my own little intellectual exercise comparing dcast() and reshape() and have successfully stumped myself. I want to melt() a data frame, then dcast() it into a new form. After doing so, I want to duplicate the process using reshape(). So far, I can do the melt and cast require(reshape2) Raw <- data.frame(site = c(1, 1, 1, 1, 2, 2, 2, 2),...
2013 Jan 22
4
Simple use of dcast (reshape2 package)
...1 2 52 TPP 3 3 53 TPP 1 4 54 TPP 2 5 50.1 GPA 9 1 51.1 GPA 11 2 52.1 GPA 8 3 53.1 GPA 8 4 54.1 GPA 10 5 And I want to reshape it into ID TPP GPA 1 1 0 9 2 2 1 11 3 3 3 8 4 4 1 8 5 5 2 10 I realise that dcast function in the reshape2 package can handle much more complicated tasks than that, but I can't make it do a simple one. If I simply tried > dcast(aa, ... ~ Target) Using ID as value column: use value.var to override. Aggregation function missing: defaulting to length Eaten GPA TPP 1...
2013 Jun 26
1
Error when using median as aggregation function in dcast
Hi, I am trying to calculated various summary statistics using the dcast function of reshape2. This works perfectly for getting the mean, sum, length, sd. But when I want to calculate the median I get an error. I tried it with and without removing NAs: my_median <- function(x) median(x, na.rm = FALSE) median_df <- dcast(patch_stats_dfm,formula=species~input+barri...
2016 Feb 11
4
Invertir dcast
...8 > Un saludo. Olivier ----- Mensaje original ----- De: "Javier Marcuzzi" <javier.ruben.marcuzzi en gmail.com> Para: "Ruben Bermad" <ruben_bm en hotmail.com>, r-help-es en r-project.org Enviados: Jueves, 11 de Febrero 2016 12:45:02 Asunto: Re: [R-es] Invertir dcast Estimado Ruben Bernard ¿Usted desea algo como sparce matrix? Javier Rubén Marcuzzi De: Ruben Bermad Enviado: jueves, 11 de febrero de 2016 9:40 Para: r-help-es en r-project.org Asunto: [R-es] Invertir dcast Hola a todos, Queria preguntaros si conoceis alguna manera para invertir la funcion dc...
2011 Dec 12
0
using dcast to reshape a DF from long to wide with multiple measured variables per obs
..."fillno2_v3", "fillno3_v2", "fillno3_v3", "fillno4_v2", "fillno4_v3", "fillno5_v2", "fillno5_v3", "fillno6_v2", "fillno6_v3"), class = "data.frame", row.names = c(NA, -3L))   I have tried melt and dcast, but can only get reshape to organize by one measured variable at a time (and not two, as I would like).   For example, the following organizes my data by fill-number and v2:   dcast(DF, person ~ fillno, value.var=c("v2"))   likewise the following works for v3   dcast(DF, person ~ fillno,...
2012 Jul 24
3
Simple reshape problem I am completely missing
...hat? I have a simple three column data.frame that I would like to reshape to wide preferably using reshape2. An example from http://stackoverflow.com/questions/9617348/reshape-three-column-data-frame-to-matrix looked perfect except I wanted a data frame but it seemed okay. I just changed acast to dcast and it seems fine. Stackoverflow example: tmp <- data.frame(x=gl(2,3, labels=letters[24:25]), y=gl(3,1,6, labels=letters[1:3]), z=c(1,2,3,3,3,2)) dd <- dcast(tmp, x~y, value.var="z") My Example: Does NOT work md2 <- structure(list(group...
2012 Mar 19
0
Reshape data frame with dcast and melt
...collapse="+"))) data_long <- sort(data_long, f = formula_sort) return(data_long) } reshape_wide <- function(data, ids) { # Bring data into wide form formula_wide <- as.formula(paste(paste(ids, collapse="+"), "~ Data_Points")) data_wide <- dcast(data, formula_wide) # Resort data formula_sort <- as.formula(paste("~", paste(ids, collapse="+"))) data_wide <- sort(data_wide, f = formula_sort) return(data_wide) } d <- data.frame( test_name = c(rep("Test_A", 6), rep("Test_B",...
2013 Jun 26
1
Margins in dcast (reshape2)
Hi, I'd like to get mean values for the margins of my casted data.frame. For the casting I am using dcast() from reshape2. However, when I set the margins parameter (margins=c("grand\_row")) I get following error concerning an unrecognized escape character '\_'. So what is the correct command to get the outermost margins only in reshape2? /johannes [[alternative HTML version delete...
2011 Sep 28
3
Data transformation & cleaning
...ID | Page 123 | Choice A 123 | Choice B 456 | Choice A 456 | Choice B ... I thought that I should do the following 1. Make the data set "wide", counting the observations so the data looks like this: ID | Count of Preference A | Count of Preference B 123 | 1 | 1 ... Using table1 <- dcast(data,ID ~ Page,fun.aggregate=length,value_var='Page' ) 2. Create a correlation matrix of preferences cor(table2[,-1]) How would I restrict my correlation to show preferences that met a minimum sample threshold? Can you confirm if the two following commands do the same thing? What would I...
2012 Jul 05
1
reshape2 errors on data frame
I've successfully reformatted data frames from long to wide with reshape2, but this time I'm getting errors that I want to understand and resolve. Here's the data frame structure and the results of the melt() and dcast() functions: str(waterchem) 'data.frame': 128412 obs. of 8 variables: $ site : Factor w/ 64 levels "D-1","D-2","D-3",..: 1 1 1 1 1 1 1 ... $ sampdate: Date, format: "2007-12-12" "2007-12-12" ... $ preeq0 : logi TRUE TRUE TRUE TR...
2011 Sep 09
4
reshape data from long to wide format
...uot;1", "2", "3", "4", "5", "6")) I need to resahpe "example" in a wide format so that ?SENSOR? appear as columns and ?DATE? as rows with corresponding ?VALUE? as value; I thought it was very simple so that I?ve been trying this: dcast(example,DATE~SENSOR) But I've got this message: Using DATE as value column. Use the value argument to cast to override this choice Errore in `[.data.frame`(data, , variables, drop = FALSE) : undefined columns selected and even if by using the value argument sorted out any good result? s...
2016 Sep 03
2
Pivot tables con data.table
Muchas gracias, pensaba hacerlo en una sola línea pero no anda. Me quedo con dcast así no tengo que cargar más paquetes. Un abrazo! Fernando Macedo El 03/09/16 a las 14:26, Carlos J. Gil Bellosta escribió: > reshape2 + dcast > > El día 3 de septiembre de 2016, 19:23, Fernando Macedo > <fermace en gmail.com> escribió: >> Buenas, estoy intentando hacer un...
2012 Jul 25
2
reshape -> reshape 2: function cast changed?
...1) Melt a dataframe based on a vector specifying column names as measure.vars. Thats working so far: dfm <- melt(df, measure.vars=n, variable_name = "species", na.rm = FALSE) 2) Recast the dataframe: dfc <- cast(dfm, Var1 + Var2 + Var3 + Var4 ~ species,max) # with reshape dfc <- dcast(dfm, Var1 + Var2 + Var3 + Var4 ~ species,max) # with reshape2 but then I get (this is new to reshape2!) a warning message: In .fun(.value[0], ...) : no non-missing arguments to max; returning -Inf The result seems to be similar (but I haven't checked it yet properly)? A message to ignore? I...
2018 Feb 25
4
reshaping column items into rows per unique ID
...ID DietType DietType DietType 1 a c b 2 f a 3 j 4 c c f I tried many times using melt(),spread (),and dcast () functions but was not able to produce the desired table. The best attempt was by typing : # 1) Adding new column with unique values: MyDf $newcol <- c (1:9) #2) then : NewDf <- dcast (MyDf,CustomerID~newcol,value.var=DietType) This produces the desired table but with many NA values like...
2012 Nov 17
3
Reshaping a dataframe
Seems like this should be easy but I'm struggling a bit. How do I rearrange a data frame to go from the first one to the second shown below ? State Date lbs TX 200701 400 TX 200702 650 TX 200703 950 TX 200704 1000 FL 200701 200 FL 200702 300 FL 200703 500 FL 200704 333 NJ 200701 409 NJ 200702 308 NJ 200703 300 NJ 200704 800 Date TX FL NJ 200701 400 200 409 200702 650