similar to: Using dcast with multiple functions to aggregate

Displaying 20 results from an estimated 700 matches similar to: "Using dcast with multiple functions to aggregate"

2008 Jul 30
1
bug in 'margins' behavior in reshape - cast
according to the documentation of the cast function in the reshape function, I would expect this bit of code from the examples to calculate marginal means over only the 'diet' variable. #Chick weight example names(ChickWeight) <- tolower(names(ChickWeight)) chick_m <- melt(ChickWeight, id=2:4, na.rm=TRUE) cast(chick_m, diet + chick ~ time, mean, margins="diet") But,
2009 Jul 06
2
ReShape chicks example - line plots
Hi, In the examples from the ReShape package there is a simple example of using melt followed by cast that produces a smallish amount of output about the chicks database. Here's the code: library(reshape) names(ChickWeight) <- tolower(names(ChickWeight)) chick_m <- melt(ChickWeight, id=2:4, na.rm=TRUE) DietResults <- cast(chick_m, diet + chick ~ time) DietResults My challenge
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 their
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), id =
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 values; that is, to obtain race3
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 from applying the reshape2 melt() function to it. However,
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+barriers,my_median) Error in
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 matriz de
2015 Apr 30
2
predict nlme
Estimado Oliver Nuñez Envío un ejemplo reproducible. Javier Marcuzzi # de donde tomo datos, y tiene el modelo (en el pdf) library(MCMCglmm) # librería con las funciónes que voy a usar library(nlme) datos0<-ChickWeight # creo algunos datos que agrego a los origonales Factor<-as.numeric(datos0$Chick) Factor[Factor > 0 & Factor <= 10] <- 'A' Factor[Factor > 10
2010 Oct 01
2
Format of Output of Residuals
An excerpt from dataset ChickWeight: ??? weight Time Chick Diet 1?????? 42??? 0???? 1??? 1 2?????? 51??? 2???? 1??? 1 3?????? 59??? 4???? 1??? 1 I am interested in the residuals of the dataset.? Specifically in saving them to another format. I have been creating text files with sink. CW.lm <- lm(weight ~ Diet, ChickWeight) resid.CW.lm <- resid(CW.lm) But when I call: resid.CW.lm The data
2013 Jan 22
4
Simple use of dcast (reshape2 package)
Suppose I have a small dataframe > aa Target Eaten ID 50 TPP 0 1 51 TPP 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
2009 Nov 14
4
Weighted descriptives by levels of another variables
I've noticed that R has a number of very useful functions for obtaining descriptive statistics on groups of variables, including summary {stats}, describe {Hmisc}, and describe {psych}, but none that I have found is able to provided weighted descriptives of subsets of a data set (ex. descriptives for both males and females for age, where accurate results require use of sampling
2011 Dec 12
0
using dcast to reshape a DF from long to wide with multiple measured variables per obs
I have data in the following format:   person<- c(1,1,1,1,2,2,2,2,2,3,3,3,3,3,3) v2<- c("2011-01-01", "2011-02-01", "2011-03-01", "2011-04-01", "2011-01-01", "2011-02-01", "2011-03-01", "2011-04-01", "2011-05-01", "2011-01-01", "2011-02-01", "2011-03-01",
2016 Feb 11
4
Invertir dcast
Con data.table todo puede ir muy rapido. > require(data.table) > M=matrix(c(5,NA,NA,NA,6,NA,7,NA,8),3,3) > M [,1] [,2] [,3] [1,] 5 NA 7 [2,] NA 6 NA [3,] NA NA 8 > M2=data.table(M) > M2 V1 V2 V3 1: 5 NA 7 2: NA 6 NA 3: NA NA 8 > M3=melt(M2,variable.name = "columna") > M3 columna value 1: V1 5 2: V1 NA 3: V1
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
2012 Mar 19
0
Reshape data frame with dcast and melt
Hello, I implemented two functions reshape_long and reshape_wide (see full working example below) to reshape data frames. I created several small examples and the two functions seemed to work properly. However, using the reshape_wide function on my real data sets (about 200.000 to 300.000 rows) failed. What happens is set all values for X, Y and Z were set to 1. The structure of my real data
2010 Aug 12
2
Linear regression on several groups
I have a simple dataset of a numerical dependent Y, a numerical independent X and a categorial variable Z with three levels. I want to do linear regression Y~X for each level of Z. How can I do this in a single command that is without using lm() applied three isolated times? -- View this message in context: http://r.789695.n4.nabble.com/Linear-regression-on-several-groups-tp2322835p2322835.html
2011 Jul 18
1
Extract confidence intervals from rma object (metafor package)
Dear R-experts! I am working on some meta-analysis using the metafor package. I would like to extract values of the confidence intervals of the effect sizes of the single studies from an rma object. Those values are printed out when plotting a forest plot using the forest function on the rma object, however I was not able to locate them. Many thanks for your help! Jokel [[alternative HTML
2010 Aug 25
1
Estimate average standard deviation of mean of two dependent groups
Dear R-experts! I am currently running a meta-analysis with the help of the great metafor package. However I have some difficulties setting up my raw data to enter it to the meta-analysis models. I have a group of subjects that have been measured in two continuous variables (A & B). I have the information about the mean of the two variables, the group size (n) and the standard deviations of
2012 Jun 24
2
Power calculation using pwr.t.test()
Dear R experts, I have conducted a power calculation in order to estimate the number of subjects needed to detect an effect size of d=0.28 (cohen's d) for a difference between two independent groups (alpha level should be 0.05 and the effect should be detected with 80% probability). The results from the code below indicates that I would need n=400 subjects (200 in each group). This is seems