similar to: mean-aggregate – but use unique for factor variables

Displaying 20 results from an estimated 20000 matches similar to: "mean-aggregate – but use unique for factor variables"

2013 Dec 13
1
data point labeling in xyplot
Hi Folks, I have data with a format like: ID y param1 param2 groupingFactor1 groupingFactor2..... 1 ... 1 1 1 2 2 2 2 3 3 3 so several grouping factors and repeated measures. I am using trellis and xyplot to get plot with several grouping factors. something like xyplot(y~x|grouping1*grouping2, data=na.omit(mydata), panel=function{panel.xyplot(x,y);....}); Lets say x is the
2013 Jan 11
3
aggregate data.frame based on column class
Hi, When using the aggregate function to aggregate a data.frame by one or more grouping variables I often have the problem, that I want the mean for some numeric variables but the unique value for factor variables. So for example in this data-frame: data <- data.frame(x = rnorm(10,1,2), group = c(rep(1,5), rep(2,5)), gender =c(rep('m',5), rep('f',5))) aggregate(data,
2002 Aug 24
1
nlme
In the non linear mixed effects package a groupedData object can be created to facilitate modeling. The gD object includes a formula of the form 'response variable' ~ 'primary covariate' | 'grouping factor'. In experiments creating response surfaces there are 2 or more primary covariates. Is there any way to use the groupedData() function to include 2 primary
2012 Dec 25
5
aggregate / collapse big data frame efficiently
Hi, I need to aggregate rows of a data.frame by computing the mean for rows with the same factor-level on one factor-variable; here is the sample code: x <- data.frame(rep(letters,2), rnorm(52), rnorm(52), rnorm(52)) aggregate(x, list(x[,1]), mean) Now my problem is, that the actual data-set is much bigger (120 rows and approximately 100.000 columns) ? and it takes very very long
2011 Oct 11
2
replicate data.frame n times
Hi, is there a way to replicate a data.frame like you can replicate the entries of a vector (with the repeat-function)? I want to do this: x <- data.frame(x, x) (where x is a data.frame). but n times. And it should be as cpu / memory efficient as possible, since n is pretty big in my case. thanks for any suggestions!
2012 Jan 29
2
apply lm() to each row of a matrix
Hi, I would like to fit lm-models to a matrix with 'samples' of a dependent variable (each row represents one sample of the dependent variable). The independent variable is a vector that stays the same: y <- c(1:10) x <- matrix(rnorm(5*10,0,1), 5, 10) now I would like to avoid looping over the rows, since my original matrix is much larger; for(t in 1:dim(x)[1]) {
2011 Jul 11
2
best way to aggregate / rearrange data.frame with different data types
Hi, I have a data.frame that looks like this: Subject <- c(rep(1,4), rep(2,4), rep(3,4)) y <- rnorm(12, 3, 2) gender <- c(rep("w",4), rep("m",4), rep("w",4)) comment <- c(rep("comment A",4), rep("comment B",4), rep("comment C",4)) data <- data.frame(Subject,y,gender,comment) data Subject y gender
2013 Mar 11
2
aggregate(), tapply(): Why is the order of the grouping variables not kept?
Dear expeRts, The question is rather simple: Why does aggregate (or similarly tapply()) not keep the order of the grouping variable(s)? Here is an example: x <- data.frame(group = rep(LETTERS[1:2], each=10), year = rep(rep(2001:2005, each=2), 2), value = rep(1:10, each=2)) ## => sorted according to group, then year aggregate(value ~ group + year, data=x,
2011 Dec 04
1
Complex multiple t tests in a data frame with several id factors
I have assayed the concentrations of various metal elements in different anatomic regions of two strains of mice. Now, for each element, in each region, I want to do a t test to find whether there is any difference between the two strains. Here is what I did (using simulated data as an example): # create the data frame > elemconc = data.frame(expand.grid(id=1:3, geno=c('exp',
2007 Sep 27
3
Aggregate factor names
Hi all, A suggestion derived from discussions amongst a number of R users in my research group: set the default column names produced by aggregate () equal to the names of the objects in the list passed to the 'by' object. ex. it is annoying to type with( my.data ,aggregate( my.dv ,list( one.iv = one.iv ,another.iv = another.iv ,yet.another.iv = yet.another.iv )
2010 Jan 30
2
aggregate by factor
I have a data frame with two columns, a factor and a numeric. I want to create data frame with the factor, its frequency and the median of the numeric column > head(motifList) events score 1 aeijm -0.25000000 2 begjm -0.25000000 3 afgjm -0.25000000 4 afhjm -0.25000000 5 aeijm -0.25000000 6 aehjm 0.08333333 To get the frequency table of events: > motifTable <-
2011 Jan 04
1
how to subset unique factor combinations from a data frame.
Hi All I have these questions and request members expert view on this. a) I have a dataframe (df) with five factors (identity variables) and value (measured value). The id variables are Year, Country, Commodity, Attribute, Unit. Value is a value for each combination of this. I would like to get just the unique combination of Commodity, Attribute and Unit. I just need the unique factor
2006 Oct 05
1
Aggregate Values for All Levels of a Factor
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello, I'm a novice user trying to figure out how to retain NA aggregate values. For example, given a data frame with data for 3 of the 4 possible factor colors("orange" is omitted from the data frame), I want to calculate the average height by color, but I'd like to retain the knowledge that "orange" is a possible factor,
2011 Oct 05
2
mean of 3D arrays
Hi, I have multiple three dimensional arrays. Like this: x1 <- array(rnorm(1000, 1, 2), dim=c(10, 10, 10)) x2 <- array(rnorm(1000, 1, 2), dim=c(10, 10, 10)) x3 <- array(rnorm(1000, 1, 2), dim=c(10, 10, 10)) Now I would like to compute the mean for each corresponding cell. As a result I want to get one 3D array (10 x 10 x 10) in which at position x, y, z is the mean of the
2007 Dec 16
2
question about the aggregate function with respect to order of levels of grouping elements
Hi, I am using aggregate() to add up groups of data according to year and month. It seems that the function aggregate() automatically sorts the levels of factors of the grouping elements, even if the order of the levels of factors is supplied. I am wondering if this is a bug, or if I missed something important. Below is an example that shows what I mean. Does anyone know if this is just the way
2006 Nov 15
2
Newbie: how to get unique x unique x aggregate chart?
I'm very new to R, so please forgive me if I just missed the answer in existing documentation... I have a data set with at least three columns, X, Y, and Z. I want to produce a chart where one axis shows all the unique values of X, and the other axis shows all the unique values of Y. Each cell within the chart should contain the result of applying an aggregate function (such as mean(), for
2006 Oct 01
3
aggregate function with 'NA'
Dear r-help reader, I have some problems with the aggregate function. My datframe looks like >frame Day Time V1 V2 1 M 0 3 NA 2 M 0 4 NA 3 M 0 5 2 4 M 1 NA 4 5 M 1 10 6 6 T 0 4 45 7 T 1 4 3 8 T 1 3 2 9 T 1 6 1 I used the aggegate function to obtain the mean in V1 and V2 over the grouping variable Time and Day
2008 Oct 01
1
Aggregate issues with subset
Hello, I used the aggregate function with success on my data frame "all". > aggregate(all, list(sc_recov), mean) I then made a subset of this data frame: >s.all <-subset(all, select= c(3,4,5,6,7,8,9,10,11,23)) but when I tried to to run the aggregate function on this subset: > aggregate(s.all, list(sc_recov), mean) The result is garbage (i.e. its not grouping the data).
2007 Sep 07
1
aggregate factor
Hi, I am using aggregate to compute means for later plotting. There are two factors involved and the problem is that the values of the second factor ( Age ) in the means are not in the right order because "10" comes inbetween "1" and "2" What I really want is the numeric value of Age but as.numeric and as.integer returns the level value instead. Is there a way to
2017 Dec 30
0
10 Minute Time Window Aggregate By Multiple Grouping Variables
Hello All, I have 1M rows of time stamped information about delivery trucks and their trip related information from simulation .Detailed info the column names and attributes for clarity 1. id: alphanumeric factor/character 2. datetime.of.trip.start: POSIXct yyyy-mm-dd hh:mm:ss 3. datetime.of.trip.end: POSIXct yyyy-mm-dd hh:mm:ss 4. trip.distance: numeric, miles 5.