similar to: Help ave() function

Displaying 20 results from an estimated 40000 matches similar to: "Help ave() function"

2017 Jun 14
1
spurious warning in ave()
Consider the following simple data set and a call to ave: > tdata <- data.frame(f1=c(1,1,1,1,2,2,2,2), f2=c(1,2,1,2,1,1,1,1), y=1:8) > with(tdata, table(f1, f2)) f2 f1 1 2 1 2 2 2 4 0 > with(tdata, ave(y, f1, f2, FUN=max)) [1] 3 4 3 4 8 8 8 8 Warning message: In FUN(X[[i]], ...) : no non-missing arguments to max; returning -Inf There are no missing values in the
2009 Apr 19
1
ave returns wrong data type (PR#13664)
Full_Name: Brendan Barnwell Version: 2.9.0 OS: Windows XP Pro Submission from: (NULL) (71.102.131.29) The ave() function returns an incorrect datatype. Specifically, ave(x, g, f) always returns a vector with the same mode as x, rather than using the mode of the vector returned by f. Observe: > x [1] "A" "B" "C" "A" "B" "C"
2010 Jun 29
1
Performance enhancement for ave
library(plyr) n<-100000 grp1<-sample(1:750, n, replace=T) grp2<-sample(1:750, n, replace=T) d<-data.frame(x=rnorm(n), y=rnorm(n), grp1=grp1, grp2=grp2) system.time({ d$avx1 <- ave(d$x, list(d$grp1, d$grp2)) d$avy1 <- ave(d$y, list(d$grp1, d$grp2)) }) # user system elapsed # 39.300 0.279 40.809 system.time({ d$avx2 <- ave(d$x, interaction(d$grp1, d$grp2, drop =
2010 Aug 20
2
Problem with POSIXct in ave
Hi, I am having trouble using the ave function with a POSIXct object. For example: x<-Sys.time()+0:9*3600 dat<-data.frame(id=rep(c('a',' b','c'),each=10),dt=rep(x,3),i=rep(1:10,3)) dat # This is what I want to do: dat$time.elapsed<-unsplit(lapply(split(dat$dt,dat$id),function(x) x-x[1]),f=dat$id) dat # The above code does the trick, but from the standpoint of
2009 Feb 15
2
Fast ave for sorted data?
Hi, This is probably really obvious, by I can't seem to find anything on it. Is there a fast version of ave for when the data is already sorted in terms of the factor, or if the breaks are already known? Basically, I have: X = 0.1, 0.2, 0.32, 0.32, 0.4, 0.56, 0.56, 0.7... Y = 223, 434, 343, 544, 231.... etc of the same, admittedly large length. Now note that some of the values of X are
2009 Mar 02
2
ave and grouping
Dear list, # I have a DF like this: sleep$b <- c(rep(8,10), rep(9,10)) sleep$me <- with(sleep, ave(extra, group, FUN = mean)) sleep # I would like to create a new variable # holding the b-th value of group 1 and 2. # This is not what I want, it takes always the '8' from group '1' # and not the '9' sleep$gr <- with(sleep, ave(extra, group, FUN = function(x)
2012 Dec 24
2
parallelized version of "by" and "ave"
Dear R experts--- Has anyone written parallel versions of "by" (i.e., mcby) and "ave" (i.e. mcave) ? I did ask a question like this a year ago, and then the answer was no. for those who are googling the group for the answer to this question, in the meantime, the poor man's version of "by" is mclapply( split( ds, factor ), FUN ) I don't know the poor
2007 Nov 21
1
ave and sd
Dear list, I'm still trying to calculate the sd for V2 for each group in V1 if V3 is '0': > x V1 V2 V3 1 A01 2.40 0 2 A01 3.40 1 3 A01 2.80 0 4 A02 3.20 0 5 A02 4.20 0 6 A03 2.98 1 7 A03 2.31 0 8 A04 4.20 0 # Work x$vmean <- ave(x$V2, x$V1, x$V3 == 0, FUN = mean) # Work x$vsd2 <- ave(x$V2, x$V1, FUN = sd) # Doesn't work x$vsd <- ave(x$V2, x$V1, x$V3
2004 Oct 22
1
ave gives unexpected NA's
[R 2.0.0 on Linux] I tried: > df <- data.frame( grp1=factor( c('A' ,'A' ,'A' ,'D', 'D' ) ) , grp2=factor( c('a1','a2','a2','d1','d1') ) ) > df grp1 grp2 val 1 A a1 1 2 A a2 2 3 A a2 4 4 D d1 8 5 D d1 16 I got: > with( df, ave( val, grp1, grp2, FUN=sum ) )
2003 Sep 27
2
frustration with ave()
Dear All, I'm confused why I'm getting NA's in the output from ave() (at the end). Any help would be greatly appreciated. I'm including the data in case that is where the problem lies: > f <- factor(FAMILYID) > bodyfat <- na.omit(data.frame(loessBODYFAT, f)) > bodyfat$loessBODYFAT [1] -8.950153e-01 -9.175285e-01 3.174061e-01 -2.101260e-01 2.534174e-02
2007 Nov 29
2
How to take the ave of two rows in a data frame
> Dear list, > I have a data frame like: > > > log2.ratios[1:3,1:4] > ID a1 a2 a3 > 1 GS1-232B23 -0.0207500 0.17553833 0.21939333 > 2 RP11-82D16 -0.1896667 0.02645167 -0.03112333 > 3 RP11-62M23 -0.1761700 0.08214500 -0.04877000 > 4 RP11-62M23 0.2761700 -0.15214500 -0.05877000 > the 3rd and
2009 Apr 23
2
conditional grouping of variables: ave or tapply or by or???
Dear R Users, I have the following data frame: v1 <- c(rep(10,3),rep(11,2)) v2 <- sample(5:10, 5, replace = T) v3 <- c(0,1,2,0,2) df <- data.frame(v1,v2,v3) > df v1 v2 v3 1 10 9 0 2 10 5 1 3 10 6 2 4 11 7 0 5 11 5 2 I want to add a new column v4 such that its values are equal to the value of v2 conditional on v3=0 for each subgroup of v1. In the above example, the
2010 Nov 30
1
more flexible "ave"
Hi all, I would like to calculate the percent of the total per group for this data.frame: df <- data.frame(site = c("a", "a", "a", "b", "b", "b"), gr = c("total", "x1", "x2", "x1", "total","x2"), value1 = c(212, 56, 87, 33, 456, 213)) df
2011 Jul 08
2
manipulating "by" lists and "ave()" functions
dear R wizards---more ignorance on my part, exacerbated by too few examples in the function documentations. > d <- data.frame( id=rep(1:3,3), x=rnorm(9), y=rnorm(9)) Question 1: how do I work with the output of "by"? for example, > b <- by( d, d$id, function(x) coef(lm( y ~ x, data=x ) )) > b d$id: 1 (Intercept) x 0.2303 0.3618
2011 Oct 26
1
Calculate the difference using ave
Dear R users, It may be very simple but it is being difficult for me. I'd like to calculate the difference in percent between to measures. My data looks like this: set.seed(123) df1 <- data.frame(measure = rep(c("A1", "A2", "A3"), each=3), water = sample(c(100:200), 9), tide = sample(c(-10:+10), 9)) df1 # What I want to calculate is:
2020 Jun 21
4
Inclusive language in LLVM: can we rename `job` in source code?
<div>Here we've began discussion about "master"</div><div><a href="https://lists.llvm.org/pipermail/llvm-dev/2020-June/142448.html">https://lists.llvm.org/pipermail/llvm-dev/2020-June/142448.html</a></div><div> </div><div>Lets remove Job word completely</div><div><pre>But as one can easily fact-check,
2007 Nov 16
0
Odp: R: ave and quantile
Hi Patrick Hausmann <c18g at uni-bremen.de> napsal dne 15.11.2007 18:59:06: > Hello Petr, > > one question solved, the next is standing in front of me... If you > have a minute to look .... great! > > > x > V1 V2 F1 > 1 A 2 0.1552277 > 2 A 3 0.1552277 > 3 A 4 0.1552277 > 4 B 3 0.8447723 > 5 B 2 0.8447723 > 6 C 6 0.2500000
2009 Apr 15
0
ave returns wrong type
I've been using the ave function to compute some statistics on a data frame. After a while I noticed that, for some reason, it was returning numerical statistics as strings instead of numbers. I delved into the code of the functions and traced the problem to the following fact: ave uses split<- to do its work. Specifically, it does "split(x, g) <- lapply(split(x, g),
2004 Apr 19
0
looking for something like "ave" I can pass non numeric to
Hi, I have been trying to calculate summary error and coding statistics on a by subject basis and seem to be writing a lot of code to do a simple thing. I won't go into my messy version. What I am asking is if anyone knows of a single command that could take the following data and get error rates over a given vector. Given data from ss with,,, subj a rt code 1 1 200 good 1 1 321 good
2007 May 08
0
The match of "ave()" for "FUN=SD"
Hello, I have many subsets of x. I want to get the standard deviation for each subset with the same factor levels. For "FUN=mean" and "FUN=median" I am using "ave()". Can anybody tell me the match of "ave()" for using "FUN=SD"? At the beginning I used aggregate(), also for mean and median. But aggregegate make ""arithmetical