similar to: ave returns wrong data type (PR#13664)

Displaying 20 results from an estimated 20000 matches similar to: "ave returns wrong data type (PR#13664)"

2010 May 02
2
Retrieve regular expression groups
I'm trying to figure out how to get the text captured by capturing groups out of a regex match. For instance, let's say I have the pattern "foo ([^ ]+)" and I match it against the string "This is a foo sentence I am reading." The group in the pattern will match the word "sentence" in the target string. How can I get access to this matched group? All I
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),
2009 Sep 16
2
Generalized cumsum?
Is there anything like cumsum and cumprod but which allows you to apply an arbitrary function instead of sum and product? In other words, I want a function cumfunc(x, f) that returns a vector, so that for all n up to the length of x cumapply(x,f)[n] = f(x[1:n]) This would give cumsum and cumprod as special cases when f=sum or f=prod. I could write such a function, but I can't see
2009 Sep 16
1
Windows RGui line editing
I've been using Tinn-R with RGui on Windows for quite some time now, but it's very irritating how the Windows RGui allows only very rudimentary line-editing. I can't even use shift-arrow key to select text! I searched through the archives and found what seemed to be a few people asking about this, but I couldn't find a clear answer. I saw some references in the docs to
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
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 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
2011 Apr 28
1
Help ave() function
Hello again. Following a great idea from Jim and Dennis, I began to use the function ave() in my big data. I proved to use this command in my data with FUN=max(x,na.rm=T), and I received a Warning that translated looks like Warning in max (x, na.rm = T): no arguments to max; returning -Inf Is this happening 'cause I´m using a big table : 254417 rows 9 columns? [[alternative HTML version
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:
2012 Oct 23
1
scatterplot with wrong line offset
Hi All, I'm trying to do a Scatterplot (package: car), and add a line (just for reference). There is my code: #------------------------------------Code--------------------------------------------------- library("car") library("calibrate") G_T<-c("car","bike","boat") ave<-c(80,10,45) perf<-c(100,80,75) df2<-data.frame(G_T,ave,perf)