Re: [R] tapply and error bars

2018-06-24 Thread Jim Lemon
Hi Ogbos, The problem is almost certainly with the data. I get the plot I expect with the sample data that you first posted, so I know that the code works. If you try thIs what do you get? oodf<-read.table(text="S/N AB 1-5 64833 2-4 95864 3-3 82322 4-2 95591 5-

Re: [R] tapply and error bars

2018-06-24 Thread Ogbos Okike
Hi Jim Thanks again for returning to this. please not that the line "oomean<-as.vector(by(oodf$B,oodf$A,mean))" was omitted (not sure whether deliberate) after you introduced the standard error function. When I used it, empty plot window with the correct axes were generated but no data was displa

Re: [R] tapply and error bars

2018-06-24 Thread Jim Lemon
Hi Ogbos, If I use the example data that you sent, I get the error after this line: oose<-as.vector(by(oodf$B,oodf$A,std.error)) Error in FUN(X[[i]], ...) : object 'std.error' not found The reason is that you have not defined std.error as a function, but as the result of a calculation. When I rew

Re: [R] tapply and error bars

2018-06-23 Thread Jim Lemon
Hi Ogbos, This may help: # assume your data frame is named "oodf" oomean<-as.vector(by(oodf$B,oodf$A,mean)) oose<-as.vector(by(oodf$B,oodf$A,std.error)) plot(-5:10,oomean,type="b",ylim=c(5,11), xlab="days (epoch is the day of Fd)",ylab="strikes/km2/day") dispersion(-5:10,oomean,oose) Jim

Re: [R] tapply error svyby function "survey" package

2014-11-12 Thread Martin Canon
Anthony, thanks for your reply. Resetting the levels didn't work. These are the first 25 rows of the dataset: structure(list(id = c(51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 73L, 74L, 75L, 76L), stratum = structure(c(1L, 4L, NA, 4L,

Re: [R] tapply error svyby function "survey" package

2014-11-12 Thread Anthony Damico
hi martin, sending the first 25 rows does not help if it does not re-create the problem.. when i run the data you have provided, i do not encounter your problem (see below). someone else may be able to guess the issue, but this would be a lot easier to solve if you can create a minimal reproducib

Re: [R] tapply error svyby function "survey" package

2014-11-12 Thread Anthony Damico
try resetting your levels? if that doesn't work, please dput() an example data set that we can test with :) thanks! sii.design <- update( sii.design , d6 = factor( d6 ) ) On Wed, Nov 12, 2014 at 7:59 AM, Martin Canon wrote: > Hi. > > > I'm trying to calculate the weighted mean score of a

Re: [R] tapply and functions with more than one objects

2013-01-22 Thread David Winsemius
On Jan 22, 2013, at 2:24 PM, Dominic Roye wrote: > Hello, > > How i can use a costum function in tapply which has more than one variable? > > I mean sum(x) only needs one object but what when i have a function > function(x,y) with more, how i indicate where are the other variables > to use?7 Y

Re: [R] tapply to data.frame or matrix

2012-09-04 Thread arun
41 1.V42 1.V43 1.V44 1.V51 1.V52 1.V53 1.V54  #   9    10    11    12    13    14    15    16    17    18    19    20 A.K. - Original Message - From: Rui Barradas To: Jannis Cc: r-help Sent: Tuesday, September 4, 2012 11:30 AM Subject: Re: [R] tapply to data.frame or matrix Hello,

Re: [R] tapply to data.frame or matrix

2012-09-04 Thread Rui Barradas
Hello, Here's a way. test <- as.data.frame(matrix(1:20, ncol = 5, nrow=4)) test.ind <- c(1,1,2,2,2) lapply(split(colnames(test), test.ind), function(x) unlist(test[, x])) Hope this helps, Rui Barradas Em 04-09-2012 15:40, Jannis escreveu: Dear R users, imagine i have a dataframe and an ind

Re: [R] tapply confusion

2012-08-30 Thread David Winsemius
On Aug 30, 2012, at 4:02 AM, andyspeak wrote: Hello Thankyou for the help. kruskal.test(Temp, Roof) is simple but just returns one result for the whole temperature dataset organised by roof. I want to compare the Temp data for each Roof in each Month. So because i have temperature dat

Re: [R] tapply confusion

2012-08-30 Thread andyspeak
Hello Thankyou for the help. kruskal.test(Temp, Roof) is simple but just returns one result for the whole temperature dataset organised by roof. I want to compare the Temp data for each Roof in each Month. So because i have temperature data on the three roofs for 16 different months then i wan

Re: [R] tapply confusion

2012-08-30 Thread andyspeak
Actually its okay. I just created 16 subsets of the dataframe using the different months and then ran kruskal test 16 times. Im sure there is a nice way to code this to do it automatically and produce a nice table of the results but i only started learning R two weeks ago!!! Thanks for all the hel

Re: [R] tapply confusion

2012-08-29 Thread David Winsemius
On Aug 29, 2012, at 7:37 AM, andyspeak wrote: Hello I have a huge data frame with three columns 'Roof' 'Month' and 'Temp' i want to run analyses on the numerical Temp data by the factors Roof and Month, separately and together. For using more than one factor i understand i should use aggrega

Re: [R] tapply confusion

2012-08-29 Thread Milan Bouchet-Valat
Le mercredi 29 août 2012 à 07:37 -0700, andyspeak a écrit : > Hello > I have a huge data frame with three columns 'Roof' 'Month' and 'Temp' > i want to run analyses on the numerical Temp data by the factors Roof and > Month, separately and together. > For using more than one factor i understand i s

Re: [R] tapply for enormous (>2^31 row) matrices

2012-02-26 Thread Gabor Grothendieck
On Thu, Feb 23, 2012 at 11:39 AM, Matthew Keller wrote: > Thank you all very much for your help (on both the r-help and the > bioconductor listserves). > > Benilton - I couldn't get sqldf to install on the server I'm using > (error is: Error : package 'gsubfn' does not have a name space). I > thin

Re: [R] tapply for enormous (>2^31 row) matrices

2012-02-23 Thread Matthew Keller
Thank you all very much for your help (on both the r-help and the bioconductor listserves). Benilton - I couldn't get sqldf to install on the server I'm using (error is: Error : package 'gsubfn' does not have a name space). I think this was a problem for R 2.13, and I'm trying to get the admin's t

Re: [R] tapply for enormous (>2^31 row) matrices

2012-02-22 Thread ilai
On Tue, Feb 21, 2012 at 4:04 PM, Matthew Keller wrote: > X <- read.big.matrix("file.loc.X",sep=" ",type="double") > hap.indices <- bigsplit(X,1:2) #this runs for too long to be useful on > these matrices > #I was then going to use foreach loop to sum across the splits > identified by bigsplit Ho

Re: [R] tapply with specific quantile value

2011-03-24 Thread Steven Ranney
Worked just fine. I had been incorrectly trying tapply(x, l.c.1, quantile(probs=0.75)) rather than tapply(x, l.c.1, quantile, probs=0.75) Thanks for the help - SR Steven H. Ranney On Thu, Mar 24, 2011 at 6:03 PM, Peter Alspach wrote: > Tena koe Steven > > The  ... argument of the apply se

Re: [R] tapply with specific quantile value

2011-03-24 Thread Jorge Ivan Velez
Hi Steven, See the prob argument under ?quantile. The following should be what you want: tapply(x, l.c.1, quantile, prob = 0.75) HTH, Jorge * * On Thu, Mar 24, 2011 at 7:18 PM, Steven Ranney <> wrote: > All - > > I have an example data frame > > x l.c.1 > 43.38812035 085 > 47.5571

Re: [R] tapply with specific quantile value

2011-03-24 Thread Tóth Dénes
Just have a look at ?quantile and the probs argument. tapply(x, l.c.1, quantile,probs=0.75) Anyway, quantiles and quartiles are not the same. I guess you meant the 3rd quartile. > All - > > I have an example data frame > > x l.c.1 > 43.38812035 085 > 47.55710661 085 > 47.55710661 085

Re: [R] tapply with specific quantile value

2011-03-24 Thread Peter Alspach
Tena koe Steven The ... argument of the apply series of functions allows one to pass arguments to the called function. So: tapply(x, l.c.1, quantile, probs=0.75) should work (although I haven't tested it). HTH . Peter Alspach > -Original Message- > From: r-help-boun...@r-projec

Re: [R] tapply output as a dataframe

2011-02-03 Thread Graves, Gregory
-Original Message- From: Phil Spector [mailto:spec...@stat.berkeley.edu] Sent: Thursday, February 03, 2011 12:41 PM To: Graves, Gregory Cc: r-help@r-project.org; Goodman, Patricia; Gorman, Patricia Subject: Re: [R] tapply output as a dataframe Try as.data.frame(as.table(a

Re: [R] tapply output as a dataframe

2011-02-03 Thread Gabor Grothendieck
On Thu, Feb 3, 2011 at 1:11 PM, David Winsemius wrote: > > On Feb 3, 2011, at 1:05 PM, Graves, Gregory wrote: > >> Yes, as far as I can tell, "sampling.date" is a character vector of the >> format "1/15/2008".  It resides in the leftmost column of the tapply output. >> >> "station.code" are the A,

Re: [R] tapply output as a dataframe

2011-02-03 Thread David Winsemius
sem...@comcast.net] Sent: Thursday, February 03, 2011 12:50 PM To: Graves, Gregory Cc: r-help@r-project.org; Goodman, Patricia; Gorman, Patricia Subject: Re: [R] tapply output as a dataframe On Feb 3, 2011, at 11:29 AM, Graves, Gregory wrote: My tapply output is generated as follows: a=tappl

Re: [R] tapply output as a dataframe

2011-02-03 Thread Graves, Gregory
February 03, 2011 12:50 PM To: Graves, Gregory Cc: r-help@r-project.org; Goodman, Patricia; Gorman, Patricia Subject: Re: [R] tapply output as a dataframe On Feb 3, 2011, at 11:29 AM, Graves, Gregory wrote: > My tapply output is generated as follows: > >> a=tapply(value,list(sampling.dat

Re: [R] tapply output as a dataframe

2011-02-03 Thread David Winsemius
On Feb 3, 2011, at 11:29 AM, Graves, Gregory wrote: On Mon, Apr 13, 2009 at 12:41 PM, Dan Dube wrote: That is pushing two years ago, so I doubt very many people still have that posting on their mail-clients. (When I did go to the archives Dan Dube's problem was posed as how to bind "a":

Re: [R] tapply output as a dataframe

2011-02-03 Thread Phil Spector
Try as.data.frame(as.table(a)) - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley

Re: [R] tapply output as a dataframe

2011-02-03 Thread Graves, Gregory
On Mon, Apr 13, 2009 at 12:41 PM, Dan Dube wrote: > i use tapply and by often, but i always end up banging my head against > the wall with the output. The proposed solution of Dan's problem posted on R-help was: > do.call(rbind,a) When I use this 'solution' I get 'ERROR: second argument must

Re: [R] tapply output

2010-10-07 Thread jim holtman
You can also use sqldf: > require(sqldf) > sqldf("select class, `group`, name, avg(height) + from myData + group by class, 'group', name") class group name avg(height) 1 0 B Jane58.5 2 0 A Tom62.5 3 1 A Enzo66.5 4 1 B Mary

Re: [R] tapply output

2010-10-07 Thread Peter Ehlers
On 2010-10-06 13:24, Erik Iverson wrote: Hello, You can use ddply from the very useful plyr package to do this. There must be a way using "base R" functions, but plyr is worth looking into in my opinion. > install.packages("plyr") > library(plyr) > ddply(myData, .(class, group, name),

Re: [R] tapply output

2010-10-06 Thread Phil Spector
Geoffrey - The output you want is exactly what the aggregate() function provides: aggregate(myData$height, myData[c('class','group','name')],mean) class group namex 1 1 A Enzo 66.5 2 0 B Jane 58.5 3 1 B Mary 70.5 4 0 A Tom 62.5 It should be mentioned t

Re: [R] tapply output

2010-10-06 Thread Erik Iverson
Hello, You can use ddply from the very useful plyr package to do this. There must be a way using "base R" functions, but plyr is worth looking into in my opinion. > install.packages("plyr") > library(plyr) > ddply(myData, .(class, group, name), function(x) mean(x$height)) class group name V

Re: [R] tapply output

2010-10-06 Thread Henrique Dallazuanna
Try this: aggregate(height ~ class + group + name, data = myData, FUN = mean) On Wed, Oct 6, 2010 at 4:13 PM, Geoffrey Smith wrote: > Hello, I am having trouble getting the output from the tapply function > formatted so that it can be made into a nice table. Below is my question > written in R

Re: [R] tapply help

2010-06-05 Thread Mark Ebbert
That was very clever. Worked perfectly, thanks! And thanks to everyone else who provided feedback. On Jun 5, 2010, at 5:46 AM, jim holtman wrote: > It this what you are looking for: > >> set.seed(1) >> # create range for each possible class >> # 'name' the values so you can use them in the 'sap

Re: [R] tapply help

2010-06-05 Thread jim holtman
It this what you are looking for: > set.seed(1) > # create range for each possible class > # 'name' the values so you can use them in the 'sapply' function > lows<-c(a=1, b=2, c=3, d=4, e=5) > highs<-c(a=5, b=6, c=7, d=8, e=9) > > # data values > vals<-sample(1:10,100,replace=T) > > #classes > cla

Re: [R] tapply function with NA

2010-05-10 Thread Gabor Grothendieck
See ?colSums On Mon, May 10, 2010 at 12:44 AM, vincent.deluard wrote: > > Hi R users, > > I have a matrix "m" of the type: > > m >       X4.20.2010 X4.19.2010   X4.16.2010 > [1,]  0.008319468 0. -0.008250825 > [2,]  0.005574136 0.01816118  0.073081608 > [3,] -0.047830688 0.01612903 -0.030

Re: [R] tapply function with NA

2010-05-09 Thread RICHARD M. HEIBERGER
It is exactly the same tmp <- matrix(1:24,6,4) tmp[4,] <- NA tmp apply(tmp, 2, sum, na.rm=TRUE) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting gu

Re: [R] Tapply.

2010-04-27 Thread Petr PIKAL
Hi steven mosher napsal dne 27.04.2010 17:04:04: > Thanks, > > I had been wondering what Drop did. That makes it more clear. > > While I have code that loops and does the problem correctly, I wanted to > do things the R way and be fast and terse. hehe. > > So: > ID d

Re: [R] Tapply.

2010-04-27 Thread steven mosher
Thanks, I had been wondering what Drop did. That makes it more clear. While I have code that loops and does the problem correctly, I wanted to do things the R way and be fast and terse. hehe. So: ID dy jan ... 11264402000 1 1987 NA NA NA NA NA 218 N

Re: [R] Tapply.

2010-04-27 Thread Petr PIKAL
Hi If you are not satisfied with R intro docs which are distributed with R installation you can consider Introductory statistics with R by P.Dalgaard for beginners and mayby Modern applied statistics with S by W.N.Venables and B.D.Ripley which is a bit outdated and applies maybe a little more t

Re: [R] Tapply.

2010-04-27 Thread Petr PIKAL
Hi r-help-boun...@r-project.org napsal dne 26.04.2010 17:05:54: > I guess my problem was seeing a bunch of examples where they pulled a > variable from a dataframe.. > > tapply(df$data, index=list(.. df$data results in vector so as eg. df[,5] unless you use drop=FALSE option > > and I > ass

Re: [R] Tapply.

2010-04-27 Thread steven mosher
Thanks dennis. Is there a book on R u could recommend. On Mon, Apr 26, 2010 at 7:12 PM, Dennis Murphy wrote: > Hi: > > > > On Mon, Apr 26, 2010 at 8:01 AM, steven mosher > > wrote: > > Thanks, > > > I was trying to stick with the base package and figure out how the base > routines worke

Re: [R] Tapply.

2010-04-26 Thread Dennis Murphy
Hi: > On Mon, Apr 26, 2010 at 8:01 AM, steven mosher wrote: > Thanks, > I was trying to stick with the base package and figure out how the base routines worked. If you want to use base functions, then here's a solution with aggregate: (the Id column was removed first): > with(DF, aggregate(DF[

Re: [R] Tapply.

2010-04-26 Thread steven mosher
I guess my problem was seeing a bunch of examples where they pulled a variable from a dataframe.. tapply(df$data, index=list(.. and I assumed that the df$data was just generalizable to a collection of vectors a vector of vector being a vector Thanks. On Mon, Apr 26, 2010 at 2:43 AM, Petr PIKA

Re: [R] Tapply.

2010-04-26 Thread steven mosher
Thanks, I was trying to stick with the base package and figure out how the base routines worked. I looked at plyer and it was very appealing. I guess i'll give in and use it On Mon, Apr 26, 2010 at 2:33 AM, Dennis Murphy wrote: > Hi: > > Use of ddply() in the plyr package appears to work. > >

Re: [R] Tapply.

2010-04-26 Thread Petr PIKAL
Hi steven mosher napsal dne 26.04.2010 10:21:37: > That fails: > > The manual says: > > tapply(X, INDEX, FUN = NULL, ..., simplify = TRUE) > Arguments > > X > > an atomic object, typically a vector. > > INDEX > > list of factors, each of same length as X. The elements are coerced to fac

Re: [R] Tapply.

2010-04-26 Thread Dennis Murphy
Hi: Use of ddply() in the plyr package appears to work. library(plyr) ddply(df[, -1], .(Year), colwise(mean), na.rm = TRUE) D Year Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 1 1.00 1980 NaN NaN NaN NaN NaN 212 203 209 228 237 NaN NaN 2 0.50 1981 NaN 251 243 246 241 NaN NaN N

Re: [R] Tapply.

2010-04-26 Thread steven mosher
That fails: The manual says: tapply(X, INDEX, FUN = NULL, ..., simplify = TRUE) ArgumentsXan atomic object, typically a vector.INDEXlist of factors, each of same length as X. The elements are coerced to factors by as.factor . my error says: E

Re: [R] Tapply.

2010-04-26 Thread steven mosher
I've tried both mean and colMean. I did success with one attempt using mean, however if only have 1 year and its a NA then I get NaN ( which I can replace). I'll keep trying. On Mon, Apr 26, 2010 at 12:26 AM, Petr PIKAL wrote: > Hi > > r-help-boun...@r-project.org napsal dne 26.04.2010 06:52:

Re: [R] tapply syntax

2010-03-28 Thread David Freedman
sorry - I use many abbreviations and I try to remove them before I post questions/answers - 'set' is my abb. for subset david On 3/28/2010 8:27 PM, Jeff Brown [via R] wrote: > What is the function "set()"? Is that a typo? When I type ?set I get > nothing, and when I try to evaluate that code

Re: [R] tapply syntax

2010-03-28 Thread jim holtman
The message tells you everything - there is no function 'set' in the workspace you are using. Did you forget to load a library? What is the context in which you are trying to use it? On Sun, Mar 28, 2010 at 8:27 PM, Jeff Brown wrote: > > What is the function "set()"? Is that a typo? When I ty

Re: [R] tapply syntax

2010-03-28 Thread Rolf Turner
On 29/03/2010, at 1:27 PM, Jeff Brown wrote: > > What is the function "set()"? Is that a typo? When I type ?set I get > nothing, and when I try to evaluate that code R tells me it can't find the > function. Yeah, it's a typo. (S)he meant ``subset''. cheers, Rolf Tu

Re: [R] tapply syntax

2010-03-28 Thread Jeff Brown
What is the function "set()"? Is that a typo? When I type ?set I get nothing, and when I try to evaluate that code R tells me it can't find the function. -- View this message in context: http://n4.nabble.com/tapply-syntax-tp1692503p1694586.html Sent from the R help mailing list archive at Nabb

Re: [R] tapply syntax

2010-03-26 Thread David Freedman
how about: d1=data.frame(pat=c(rep('a',3),'b','c',rep('d',2),rep('e',2),'f'),var=c(1,2,3,1,2,2,3,2,4,4)) ds=set(d1,var %in% c(2,3)) with(ds,tapply(var,pat,FUN=length)) hth, David Freedman, CDC, Atlanta -- View this message in context: http://n4.nabble.com/tapply-syntax-tp1692503p1692553.html S

Re: [R] tapply syntax

2010-03-26 Thread Min-Han Tan
Hi, I figured a workaround to my problem, but if anyone has any advice on how to express a function in tapply to achieve the same outcome, that would be awesome and I'd learn something about functions! The workaround was tapply ((data$Variation.Type %in% c(2,3)), data$Patient, sum) Thanks. Min-

Re: [R] tapply for function taking of >1 argument?

2010-02-04 Thread David Winsemius
On Feb 4, 2010, at 9:56 AM, J. R. M. Hosking wrote: sjaffe wrote: I'm sure I can put this together from the various 'apply's and split, but I wonder if anyone has a quick incantation: E.g. I can do tapply( data, groups, mean) but how can I do something like: tapply( list(data,weights), grou

Re: [R] tapply for function taking of >1 argument?

2010-02-04 Thread J. R. M. Hosking
sjaffe wrote: I'm sure I can put this together from the various 'apply's and split, but I wonder if anyone has a quick incantation: E.g. I can do tapply( data, groups, mean) but how can I do something like: tapply( list(data,weights), groups, weighted.mean ) ? (or: mapply is to sapply as ? is

Re: [R] tapply for function taking of >1 argument?

2010-02-03 Thread hadley wickham
> It will of necessity be slower (because there's more machinery underlying > the sqldf package); but I doubt whether it would be noticeably slower than > the native R solution in most practical situations. The same would be true > for plyR's implementation (it relies on the proto package, which sl

Re: [R] tapply for function taking of >1 argument?

2010-02-03 Thread Bert Gunter
g] On Behalf Of sjaffe Sent: Wednesday, February 03, 2010 10:25 AM To: r-help@r-project.org Subject: Re: [R] tapply for function taking of >1 argument? Thanks, Ibm actually more comfortable with vector-ish syntax than sql-ish but this is a good thing to keep in mindb& I wonder how it c

Re: [R] tapply for function taking of >1 argument?

2010-02-03 Thread sjaffe
Thanks, I’m actually more comfortable with vector-ish syntax than sql-ish but this is a good thing to keep in mind… I wonder how it compares in performance versus ‘by’ or ‘tapply’ From: Gabor Grothendieck [via R] [mailto:ml-node+1461531-1948782...@n4.nabble.com] Sent: Wednesday, Fe

Re: [R] tapply for function taking of >1 argument?

2010-02-03 Thread Gabor Grothendieck
Also try this: > library(sqldf) > DF <- data.frame(data = 1:10, groups = rep(1:2, 5), weights = 1) > sqldf("select groups, sum(data * weights)/sum(weights) 'wtd mean' from DF > group by groups") groups wtd mean 1 15 2 26 On Tue, Feb 2, 2010 at 5:06 PM, sjaffe wrote:

Re: [R] tapply for function taking of >1 argument?

2010-02-03 Thread hadley wickham
On Wed, Feb 3, 2010 at 11:06 AM, David Freedman <3.14da...@gmail.com> wrote: > > also, > > library(plyr) > ddply(d,~grp,function(df) weighted.mean(df$x,df$w)) Or ddply(d, "grp", summarise, mean = weighted.mean(x, w)) which is convenient if you want more than one output Hadley -- http://had.

Re: [R] tapply for function taking of >1 argument?

2010-02-03 Thread David Freedman
also, library(plyr) ddply(d,~grp,function(df) weighted.mean(df$x,df$w)) -- View this message in context: http://n4.nabble.com/tapply-for-function-taking-of-1-argument-tp1460392p1461428.html Sent from the R help mailing list archive at Nabble.com. __

Re: [R] tapply for function taking of >1 argument?

2010-02-03 Thread Steve Jaffe
Yes, this is clearly the key to working with subsets. Thanks -Original Message- From: Petr PIKAL [mailto:petr.pi...@precheza.cz] Sent: Wednesday, February 03, 2010 4:16 AM To: Steve Jaffe Cc: r-help@r-project.org Subject: Re: [R] tapply for function taking of >1 argument? Hi r-h

Re: [R] tapply for function taking of >1 argument?

2010-02-03 Thread Petr PIKAL
Hi r-help-boun...@r-project.org napsal dne 02.02.2010 22:16:06: > > 'fraid not :-(( > > tapply( data, groups, weighted.mean, weights) tapply(seq(along=lll), rrr, function(i, x, w) weighted.mean(x[i], w[i]), x=lll, w=ttt) If you want to subset more than one thing, subset the index vec

Re: [R] tapply for function taking of >1 argument?

2010-02-02 Thread sjaffe
Thanks! :-) I suppose it's obvious, but one will generally have to use a (anonymous) function to 'unpack' the data.frame into columns, unless the function already knows how to do this. I mention this because when I tested the solution on my example I got an unexpected result -- apparently weig

Re: [R] tapply for function taking of >1 argument?

2010-02-02 Thread Steve Jaffe
Excellent! I knew there would be a clever answer using 'do.call' :-) -Original Message- From: Charles C. Berry [mailto:cbe...@tajo.ucsd.edu] Sent: Tuesday, February 02, 2010 4:25 PM To: Steve Jaffe Cc: r-help@r-project.org Subject: Re: [R] tapply for function taking of >1

Re: [R] tapply for function taking of >1 argument?

2010-02-02 Thread Charles C. Berry
On Tue, 2 Feb 2010, sjaffe wrote: 'fraid not :-(( tapply( data, groups, weighted.mean, weights) won't work because the *entire* weights vector is passed as the 2nd arg to weighted.means. But weighted.mean needs 'weights' to be split in the same way as 'data' -- the first and 2nd args need to

Re: [R] tapply for function taking of >1 argument?

2010-02-02 Thread Bert Gunter
?by Bert Gunter Genentech Nonclinical Statistics -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of sjaffe Sent: Tuesday, February 02, 2010 1:16 PM To: r-help@r-project.org Subject: Re: [R] tapply for function taking of >1 argum

Re: [R] tapply for function taking of >1 argument?

2010-02-02 Thread sjaffe
'fraid not :-(( tapply( data, groups, weighted.mean, weights) won't work because the *entire* weights vector is passed as the 2nd arg to weighted.means. But weighted.mean needs 'weights' to be split in the same way as 'data' -- the first and 2nd args need to correspond. Jorge Ivan Velez wrot

Re: [R] tapply for function taking of >1 argument?

2010-02-02 Thread Jorge Ivan Velez
Hi sjaffem, You were almost there: tapply( yourdata, groups, weighted.mean, weights) See ?tapply for more information. HTH, Jorge On Tue, Feb 2, 2010 at 3:58 PM, sjaffe <> wrote: > > I'm sure I can put this together from the various 'apply's and split, but I > wonder if anyone has a quick in

Re: [R] tapply on multiple groups

2010-01-28 Thread Gigi Lipori
Thanks. My mistake was that I used c(dbs.final$Days,dbs.final$Place) instead of list(... when I tried to follow that part of the documentation. >>> David Winsemius 1/28/2010 11:49 AM >>> On Jan 28, 2010, at 10:26 AM, GL wrote: > > Can you make tapply break down groups similar to bwplot or suc

Re: [R] tapply on multiple groups

2010-01-28 Thread David Winsemius
On Jan 28, 2010, at 10:26 AM, GL wrote: Can you make tapply break down groups similar to bwplot or such? Example: Data frame has one measure (Days) and two Dimensions (MM and Place). All have the same length. length(dbs.final$Days) [1] 3306 length() [1] 3306 length() [1] 3306

Re: [R] tapply and more than one function, with different arguments

2010-01-26 Thread RINNER Heinrich
Hi Dennis, now that's a very nice function, and this seems to be just what I need! Thanks a lot! -Heinrich. Von: Dennis Murphy [djmu...@gmail.com] Gesendet: Dienstag, 26. Januar 2010 19:44 An: RINNER Heinrich Cc: r-help Betreff: Re: [R] tapply and more

Re: [R] tapply and more than one function, with different arguments

2010-01-26 Thread Dennis Murphy
Hi: Using the plyr package, we can get the result as follows: > library(plyr) > my.fun <- function(x, mult) mult*sum(x) > dat <- data.frame(x = 1:4, grp = c("a","a","b","b")) > ddply(dat, .(grp), summarize, max = max(x), myfun = my.fun(x, 10)) grp max myfun 1 a 230 2 b 470 HTH,

Re: [R] tapply and more than one function, with different arguments

2010-01-26 Thread Peter Ehlers
Try replacing 'max' with 'mean' and see what you get. Then have a look at ?max and see what max() does with extra arguments. I'm not sure it's relevant, but it might be useful to check what Hmisc::summarize does. -Peter Ehlers RINNER Heinrich wrote: Dear R-users, I am working with R version

Re: [R] tapply function

2009-11-03 Thread Sundar Dorai-Raj
you must have missing values in "data". Try tapply(data, group, mean, na.rm = TRUE) If that's not the case, read the bottom of this email about the posting guide. HTH, --sundar On Tue, Nov 3, 2009 at 5:28 AM, FMH wrote: > Hi, > > I tried to use tapply function to find the mean of the data in

Re: [R] tapply with multiple arguments that are not part of the same data frame

2009-10-22 Thread Kavitha Venkatesan
I just realized my earlier post of my question below was not in "Plain" Text mode, hence the repeat post...apologies! Kavitha On Thu, Oct 22, 2009 at 4:19 PM, Kavitha Venkatesan wrote: > Hi all, > > I would like to invoke a function that takes multiple arguments (some of > which are specified co

Re: [R] tapply() and using factor() on a factor

2009-10-16 Thread David Winsemius
it clearly doesn't. -- DW In other words, how do I take a subset which yields "a" as the only level for log2? Alex -Original Message----- From: William Dunlap [mailto:wdun...@tibco.com] Sent: Thursday, October 15, 2009 11:59 PM To: Alexander Peterhansl; r-help@r-project.org Subj

Re: [R] tapply() and using factor() on a factor

2009-10-16 Thread Alexander Peterhansl
quot; "e" "f" "g" "h" "i" "j" In other words, how do I take a subset which yields "a" as the only level for log2? Alex -Original Message- From: William Dunlap [mailto:wdun...@tibco.com] Sent: Thursday, October 1

Re: [R] tapply() and using factor() on a factor

2009-10-15 Thread William Dunlap
> -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Alexander > Peterhansl > Sent: Thursday, October 15, 2009 2:50 PM > To: r-help@r-project.org > Subject: [R] tapply() and using factor() on a factor > > Dear List, > > > > Sh

Re: [R] tapply with cbinded x

2009-06-16 Thread Wacek Kusnierczyk
Petr PIKAL wrote: > Hi > > r-help-boun...@r-project.org napsal dne 16.06.2009 12:45:04: > > >> Stefan Uhmann wrote: >> >>> Dear List, >>> >>> why does this not work? >>> >>> df <- data.frame(var1 = c(3,2,1), var2 = c(6,5,4), var3 = c(9,8,7), >>> fac = c('A', 'A', 'B')) >>> tapply(cbind(

Re: [R] tapply with cbinded x

2009-06-16 Thread Wacek Kusnierczyk
Stavros Macrakis wrote: > On Tue, Jun 16, 2009 at 5:16 AM, Stefan Uhmann >> wrote: >> > > >> why does this not work? >> >> df <- data.frame(var1 = c(3,2,1), var2 = c(6,5,4), var3 = c(9,8,7), >>fac = c('A', 'A', 'B')) >> tapply(cbind(df$var1, df$var2, df$var3), df$fac, mean) >> >

Re: [R] tapply with cbinded x

2009-06-16 Thread Petr PIKAL
Hi r-help-boun...@r-project.org napsal dne 16.06.2009 12:45:04: > Stefan Uhmann wrote: > > Dear List, > > > > why does this not work? > > > > df <- data.frame(var1 = c(3,2,1), var2 = c(6,5,4), var3 = c(9,8,7), > > fac = c('A', 'A', 'B')) > > tapply(cbind(df$var1, df$var2, df$var3), df$fac, me

Re: [R] tapply with cbinded x

2009-06-16 Thread Stavros Macrakis
On Tue, Jun 16, 2009 at 5:16 AM, Stefan Uhmann wrote: > why does this not work? > > df <- data.frame(var1 = c(3,2,1), var2 = c(6,5,4), var3 = c(9,8,7), >fac = c('A', 'A', 'B')) > tapply(cbind(df$var1, df$var2, df$var3), df$fac, mean) > Because tapply is defined for atomic vectors and not

Re: [R] tapply with cbinded x

2009-06-16 Thread Wacek Kusnierczyk
Stefan Uhmann wrote: > Dear List, > > why does this not work? > > df <- data.frame(var1 = c(3,2,1), var2 = c(6,5,4), var3 = c(9,8,7), > fac = c('A', 'A', 'B')) > tapply(cbind(df$var1, df$var2, df$var3), df$fac, mean) because length(cbind(df$var1, df$var2, df$var3)) # 9 length(df$

Re: [R] tapply changing order of factor levels?

2009-05-06 Thread Alain Guillet
Hi, I meant that your problem occured because the levels of mylevels are not ordered whereas tapply uses the ordered levels for printing. If you order them (look under), you can see the results of the tapply has the same order as the levels of myfactor >mydata<-c("IN0020020155","IN0019800021

Re: [R] tapply changing order of factor levels?

2009-05-06 Thread Bert Gunter
782 0.4682773 Bert Gunter Genentech Nonclinical Statistics -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of jim holtman Sent: Wednesday, May 06, 2009 6:57 AM To: Chirantan Kundu Cc: r-help@r-project.org Subject: Re: [R] tapply c

Re: [R] tapply changing order of factor levels?

2009-05-06 Thread S Ellison
The problem is in the code. When you say >> mysummary<-tapply(myfactor,mydata,length) >> mysummary you have used mydata as a factor and myfactor as the data. tapply has (correctly) used the ordered labels in the grouping factor (mydata) to label its output. If you did what you probably intende

Re: [R] tapply changing order of factor levels?

2009-05-06 Thread Chirantan Kundu
Hi Ellison, Thanks for pointing it out. Bad miss on my part. Regards. On Wed, May 6, 2009 at 7:55 PM, S Ellison wrote: > The problem is in the code. > > When you say > >> mysummary<-tapply(myfactor,mydata,length) > >> mysummary > > you have used mydata as a factor and myfactor as the data. >

Re: [R] tapply changing order of factor levels?

2009-05-06 Thread Chirantan Kundu
Hi Alain, I tried levels(myfactor) as you suggested. > levels(myfactor) [1] "IN0020020155" "IN0019800021" "IN0020020064" The order is preserved, no alphanumerical sorting done here. Regards. On Wed, May 6, 2009 at 7:35 PM, Alain Guillet wrote: > Hi, > > I don't believe the problem is related t

Re: [R] tapply changing order of factor levels?

2009-05-06 Thread Alain Guillet
Hi, I don't believe the problem is related to tapply. I would say it is because of the factor. In fact, the order of a factor is given by the alphanumerical order of his levels. You can see it with levels(myfactor). I you want to change the order, redefine the levels of myfactor with the expec

Re: [R] tapply changing order of factor levels?

2009-05-06 Thread Chirantan Kundu
Thanks, Jim. It works! On Wed, May 6, 2009 at 7:26 PM, jim holtman wrote: > The result of 'tapply' is just a named vector and the names are in > alphabetical order. If you want them printed in a different order, then you > have to specify it. Since you have the order in 'mylevels', this will w

Re: [R] tapply changing order of factor levels?

2009-05-06 Thread jim holtman
The result of 'tapply' is just a named vector and the names are in alphabetical order. If you want them printed in a different order, then you have to specify it. Since you have the order in 'mylevels', this will work: > str(mysummary) int [1:3(1d)] 4 3 2 - attr(*, "dimnames")=List of 1 ..$

Re: [R] tapply output as a dataframe

2009-04-13 Thread Dan Dube
this is what i needed! thank you. > -Original Message- > From: Jorge Ivan Velez [mailto:jorgeivanve...@gmail.com] > Sent: Monday, April 13, 2009 12:50 PM > To: Dan Dube > Cc: r-help@r-project.org > Subject: Re: [R] tapply output as a dataframe > > &

Re: [R] tapply output as a dataframe

2009-04-13 Thread jim holtman
> do.call(rbind,a) [,1] [,2] [,3] [,4] 1 -0.7871502 -0.4437714 0.4011135 -0.2626129 2 -0.9546515 0.2210001 0.816 0.1245766 3 -0.5389725 -0.2750984 0.6655951 -0.1873485 4 -0.8176898 -0.1844181 0.4737187 -0.2688996 On Mon, Apr 13, 2009 at 12:41 PM, Dan Dube wrote: >

Re: [R] tapply output as a dataframe

2009-04-13 Thread Jorge Ivan Velez
Dear Dan, Try this: do.call(rbind,a) HTH, Jorge On Mon, Apr 13, 2009 at 12:41 PM, Dan Dube wrote: > i use tapply and by often, but i always end up banging my head against > the wall with the output. > > is there a simpler way to convert the output of the following tapply to > a dataframe or

Re: [R] tapply bug? - levels of a factor in a data frame after tapply are intermixed

2009-02-13 Thread Dimitri Liakhovitski
.s...@imail.org > 801.408.8111 > > >> -Original Message- >> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- >> project.org] On Behalf Of Dimitri Liakhovitski >> Sent: Friday, February 13, 2009 10:54 AM >> To: marc_schwa...@comcast.net >&

Re: [R] tapply bug? - levels of a factor in a data frame after tapply are intermixed

2009-02-13 Thread Marc Schwartz
on 02/13/2009 11:38 AM Dimitri Liakhovitski wrote: > On Fri, Feb 13, 2009 at 12:24 PM, Marc Schwartz > wrote: >> on 02/13/2009 11:09 AM Dimitri Liakhovitski wrote: >>> Hello! I have encountered a really weird problem. Maybe you've >>> encountered it before? >>> I have a large data frame "importanc

  1   2   >