Re: [R] creating lagged variable in panel data

2012-08-30 Thread Alok Bohara, PhD
Sorry, this is what I used : f - function(x) { wage - ts(x$wage, start = x$year[1]) idx - seq(length = length(wage)) wages - cbind(wage, wage.lag1 = lag(wage, -1))[idx,] cbind(x, wages) } result - do.call(rbind,

Re: [R] generating random samples of IG distribution

2012-08-30 Thread David Scott
I don't read R-help these days so have just seen this. Both generalized inverse Gaussian and normal inverse Gaussian are in GeneralizedHyperbolic. HyperbolicDist is no longer being maintained. David Scott On 12/06/2012 5:41 a.m., David L Carlson wrote: Should have been For the normal

Re: [R] 2 (related) problems with RODBC in 64 bit Windows

2012-08-30 Thread Uwe Ligges
On 29.08.2012 20:32, Ivan Alves wrote: Dear Uwe, Many thanks for the reply. On 1, the problem is that RODBC on 32 bit ' interprets' factors correctly, whereas on 64 bit it gives the error below. On both systems forcing characters (via colClasses = character in read.csv), results in no

Re: [R] latex \subfloat{} incompatible with sweave/knitr code

2012-08-30 Thread Liviu Andronic
On Thu, Aug 30, 2012 at 12:50 AM, Yihui Xie x...@yihui.name wrote: Do you know what environments are allowed inside \subfloat{}? The graphics example works because it is nothing but a simple \includegraphics{} command. The table example you gave is much more complicated than that. Regards,

[R] segfault in gplots::heatmap.2

2012-08-30 Thread Andreas Leha
Hi all, I experience a segfault when calling gplots::heatmap.2(), but only when certain other packages are loaded. I am not sure for the correct place to send this bug report. Should I send it to the package maintainers directly? If R-help is the wrong place, please feel free to direct me to

[R] Argument of a linear model

2012-08-30 Thread m4n14ccc
Hey I have a little problem here: I have an experimental space, lets say [-1,+1]^2, and I fit a second order model above it. Regarding the whole experimental space the regression function maps within [-3,+4], which means nothing else than f^-1([-3,+4])=[-1,+1] Now for example the question is:

Re: [R] Leading plus in numeric fields

2012-08-30 Thread PIKAL Petr
Hi -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Luca Meyer Sent: Thursday, August 30, 2012 7:55 AM To: R help Subject: [R] Leading plus in numeric fields Hello R experts, I have go this data frame: 'data.frame': 1

[R] Maximum a Posteriori (MAP) estimation in R

2012-08-30 Thread bin you
Hi, r-helpers, does anybody know how to get the MAP estimator? I have a dataframe (nrow=10,000, ncol=24) with 24 parameters. It is a sample from MCMC simulation. which function can generate the MAP estimator for each of the 24 parameters. Many thanks in advance, Bin [[alternative HTML

[R] help on plot on the log scale but showing original values on axis

2012-08-30 Thread Andras Farkas
dear All   I am trying to plot the following with the x axis on the log scale, but I would like the original x values to show up as labels:   x -c(0.25,0.5,1,2,4,8,16,32) y -c(1,1,1,1,0.9,0.8,0.6,0.2)   plot(log(x),y,type=b)   here I would like the labels 0.25,0.5,1,2,4,8,16, and 32 to show on

Re: [R] barchart with 3 rows

2012-08-30 Thread Geophagus
Thanks a lot 2 all of you. Both proposals work very fine!! Thank you and best greetings. Geophagus -- View this message in context: http://r.789695.n4.nabble.com/barchart-with-3-rows-tp4641572p4641809.html Sent from the R help mailing list archive at Nabble.com.

Re: [R] no true negative data, need roc curve

2012-08-30 Thread vjyns
Hi, again i had small clarification regarding the discussion. I had 6 images of two threshold test, so can i plot 6 roc for each individual image? or can i plot two roc curve (threshold 1 all images summed up and similar to threshold 2)? which is the correct one? Please clarify me in this

Re: [R] help on plot on the log scale but showing original values on axis

2012-08-30 Thread Rui Barradas
Hello, The following is the general idea. x -c(0.25,0.5,1,2,4,8,16,32) y -c(1,1,1,1,0.9,0.8,0.6,0.2) plot(log(x),y,type=b, xaxt = n) axis(1, at = log(x), labels = x) If the x values are not so neat, you can adjust the axis ticks and labels using round/seq. Hope this helps, Rui Barradas Em

Re: [R] predict.lm(...,type=terms) question

2012-08-30 Thread Rui Barradas
Hello, Instead of reversing the regression, that, like you say, may have problems, it's very easy to wrap the formula x' - (y' - beta0)/beta1 in a function and use the direct regression to get new 'x' values from new 'y' ones. This function assumes a first order ols model. invpredict -

[R] Which BUGS should one use?

2012-08-30 Thread Petar Milin
Hello ALL! Some times ago I started to learn and play with Bayesian stuffs. Many advice use of WinBUGS for Bayesian inference Using Gibbs Sampler. However, WinBUGS is discontinued, and now, development is under OpenBUGS. I wasn't lazy, so I installed both and tried out. In more than 90% of cases

[R] apply -- data.frame

2012-08-30 Thread Sam Steingold
Is there a way for an apply-type function to return a data frame? the closest thing I think of is foo - as.data.frame(sapply(...)) names(foo) - c() is there a more elegant way? Thanks! -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000

Re: [R] apply -- data.frame

2012-08-30 Thread andrija djurovic
hi try with plyr library and function ddply Andrija On 30 Aug 2012 12:58, Sam Steingold s...@gnu.org wrote: Is there a way for an apply-type function to return a data frame? the closest thing I think of is foo - as.data.frame(sapply(...)) names(foo) - c() is there a more elegant

Re: [R] apply -- data.frame

2012-08-30 Thread andrija djurovic
I forgot to mention data.table package and also function aggregate as part of base R functions could be useful here Andrija On 30 Aug 2012 13:09, andrija djurovic djandr...@gmail.com wrote: hi try with plyr library and function ddply Andrija On 30 Aug 2012 12:58, Sam Steingold

[R] use row and col names of a matrix to create colnames of a new one.

2012-08-30 Thread Juan Antonio Balbuena
Hello I would appreciate any help with the following: Given a matrix with col and row names, such as matrix1 - matrix(rnorm(16),4) rownames(matrix1) - LETTERS(1:4) colnames(matrix1) - letters[1:4] matrix1 a bc d A 1.6845882 -0.27809792 -0.874798414

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

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

[R] Help on Plot Title where text is mixed with numerical carachters

2012-08-30 Thread Andras Farkas
Dear All,   I have the following code set up:   x -2000 y -8 z -3   I would need to use these numbers to show up in my plot title mixed with text. The x,y,z numbers would need to change, the text would not. So my title should look like this   x txt1 y txt2 z txt3   so if: txt1=hours txt2=minutes

[R] random forest using party package

2012-08-30 Thread mushira
Hi all, I am trying out with random forest on party package but am getting an error saying : cannot allocate vector of size 564. What would be the problem? the coding as below: data.controls - cforest_unbiased(ntree=1000, mtry=3) data.cforest - cforest(class ~x1+x2+x3, data = Score,

[R] path analysis help

2012-08-30 Thread Jinsong Zhao
Hi there, I searched R-help list with path analysis as keyword, and learn that sem package can do it. However, I don't figure out a way to construct the model for the path diagram as Fig. 1. in Huang et al. (2002)[1]. I try the following code: huang.cor - readMoments(diag=FALSE,

Re: [R] Leading plus in numeric fields

2012-08-30 Thread arun
HI, Try this: set.seed(1) dat1-data.frame(OreTot=c(40,-7,41,35,7,15),GeoTot=c(TRUE,FALSE,TRUE,FALSE,TRUE,NA),OreCli=as.numeric(sample(1:25,6,replace=TRUE))) dat1$OreTot-ifelse(dat1$OreTot0,formatC(dat1$OreTot,format=f,digits=1,flag=+),dat1$OreTot)

Re: [R] Leading plus in numeric fields

2012-08-30 Thread arun
HI, You can also use gsub set.seed(1) dat1-data.frame(OreTot=c(40,-7,41,35,7,15),GeoTot=c(TRUE,FALSE,TRUE,FALSE,TRUE,NA),OreCli=as.numeric(sample(1:25,6,replace=TRUE))) dat1[,1]-ifelse(dat1[,1]0,gsub((\\d+),+\\1,dat1[,1]),dat1[,1]) dat1[,3]-ifelse(dat1[,3]0,gsub((\\d+),+\\1,dat1[,3]),dat1[,3])  

Re: [R] Leading plus in numeric fields

2012-08-30 Thread arun
HI, As you are more number of columns which are numeric, try this: set.seed(1) dat1-data.frame(OreTot=c(40,-7,41,35,7,15),GeoTot=c(TRUE,FALSE,TRUE,FALSE,TRUE,NA),OreCli=as.numeric(sample(1:25,6,replace=TRUE))) dat2-dat1[sapply(dat1,is.numeric)] dat3-data.frame(sapply(dat2,function(x)

Re: [R] Argument of a linear model

2012-08-30 Thread David Winsemius
On Aug 30, 2012, at 12:08 AM, m4n14ccc wrote: Hey I have a little problem here: I have an experimental space, lets say [-1,+1]^2, and I fit a second order model above it. Regarding the whole experimental space the regression function maps within [-3,+4], which means nothing else than

Re: [R] use row and col names of a matrix to create colnames of a new one.

2012-08-30 Thread David Winsemius
On Aug 30, 2012, at 7:24 AM, Juan Antonio Balbuena wrote: matrix1 - matrix(rnorm(16),4) rownames(matrix1) - LETTERS[1:4] # fixed the coding error colnames(matrix1) - letters[1:4] matrix2 - matrix1 colnames(matrix2) - paste(rownames(matrix1),colnames(matrix1),sep=-) matrix2 -- David

Re: [R] Help on Plot Title where text is mixed with numerical carachters

2012-08-30 Thread Greg Snow
Look at the sprintf and paste functions (either one will do what you describe). On Thu, Aug 30, 2012 at 7:49 AM, Andras Farkas motyoc...@yahoo.com wrote: Dear All, I have the following code set up: x -2000 y -8 z -3 I would need to use these numbers to show up in my plot title mixed with

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

Re: [R] random forest using party package

2012-08-30 Thread David Winsemius
On Aug 30, 2012, at 4:02 AM, mushira wrote: Hi all, I am trying out with random forest on party package but am getting an error saying : cannot allocate vector of size 564. What would be the problem? the coding as below: data.controls - cforest_unbiased(ntree=1000, mtry=3) data.cforest

Re: [R] Help on Plot Title where text is mixed with numerical carachters

2012-08-30 Thread John Kane
?paste plot(1, main = paste(x, hours, y , minutes, z , seconds, sep = )) John Kane Kingston ON Canada -Original Message- From: motyoc...@yahoo.com Sent: Thu, 30 Aug 2012 06:49:04 -0700 (PDT) To: r-help@r-project.org Subject: [R] Help on Plot Title where text is mixed with

[R] Identifying and Removing NA Columns and factor Columns with more than x Levels

2012-08-30 Thread Lopez, Dan
Hi, How do you subset a dataframe so that you only have columns: 1. that contain one or more NAs? 2. that contain factors with greater than or equal to 32 levels? How do you remove from a dataframe columns** 3. with one or more NA's? 4. that contain factors with

Re: [R] path analysis help

2012-08-30 Thread John Fox
Dear Jinsong, This model is grossly underidentified because there are no exogenous variables in it. Your inability to estimate the model isn't a software issue. Best, John --- John Fox Senator McMaster Professor of Social Statistics Department of

Re: [R] Identifying and Removing NA Columns and factor Columns with more than x Levels

2012-08-30 Thread Bert Gunter
If d is your data frame i1 - sapply(d,function(x)is.factor(x)length(levels(x))31) ## a vector of length ncol(d) that is TRUE only for factor columns with 31 levels i2 - sapply(d,function(x)any(is.na(x))) ## You can figure it out. -- Bert On Thu, Aug 30, 2012 at 8:38 AM, Lopez, Dan

Re: [R] help on plot on the log scale but showing original values on axis

2012-08-30 Thread Michael Weylandt
Possibly easier: plot(x, y, log = x) Cheers, Michael On Aug 30, 2012, at 5:47 AM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, The following is the general idea. x -c(0.25,0.5,1,2,4,8,16,32) y -c(1,1,1,1,0.9,0.8,0.6,0.2) plot(log(x),y,type=b, xaxt = n) axis(1, at = log(x), labels

Re: [R] apply -- data.frame

2012-08-30 Thread Sam Steingold
* Sam Steingold f...@tah.bet [2012-08-30 08:56:17 -0400]: Is there a way for an apply-type function to return a data frame? the closest thing I think of is foo - as.data.frame(t(sapply(...))) names(foo) - c() alas, this has a problem of creating a homogeneous data frame, i.e., all

Re: [R] apply -- data.frame

2012-08-30 Thread Bert Gunter
?lapply z -data.frame(a=1:3,b=letters[1:3]) lapply(z,[,1:2) $a [1] 1 2 $b [1] a b Levels: a b c data.frame(lapply(z,[,1:2)) ## Is this not what you want? a b 1 1 a 2 2 b You really should spend a little more time with the docs figuring out what R _does_ and a little less complaining

Re: [R] apply -- data.frame

2012-08-30 Thread David Winsemius
On Aug 30, 2012, at 9:44 AM, Sam Steingold wrote: * Sam Steingold f...@tah.bet [2012-08-30 08:56:17 -0400]: Is there a way for an apply-type function to return a data frame? the closest thing I think of is foo - as.data.frame(t(sapply(...))) names(foo) - c() alas, this has a problem

[R] knitr

2012-08-30 Thread Sven D
Hello, after trying to convert to pdf using knitr, I get the following error messages from the error log: C:/Users/duve/Documents/plots2.tex:5: LaTeX Error: Missing \begin{document}. See the LaTeX manual or LaTeX Companion for explanation. Type H return for immediate help You're in trouble

Re: [R] Deduping in R by multiple variables

2012-08-30 Thread ramoss
Thanks for your help guys. I was refering to the variables the wrong way. This worked for me: idx - !duplicated(detail2[,c(TDATE,FIRM,CM,BRANCH, BEGTIME, ENDTIME,OTYPE,OCOND, ACCTYP,OSIDE,SHARES,STOCKS, STKFUL)]) detail3 -

Re: [R] knitr

2012-08-30 Thread Yihui Xie
Can you post a reproducible example? Do you have \begin{document} in your Rnw file? Regards, Yihui -- Yihui Xie xieyi...@gmail.com Phone: 515-294-2465 Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA On Thu, Aug 30, 2012 at 10:35 AM, Sven D

Re: [R] apply -- data.frame

2012-08-30 Thread William Dunlap
Here are two ways of turning a character vector like yours into a data.frame, neither of which uses an apply-like function. s - c(XVI=p,16, XVII=q,17, XVIII=r,18) d1 - data.frame(Letter=sub(,.*, , s), Number=as.integer(sub(.*,,,s))) d2 - read.table(text=s, sep=,,

Re: [R] Bonferroni correction for multiple correlation tests

2012-08-30 Thread Michael Dewey
At 00:23 30/08/2012, Louise Cowpertwait wrote: Please can someone advise me how I can adjust correlations using bonferroni's correction? I am doing manny correlation tests as part of an investigation of the validity/reliability of a psychometric measure. Louise, apart from the excellent

Re: [R] random forest using party package

2012-08-30 Thread Bhupendrasinh Thakre
Have you tried to check memory limit. You may want to check Memory.limit() Although in most of the cases you can extend limit to 4000. Also as David mentioned try to run only r and force stop others. Best Regards, Bhupendrasinh Thakre Sent from my iPhone On Aug 30, 2012, at 10:02 AM, David

Re: [R] apply -- data.frame

2012-08-30 Thread Rui Barradas
Hello, Yet another alternative. library(plyr) dfr - ldply(strsplit(c(a,1, b,2, c,3), ,), identity) str(dfr) #dfr$V2 - as.numeric(dfr$V2) So, if the op was about conversion to df, the answer is yes. Rui Barradas Em 30-08-2012 18:14, David Winsemius escreveu: On Aug 30, 2012, at 9:44 AM,

Re: [R] Problem installing Rmpi with Open MPI

2012-08-30 Thread Dirk Eddelbuettel
On 29 August 2012 at 20:07, Linh Tran wrote: | Thank you for the advice. I tried using the command, and it still | wouldn't load. | | I tried uninstalling all of the MPI interfaces, reinstalled openmpi | using the --enabled-shared --disable-dlopen command, and Rmpi was able | to install

Re: [R] apply -- data.frame

2012-08-30 Thread Sam Steingold
* Bert Gunter thagre.ore...@trar.pbz [2012-08-30 09:59:46 -0700]: You really should spend a little more time with the docs figuring out what R _does_ and a little less complaining about what you think R cannot do. The only thing I think R cannot do is compact its memory, thus, effectively,

Re: [R] transform RTs

2012-08-30 Thread Matthias Gondan
you might to do something like library(SuppDists) t = runif(100, 100, 500) # original RT t_IG = qinvGauss(ecdf(t)(t)-0.5/length(t), 1, 16) plot(density(t_IG)) but what is the purpose of it? Usually reaction times are thought to follow a certain kind of distribution (e.g. an inverse Gaussian

Re: [R] Identifying and Removing NA Columns and factor Columns with more than x Levels

2012-08-30 Thread Lopez, Dan
Hi Bert, Thanks! These worked perfectly. mydata-mydata[,!(i1)] Dan -Original Message- From: Bert Gunter [mailto:gunter.ber...@gene.com] Sent: Thursday, August 30, 2012 8:54 AM To: Lopez, Dan Cc: R help (r-help@r-project.org) Subject: Re: [R] Identifying and Removing NA Columns and

Re: [R] Identifying and Removing NA Columns and factor Columns with more than x Levels

2012-08-30 Thread arun
Hi, For the first part in the two questions, do this: dat1-data.frame(Temp=c(5,10,9,15,NA,14,25,21,24,23,21,24,35,35,36,34,32,33),Temp2=c(5,10,9,15,15,14,25,21,24,23,21,24,35,35,36,34,32,33),Month=rep(c(January,February,March,April,May,June),each=3),Roof=as.factor(rep(1:6,times=3)))  

[R] self-defined distance function to be computed on matrix

2012-08-30 Thread zz
Hello, I have a self-defined function to be computed on each column in a matrix. The basic idea is to ignore the elements that have value of 0 during computation. I should be able to write my own function but it could be computational expensive, so I'd love to ask if anyone may have

Re: [R] segfault in gplots::heatmap.2

2012-08-30 Thread R. Michael Weylandt
On Thu, Aug 30, 2012 at 2:30 AM, Andreas Leha andreas.l...@med.uni-goettingen.de wrote: Hi all, I experience a segfault when calling gplots::heatmap.2(), but only when certain other packages are loaded. I am not sure for the correct place to send this bug report. Should I send it to the

Re: [R] self-defined distance function to be computed on matrix

2012-08-30 Thread R. Michael Weylandt
Hi zz, The help file for the dist() function ( ?dist) says that Missing values are allowed, and are excluded from all computations involving the rows within which they occur so if you can cajole this into any of the standard distance metrics, you could do something like: x[x == 0] - NA

Re: [R] apply -- data.frame

2012-08-30 Thread Sam Steingold
* William Dunlap jqha...@gvopb.pbz [2012-08-30 17:35:08 +]: I don't agree with your analysis of what went wrong with your example a double conversion: from number to string first (by c()) and then back. I did not make myself quite clear, sorry. I should have written something like c(1,2,a)

Re: [R] self-defined distance function to be computed on matrix

2012-08-30 Thread Peter Langfelder
On Thu, Aug 30, 2012 at 10:48 AM, zz czh...@uams.edu wrote: Hello, I have a self-defined function to be computed on each column in a matrix. The basic idea is to ignore the elements that have value of 0 during computation. I should be able to write my own function but it could be

Re: [R] Which BUGS should one use?

2012-08-30 Thread Seref Arikan
Hi Petar, I've tried to build a model with WinBugs and found out that there is a limit related to defining variables with discrete distributions. Sorry I can't remember the details but I think it did not support more than 5 discrete variables as parent of another variable or something like that.

Re: [R] Which BUGS should one use?

2012-08-30 Thread R. Michael Weylandt
Whit Armstrong is building a R-centric BUGS (RcppBugs) which looks very powerful as well: you might talk to him about it. www.rinfinance.com/agenda/2012/talk/WhitArmstrong.pdf https://github.com/armstrtw/rcppbugs Cheers, Michael On Thu, Aug 30, 2012 at 3:12 PM, Seref Arikan

Re: [R] predict.lm(...,type=terms) question

2012-08-30 Thread David Winsemius
On Aug 30, 2012, at 2:29 PM, John Thaden wrote: Dave said my newdata data frame 'new' must have a column named 'area'. It did. Nonetheless predict.lm throws an error with type = terms and newdata = new. I see nothing in the predict.lm documentation that bars this usage. Is there a bug?

Re: [R] predict.lm(...,type=terms) question

2012-08-30 Thread John Thaden
Dave said my newdata data frame 'new' must have a column named 'area'. It did. Nonetheless predict.lm throws an error with type = terms and newdata = new. I see nothing in the predict.lm documentation that bars this usage. Is there a bug? To illustrate an OLS behavior, I had cited Ludbrook '12.

[R] How to modify the values of the parameters passing via ...

2012-08-30 Thread Zhiqiu Hu
Dear Friends, Let's assume there are three parameters that were passed into fun1. In fun1, we need to modify one para but the remains need to be untouched. And then all parameters were passed into fun2. However, I have failed to achieve it. Please see the following code.

Re: [R] self-defined distance function to be computed on matrix

2012-08-30 Thread zz
Thank you all for the quick responses. Setting 0 with *NA* is the right thing to do. Also Peter, thanks to your package, using the command 'cos - cor(m,method='pearson',cosine=TRUE,use='p')' you mentioned' makes my life a lot more easier. zz -- View this message in context:

[R] storage mode error question (R2winBUGS)

2012-08-30 Thread Alejandro Pietrek
Hi all, I've been trying to run a model using R2winBUGS, and recurrently I get the message: Error in FUN(X[[3L]], ...) : invalid to change the storage mode of a factor My model is the following: sink(GLMM_Poisson.txt) cat( model{ mu~dnorm(0,0.01) beta1~dnorm(-1,1) for(j in

Re: [R] How to modify the values of the parameters passing via ...

2012-08-30 Thread Rui Barradas
Hello, You could see what is fun1 receiving with this modification meant for debugging: fun1 -function(x, y, z=10){ print(match.call()) x + y + z } Anyway, there is s standard way of dealing with argument '...' when one needs to know what was passed. Include dots - list(...) at the

[R] fitting lognormal censored data

2012-08-30 Thread Salma Wafi
Hi , I am trying to get some estimator based on lognormal distribution when we have left,interval, and right censored data. Since, there is now avalible pakage in R can help me in this, I had to write my own code using Newton Raphson method which requires first and second derivative of log

[R] dynamic list in aggregate()

2012-08-30 Thread Xianming Wei
Hi all, How can I have a dynamic list for different combinations of grouping factors in the following example? Thanks. dat - data.frame(x=rnorm(100), a=sample(letters[1:5], replace = T), b=sample(letters[1:5], replace = T),

Re: [R] dynamic list in aggregate()

2012-08-30 Thread William Dunlap
Replace lst - paste('dat$', grp, sep='', collapse =',') aggregate(dat$x, list(lst), mean) with aggregate(dat$x, dat[grp], mean) The 'by' argument to aggregate should be a list and data.frames (like dat and dat[grp]) are lists. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com