Re: [R] read table problem
Files save()d in R should be read back with load(). .RData or .rda are common extensions for such files. On Fri, 24 Feb 2006, Chua Tock Hing wrote: Hi I have a file saved in R, named agrexp.Rdata, shown below agrdata fert yield 1 2584 2 5080 3 7590 4 100 154 5 125 148 If I double clicked on this file, the data is displayed without problem. However if I tried to import using: agrdata-read.table(agrexp.Rdata) or agrdata-read.table(agrexp.Rdata,header=TRUE) or agrdata-read.table(agrexp.Rdata,header=TRUE,row.names=1) or agrdata-read.table(agrexp.Rdata,sep=) I get an error message Warning message: incomplete final line found by readTableHeader on 'agrexp.Rdata' or if I used: data(agrexp) I get Warning message: data set 'agrexp' not found in: data(agrexp) Can anybody please help? I am a new user! Thank you CHUA TH [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] converting character matrix to a dataframe
On Fri, 24 Feb 2006, Prof Brian Ripley wrote: It is a bit more efficient to use as.data.frame in your apply. You could make a copy of as.data.frame.matrix (under another name) and remove the special-casing of character matrices. This would efficiently give you a data frame with character columns, but they would then not be treated 'AsIs' in subsequent manipulations. So this is only desirable if efficiency is really important (and it seems unlikely to me that it is). On Thu, 23 Feb 2006, John M. Miyamoto wrote: Dear R-Help, Suppose I have a character matrix, e.g., (ch.mat - matrix(c('a','s','*','f','w','*','k','*','*','f','i','o'), ncol=3)) When I convert 'ch.mat' to a dataframe, the columns are converted to factors: [SNIP] The following code is reasonably efficient even if the matrix has arbitrarily many columns. (d3 - data.frame(apply(ch.mat,2,function(x) data.frame(I(x) mode(d3[,1]) is.factor(d3[,1]) Question: Is there a more efficient method than the last one for converting a character matrix to a dataframe while preventing the automatic conversion of the column vectors to factors? So I take it that this last solution would be: (ch.mat - matrix(c('a','s','*','f','w','*','k','*','*','f','i','o'), ncol=3)) (d4 - data.frame(apply(ch.mat, 2, function(x) as.data.frame(I(x) mode(d4[,1]) is.factor(d4[,1]) You're right that I'm not really concerned with computational efficiency, but only minimizing the amount of code that I have to write and remember. The solution seems to be that I should write a function that accomplishes this task, which I have done. Thank you. John __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] importing data from BUGS format to R?
On Fri, 2006-02-24 at 08:48 +0100, Uwe Ligges wrote: Gabor Grothendieck wrote: Just source the file: source(mywinbugsfile.R) head(y) ... and don't forget to transpose the matrix afterwards, if this was BUGS code. Uwe Ligges If this were a WinBUGS data file (or initial values file), the whole expression would be wrapped in a call to list(). In this case, you would need to assign the output from source(), or use the dget() function, e.g. for the EPILEPSY example: mydata - dget(epildata.txt) names(mydata) [1] NTyTrt Base Age V4 mydata$T [1] 4 But, as Uwe points out, arrays will need to be reorganized, as WinBUGS fills matrices by row rather than column. head(mydata$y) #wrong! [,1] [,2] [,3] [,4] [1,]5997 [2,]3 1146 [3,]3007 [4,]3041 [5,]3531 [6,]5002 I wrote a function called bugs2jags, which you will find in the coda package, for converting WinBUGS data files into the data format used by JAGS which is, by no coincidence, the format used by the R function dump(). library(coda) Loading required package: lattice bugs2jags(epildata.txt,epildata.R) #Creates file epildata.R source(epildata.R) ls() [1] Age Base NTTrt V4 y This creates objects in your work space, and sorts out the arrays head(y) #right [,1] [,2] [,3] [,4] [1,]5333 [2,]3533 [3,]2405 [4,]4414 [5,]7 189 21 [6,]5287 Martyn On 2/23/06, Jeffrey Moore [EMAIL PROTECTED] wrote: For those who use WinBUGS (or for those who are just familar with this format), I have a text file that looks like this (which is how R would export data if you used the structure function): y= structure(.Data= c(-6.93310E+01, 4.32870E+01, -6.96600E+01, 4.35730E+01, -6.90150E+01, 4.35870E+01, -5.81060E+01, 4.52890E+01, -6.65590E+01, 4.34600E+01, -6.61850E+01, 4.35000E+01, -6.54130E+01, 4.31940E+01, -6.42790E+01, 4.34780E+01, -6.35520E+01, 4.38070E+01, -6.32980E+01, 4.39520E+01, -6.25690E+01, 4.41760E+01, -6.20810E+01, 4.40800E+01, -6.14280E+01, 4.46210E+01, -6.10530E+01, 4.48050E+01, -6.00300E+01, 4.50480E+01, -5.88110E+01, 4.50280E+01, -5.83660E+01, 4.50400E+01, -5.83140E+01, 4.48780E+01, -5.87330E+01, 4.50340E+01, -5.87430E+01, 4.51630E+01, -5.88170E+01, 4.54030E+01, -5.89380E+01, 4.53260E+01, -5.89110E+01, 4.55260E+01, NA, NA, -5.91250E+01, 4.56070E+01, -5.90140E+01, 4.59690E+01, -5.89830E+01, 4.64640E+01, -5.89240E+01, 4.66300E+01, -5.93770E+01, 4.66810E+01, -5.90010E+01, 4.65640E+01, -5.91230E+01, 4.67780E+01, -5.92350E+01, 4.7E+01, -5.92310E+01, 4.68350E+01, NA, NA, -5.88530E+01, 4.68560E+01, NA, NA, NA, NA, NA, NA, -5.83550E+01, 4.65300E+01, -5.83270E+01, 4.64970E+01, -5.86210E+01, 4.65320E+01, NA, NA, -5.82720E+01, 4.65060E+01, -5.81480E+01, 4.64490E+01, -5.83350E+01, 4.63650E+01, NA, NA, -5.84800E+01, 4.63340E+01, -5.83980E+01, 4.63040E+01, -5.83390E+01, 4.62030E+01, -5.82170E+01, 4.62620E+01, NA, NA, -5.80420E+01, 4.61940E+01, -5.80360E+01, 4.57280E+01, -5.80590E+01, 4.55420E+01, -5.83010E+01, 4.54730E+01, -5.83710E+01, 4.55010E+01, -5.86540E+01, 4.52870E+01, -5.87020E+01, 4.51740E+01, -5.87400E+01, 4.52620E+01, -5.88330E+01, 4.53190E+01, -5.89740E+01, 4.53410E+01, NA, NA, -5.85240E+01, 4.54970E+01, -5.81710E+01, 4.56200E+01, -5.79070E+01, 4.58370E+01, NA, NA, -5.73610E+01, 4.62660E+01, -5.71820E+01, 4.60770E+01, -5.70540E+01, 4.59920E+01, NA, NA, NA, NA, -5.58460E+01, 4.51830E+01, -5.53690E+01, 4.52890E+01, -5.49260E+01, 4.53340E+01, -5.40070E+01, 4.53670E+01, -5.35510E+01, 4.54510E+01, NA, NA, -5.15130E+01, 4.63060E+01, -5.15000E+01, 4.63280E+01, -5.08410E+01, 4.67780E+01, -4.99400E+01, 4.69670E+01, -4.88440E+01, 4.72810E+01, -4.87250E+01, 4.76880E+01, -4.70460E+01, 4.87420E+01, -5.17870E+01, 4.83990E+01, -4.68830E+01, 4.97030E+01, -4.73700E+01, 5.03350E+01, -4.75990E+01, 5.10690E+01, -5.15050E+01, 5.05110E+01, -4.80640E+01, 5.19200E+01, -4.83890E+01, 5.27580E+01, NA, NA, -4.85200E+01, 5.41250E+01, -4.87630E+01, 5.53650E+01, NA, NA, -4.84790E+01, 5.70560E+01, -4.82690E+01, 5.77990E+01, -4.77870E+01, 5.87570E+01, -4.74070E+01, 5.96700E+01, -4.76990E+01, 6.02020E+01, -4.82110E+01, 6.03410E+01, -4.90240E+01, 6.05510E+01, -4.89050E+01, 6.06780E+01, -4.80660E+01, 6.05380E+01, -4.61030E+01, 6.01290E+01, NA, NA, -4.59880E+01, 6.02070E+01, -4.55240E+01, 5.99680E+01, -4.59540E+01, 5.97650E+01, -4.58830E+01, 5.98200E+01, -4.64730E+01, 6.00690E+01, -4.64660E+01, 6.00730E+01, -4.59630E+01, 5.99330E+01, -4.63940E+01, 6.01380E+01, -4.64370E+01, 6.02270E+01, -4.67750E+01, 6.04410E+01, -4.68020E+01, 6.04700E+01, -4.57440E+01, 5.97720E+01, -4.48480E+01, 5.96590E+01, -4.50540E+01, 5.97830E+01), .Dim=c(120, 2)) I would like to read this into R as an 120x2
[R] R script autoload at startup
Hello; I'm now using mainly R for windows, mainly because I'm writing a tcl/Tk interface for some people, and I've got two questions. I'm an absolute beginner with tctk or tcktk use under the R GUI. 1) Is it posible to create a shorcut that launchs the R GUI and automatically reads the source code of the tcl/tk script to also launch the tcltk interface? 2) Is the RGUI programmed with tcltk? In this case, is it possible for an user like me to create a menu entry at the R GUI to call the source code in this R/tcl/Tk script? Any of the two options would be very good for us. Thanks and best regards, Javier __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Extracting information from factanal()
Dear list members, I apologize for putting this (probably) very basic question on the mailing list. I have scanned through the R website (using search) but did not found an answer. (code included below) A factor matrix is simply extracted (which can then subsequently be exported using write.table) by FACT$loadings[1:6,]. I would also like to specifically extract and export proportion var, but unfortunately are not succesful after attempting different ways (str(FACT) did not help me). Any suggestions/comments are appreciated. Kind regards, Robin Smit FACT - factanal(HATCO, 2, rotation = none) FACT Call: factanal(x = HATCO, factors = 2, rotation = none) Uniquenesses: x1x2x3x4x6x7 0.498 0.568 0.477 0.111 0.298 0.526 Loadings: Factor1 Factor2 x1 0.709 x2 0.326 -0.570 x3 -0.166 0.704 x4 0.941 x6 0.829 0.118 x7 0.267 -0.634 Factor1 Factor2 SS loadings 1.778 1.743 Proportion Var 0.296 0.291 Cumulative Var 0.296 0.587 Test of the hypothesis that 2 factors are sufficient. The chi square statistic is 3.98 on 4 degrees of freedom. The p-value is 0.409 This e-mail and its contents are subject to the DISCLAIMER at http://www.tno.nl/disclaimer/email.html [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] 2 barplots in the same graph
Thanks All! I combine your answers and post the code here again, if later somebody need it. Actually, what I want is: x1 [1] 1 2 10 x2 [1] -3 5 -8 barplot(x1,col=white,border=red) barplot(x2,col=white,border=green,add=T) So that, the two plots even share the same x-axis. But, It comes another question: barplot(x2,col=white,border=green,add=T), because there are 2 numbers are negative, some part of the bar is missing. Is there any automatic function to make the axes fit very well for both bars? And, suppose I want to add another command: axis(1, 0:20) to draw x-axis. I notice it increase like: 0,1,2,3,...20; how can I make it 0,5,15,20? Thanks! On 2/22/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: The barplot solution already presented is probably what you want but just in case here is a zoo solution: library(zoo) z - merge(zoo(x2), zoo(x1, seq(x1)+.5)) plot(z, type = h, plot.type = single, col = 1:2, lwd = 5) Or a similar solution without zoo: plot(c(x1, x2) ~ c(seq(x1)+.5, seq(x2)), col = c(1+0*x1, 2+0*x2), type = h, lwd = 5) On 2/22/06, jia ding [EMAIL PROTECTED] wrote: Hello, I have a very simple question about 2 barplots in the same graph. It seems quite easy, but I searched google for long time, haven't find solution. For example, I want one graph like: x1=seq(0,2,by=0.3) x2=seq(3,0,by=-0.1) barplot(x1,col=red) barplot(x2,col=green) It means if it's on the same graph, some bars are overlaped. So if the bars are hollow, instead of filled with color, it will be better. Actually, I think it's something similar with matlab's hold on command. Thanks! Nina [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] does multinomial logistic model from multinom (nnet) has logLik?
I should ues Not obvious instead of invalid, this is my mistake. 2006/2/24, Prof Brian Ripley [EMAIL PROTECTED]: Please note, I told you that the deviance was minus twice log-likelihood unless summ 0. I had not checked the latter case, where it is not obvious, but I did not say it was invalid. In fact the answer is to be found on p.203 of MASS4 (we do ask people to read the supporting documentation), and this is valid also for summ 0. I did read the help page in nnet.And MASS4 is not avaivable just now :( I will check that when I can. I will add a comment to the help file. appreciate! On Wed, 22 Feb 2006, ronggui wrote: Here is a function for calculating the measures of fit for multinomial logistic model (using nnet::multinom).If anything wrong ,I hope experts point it out.Thank you. fitstat - function(object) { #thanks Ripley, B. D. for telling how to get the LogLik and when is not obvious. {if (!is.null(object$call$summ) !identical(object$call$summ,0)) stop(when 'summ' argument is not zero,can NOT get Loglik) } object.base - update(object,.~1,trace=FALSE) dev.base - deviance(object.base) ; L.base - - dev.base/2 dev.full - deviance(object) ; L.full - - dev.full/2 G2 - dev.base - dev.full df - object$edf - object.base$edf LR.test.p - pchisq(G2,df,lower=F) aic - object$AIC n-dim(object$residuals)[1] #get the predict value to cal count R2 pre - predict(object,type=class) y - eval.parent(object$call$data)[,as.character(object$call$formula[[2]])] if (!identical(length(y),length(pre))) stop(Length not matched.) tab - table(y,pre) if (!identical(dim(tab)[1],dim(tab)[2])) stop(pred and y have diff nlevels) ad - max(rowSums(tab))#max of row sum #cal R2 ML.R2 - 1-exp(-G2/n) McFadden.R2 - 1-(L.full/L.base) McFadden.Adj.R2 - 1-((L.full-mod$edf)/L.base) Cragg.Uhler.R2 - ML.R2/(1-exp(2*L.base/n)) Count.R2 - sum(diag(tab))/sum(tab) Count.adj.R2 - (sum(diag(tab))-ad)/(sum(tab)-ad) #get the result res-list(LR=G2,df=df,LR.test.p =LR.test.p ,aic=aic,ML.R2=ML.R2,Cragg.Uhler.R2=Cragg.Uhler.R2,McFadden.R2 =McFadden.R2 ,McFadden.Adj.R2=McFadden.Adj.R2,Count.R2=Count.R2,Count.adj.R2=Count.adj.R2) #print the result cat(\n, paste(rep(-,21)), \n The Fitstats are : \n, sprintf(G2(%d) = %f,df,G2), ,Prob ,format.pval(LR.test.p), \n,sprintf(AIC = %f,aic), sprintf(,ML.R2 = %f \n,ML.R2), paste(rep(-,21)),\n, sprintf(Cragg.Uhler.R2 = %f \n,Cragg.Uhler.R2), sprintf(McFadden.R2 = %f \n,McFadden.R2), sprintf(McFadden.Adj.R2 = %f \n,McFadden.Adj.R2), sprintf(Count.R2= %f \n,Count.R2), sprintf(Count.adj.R2= %f \n,Count.adj.R2), \n Note:The maxinum of ML R2 is less than 1 \n, paste(rep(-,21)),\n) invisible(res) } #example require(nnet) data(mexico,package=Zelig) mod - multinom(vote88 ~ pristr + othcok + othsocok,mexico) summary(mod,cor=F) fitstat(mod) #reference: #J. SCOTT LONG and JEREMY FREESE,REGRESSION MODELS FOR CATEGORICAL DEPENDENT VARIABLES USING STATA. fitstat(mod) - - - - - - - - - - - - - - - - - - - - - The Fitstats are : G2(6) = 381.351620 ,Prob 2.22e-16 AIC = 2376.571142 ,ML.R2 = 0.244679 - - - - - - - - - - - - - - - - - - - - - Cragg.Uhler.R2 = 0.282204 McFadden.R2 = 0.139082 McFadden.Adj.R2 = 0.133247 Count.R2= 0.596026 Count.adj.R2= 0.123003 Note:The maxinum of ML R2 is less than 1 - - - - - - - - - - - - - - - - - - - - - 在 06-2-22,ronggui[EMAIL PROTECTED] 写道: So it's valid to get logLik (deviance/-2) when the summ argument is unused? Thank you. 2006/2/22, Prof Brian Ripley [EMAIL PROTECTED]: On Wed, 22 Feb 2006, ronggui wrote: I want to get the logLik to calculate McFadden.R2 ,ML.R2 and Cragg.Uhler.R2, but the value from multinom does not have logLik.So my quetion is : is logLik meaningful to multinomial logistic model from multinom?If it does, how can I get it? From the help page: Value: A 'nnet' object with additional components: deviance: the residual deviance. So it has a residual deviance. That is -2 log Lik in many cases (but not if the argument 'summ' is used) Thank you! ps: I konw VGAM has function to get the multinomial logistic model with logLik, but I prefer use the function from official R packages . -- ronggui Deparment of Sociology Fudan University -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 -- 黄荣贵 Deparment of Sociology Fudan University -- ronggui Deparment of Sociology Fudan University -- Brian D. Ripley, [EMAIL PROTECTED]
Re: [R] 2 barplots in the same graph
Le 24.02.2006 11:17, jia ding a écrit : Thanks All! I combine your answers and post the code here again, if later somebody need it. Actually, what I want is: x1 [1] 1 2 10 x2 [1] -3 5 -8 barplot(x1,col=white,border=red) barplot(x2,col=white,border=green,add=T) So that, the two plots even share the same x-axis. But, It comes another question: barplot(x2,col=white,border=green,add=T), because there are 2 numbers are negative, some part of the bar is missing. Is there any automatic function to make the axes fit very well for both bars? R barplot(x1,col=white,border=red, ylim=range(c(x1,x2))) And, suppose I want to add another command: axis(1, 0:20) to draw x-axis. I notice it increase like: 0,1,2,3,...20; how can I make it 0,5,15,20? before doing axis(1, 0:20) have you tried to do R 0:20 So, R axis(1, (0:4)*5) or R axis(1, c(0,5, 10, 15, 20)) or R axis(1, seq(0,20, by=5)) it's up to you. There are probably other solutions as well Thanks! You're welcome Romain -- visit the R Graph Gallery : http://addictedtor.free.fr/graphiques Discover the R Movies Gallery : http://addictedtor.free.fr/movies +---+ | Romain FRANCOIS - http://francoisromain.free.fr | | Doctorant INRIA Futurs / EDF | +---+ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] [R-pkgs] New `party' tools
Dear useRs, Version 0.8-1 of the `party' package will appear on CRAN and its mirrors in due course. This version implements two new tools: o `mob', an object-oriented implementation of a recently suggested algorithm for model-based recursive partitioning (Zeileis, Hothorn, Hornik, 2005) has been added. It works out of the box for partitioning (generalized) linear regression models, others can be easily plugged in. A new vignette MOB describes the implementation ideas and provides a few examples with nice plots. o `cforest', an implementation of Breiman's random forest ensemble algorithm based on conditional inference trees (`ctree') has been added and can be used to analyse censored data and weighted problems. Moreover, some minor issues have been addressed and are documented in the CHANGES file. Best wishes, Torsten, Kurt and Achim. ___ R-packages mailing list [EMAIL PROTECTED] https://stat.ethz.ch/mailman/listinfo/r-packages __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] 2 barplots in the same graph
Hi, Would you pls try these? x1-c(1,2,10) x2-c(-3,5,-8) barplot(x1,col=white,border=red,ylim=range(c(x1,x2))) barplot(x2,col=white,border=green,ylim=range(c(x1,x2)),add=T) axis(1, 0:3) box() Q1, on x-axis 1,2,3 is not shown at the middle position of the bars. e.gfor first bar, 1 is tend to right ; while third bar, 3 is tend to left. Q2, once box(), then bars are cut again. Q3, when y-axis is 0, I want to draw a parallel line to x-axis: I tried lines(c(0,5),c(0,0)) ; is there any other way to do it? Thanks. Nina On 2/24/06, Romain Francois [EMAIL PROTECTED] wrote: Le 24.02.2006 11:17, jia ding a écrit : Thanks All! I combine your answers and post the code here again, if later somebody need it. Actually, what I want is: x1 [1] 1 2 10 x2 [1] -3 5 -8 barplot(x1,col=white,border=red) barplot(x2,col=white,border=green,add=T) So that, the two plots even share the same x-axis. But, It comes another question: barplot(x2,col=white,border=green,add=T), because there are 2 numbers are negative, some part of the bar is missing. Is there any automatic function to make the axes fit very well for both bars? R barplot(x1,col=white,border=red, ylim=range(c(x1,x2))) And, suppose I want to add another command: axis(1, 0:20) to draw x-axis. I notice it increase like: 0,1,2,3,...20; how can I make it 0,5,15,20? before doing axis(1, 0:20) have you tried to do R 0:20 So, R axis(1, (0:4)*5) or R axis(1, c(0,5, 10, 15, 20)) or R axis(1, seq(0,20, by=5)) it's up to you. There are probably other solutions as well Thanks! You're welcome Romain -- visit the R Graph Gallery : http://addictedtor.free.fr/graphiques Discover the R Movies Gallery : http://addictedtor.free.fr/movies +---+ | Romain FRANCOIS - http://francoisromain.free.fr | | Doctorant INRIA Futurs / EDF | +---+ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] 2 barplots in the same graph
Le 24.02.2006 11:58, jia ding a écrit : Hi, Would you pls try these? x1-c(1,2,10) x2-c(-3,5,-8) barplot(x1,col=white,border=red,ylim=range(c(x1,x2))) barplot(x2,col=white,border=green,ylim=range(c(x1,x2)),add=T) axis(1, 0:3) box() ylim is not needed on the second call. Q1, on x-axis 1,2,3 is not shown at the middle position of the bars. e.g for first bar, 1 is tend to right ; while third bar, 3 is tend to left. Use the outputs from barplot : out - barplot(x1,col=white,border=red,ylim=extendrange(c(x1,x2))) out axis(1, out[,1], sprintf('bar %d', 1:3)) Q2, once box(), then bars are cut again. You can use extendrange instead of range, ie : barplot(x1,col=white,border=red,ylim=extendrange(c(x1,x2))) Q3, when y-axis is 0, I want to draw a parallel line to x-axis: I tried lines(c(0,5),c(0,0)) ; is there any other way to do it? abline(h=0) Thanks. Nina Also, try : ?barplot http://addictedtor.free.fr/graphiques/search.php?q=barplot Romain -- visit the R Graph Gallery : http://addictedtor.free.fr/graphiques Discover the R Movies Gallery : http://addictedtor.free.fr/movies +---+ | Romain FRANCOIS - http://francoisromain.free.fr | | Doctorant INRIA Futurs / EDF | +---+ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Extracting information from factanal()
For the loadings, please use the loadings() accessor function. It is loadings print method that is giving you the proportion var, not factanal(). So to use a reproducible example example(factanal) fit - factanal(m1, factors = 3) (ld - loadings(fit)) Loadings: Factor1 Factor2 Factor3 v1 0.944 0.182 0.267 v2 0.905 0.235 0.159 v3 0.236 0.210 0.946 v4 0.180 0.242 0.828 v5 0.242 0.881 0.286 v6 0.193 0.959 0.196 Factor1 Factor2 Factor3 SS loadings 1.893 1.886 1.797 Proportion Var 0.316 0.314 0.300 Cumulative Var 0.316 0.630 0.929 and look at S3method(print, loadings) to see how it does that. (It calculates the summary table, not extracts the values.) On Fri, 24 Feb 2006, Smit, R. (Robin) wrote: Dear list members, I apologize for putting this (probably) very basic question on the mailing list. I have scanned through the R website (using search) but did not found an answer. (code included below) A factor matrix is simply extracted (which can then subsequently be exported using write.table) by FACT$loadings[1:6,]. I would also like to specifically extract and export proportion var, but unfortunately are not succesful after attempting different ways (str(FACT) did not help me). Any suggestions/comments are appreciated. Kind regards, Robin Smit FACT - factanal(HATCO, 2, rotation = none) FACT Call: factanal(x = HATCO, factors = 2, rotation = none) Uniquenesses: x1x2x3x4x6x7 0.498 0.568 0.477 0.111 0.298 0.526 Loadings: Factor1 Factor2 x1 0.709 x2 0.326 -0.570 x3 -0.166 0.704 x4 0.941 x6 0.829 0.118 x7 0.267 -0.634 Factor1 Factor2 SS loadings 1.778 1.743 Proportion Var 0.296 0.291 Cumulative Var 0.296 0.587 Test of the hypothesis that 2 factors are sufficient. The chi square statistic is 3.98 on 4 degrees of freedom. The p-value is 0.409 This e-mail and its contents are subject to the DISCLAIMER at http://www.tno.nl/disclaimer/email.html [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] RGtk2 install in Mac
Dear R-list, I'm struggling installing RGtk2 on my Mac. Has anybody succeeded in doing so? I've got Gtk2.8 (finally) and I have R2.0.1 I'm using ibook G4 and Mac 10.3.9 and here is the error I got from installing R CMD INSTALL ~/Desktop/install/RGtk2_2.8.0-0.tar.gz * Installing *source* package 'RGtk2' ... checking for pkg-config... /sw/bin/pkg-config checking pkg-config is at least version 0.9.0... yes checking for GTK... yes checking for LIBGLADE... yes checking for GTKMOZEMBED... configure: WARNING: firefox-gtkmozembed not found configure: creating ./config.status config.status: creating src/Makevars ** libs gcc -no-cpp-precomp -I/Library/Frameworks/R.framework/Resources/include -I/usr/local/include -g -D_R_=1 -DUSE_R=1 -I/usr/local/include/gtk-2.0 -I/usr/local/lib/gtk-2.0/include -I/usr/local/include/atk-1.0 -I/usr/local/include/cairo -I/usr/local/include/pango-1.0 -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/local/include/libglade-2.0 -I/usr/local/include/gtk-2.0 -I/usr/local/include/libxml2 -I/usr/local/lib/gtk-2.0/include -I/usr/local/include/atk-1.0 -I/usr/local/include/cairo -I/usr/local/include/pango-1.0 -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/Library/Frameworks/R.framework/Resources/include -DHAVE_LIBGLADE -fno-common -g -O2 -c RGtkDataFrame.c -o RGtkDataFrame.o .. gcc -no-cpp-precomp -I/Library/Frameworks/R.framework/Resources/include -I/usr/local/include -g -D_R_=1 -DUSE_R=1 -I/usr/local/include/gtk-2.0 -I/usr/local/lib/gtk-2.0/include -I/usr/local/include/atk-1.0 -I/usr/local/include/cairo -I/usr/local/include/pango-1.0 -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/local/include/libglade-2.0 -I/usr/local/include/gtk-2.0 -I/usr/local/include/libxml2 -I/usr/local/lib/gtk-2.0/include -I/usr/local/include/atk-1.0 -I/usr/local/include/cairo -I/usr/local/include/pango-1.0 -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/Library/Frameworks/R.framework/Resources/include -DHAVE_LIBGLADE -fno-common -g -O2 -c conversion.c -o conversion.o conversion.c: In function `asCRaw': conversion.c:49: error: subscripted value is neither array nor pointer conversion.c: In function `asRRaw': conversion.c:87: warning: assignment makes pointer from integer without a cast conversion.c:88: error: subscripted value is neither array nor pointer make: *** [conversion.o] Error 1 ERROR: compilation failed for package 'RGtk2' ** Removing '/Library/Frameworks/R.framework/Versions/2.0.1/Resources/library/ RGtk2' ** Restoring previous '/Library/Frameworks/R.framework/Versions/2.0.1/Resources/library/ RGtk2' Any suggestions would be helpful. Thanks ___ Zhesi He S-Block Biology, YCCSA, University of York York YO10 5YW, U.K. Phone: +44-(0)1904-328554 Email: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Ranking within factor subgroups
Thank you! I did not know about the split and unsplit functions. It looks like a very powerful and useful combination to master. Regards, Adai On Thu, 2006-02-23 at 07:28 +0100, Peter Dalgaard wrote: maneesh deshpande [EMAIL PROTECTED] writes: Hi Adai, I think your solution only works if the rows of the data frame are ordered by date and the ordering function is the same used to order the levels of factor(df$date) ? It turns out (as I implied in my question) my data is indeed organized in this manner, so my current problem is solved. In the general case, I suppose, one could always order the data frame by date before proceeding ? Thanks, Maneesh You might prefer to look at split/unsplit/split-, i.e. the z-scores by group line: z - unsplit(lapply(split(x, g), scale), g) with scale suitably replaced. Presumably (meaning: I didn't quite read your code closely enough) z - unsplit(lapply(split(x, g), bucket, 10), g) could do it. From: Adaikalavan Ramasamy [EMAIL PROTECTED] Reply-To: [EMAIL PROTECTED] To: maneesh deshpande [EMAIL PROTECTED] CC: r-help@stat.math.ethz.ch Subject: Re: [R] Ranking within factor subgroups Date: Wed, 22 Feb 2006 03:44:45 + It might help to give a simple reproducible example in the future. For example df - cbind.data.frame( date=rep( 1:5, each=100 ), A=rpois(500, 100), B=rpois(500, 50), C=rpois(500, 30) ) might generate something like date A B C 11 93 51 32 21 95 51 30 31 102 59 28 41 105 52 32 51 105 53 26 61 99 59 37 .... ... .. .. 4955 100 57 19 4965 96 47 44 4975 111 56 35 4985 105 49 23 4995 105 61 30 5005 92 53 32 Here is my proposed solution. Can you double check with your existing functions to see if they are correct. decile.fn - function(x, nbreaks=10){ br - quantile( x, seq(0, 1, len=nbreaks+1), na.rm=T ) br[1] - -Inf return( cut(x, br, labels=F) ) } out - apply( df[ ,c(A, B, C)], 2, function(v) unlist( tapply( v, df$date, decile.fn ) ) ) rownames(out) - rownames(df) out - cbind(df$date, out) Regards, Adai On Tue, 2006-02-21 at 21:44 -0500, maneesh deshpande wrote: Hi, I have a dataframe, x of the following form: DateSymbol AB C 20041201 ABC 10 12 15 20041201 DEF 95 4 ... 20050101 ABC 5 3 1 20050101 GHM 12 42 here A, B,C are properties of a set symbols recorded for a given date. I wante to decile the symbols For each date and property and create another set of columns bucketA,bucketB, bucketC containing the decile rank for each symbol. The following non-vectorized code does what I want, bucket - function(data,nBuckets) { q - quantile(data,seq(0,1,len=nBuckets+1),na.rm=T) q[1] - q[1] - 0.1 # need to do this to ensure there are no extra NAs cut(data,q,include.lowest=T,labels=F) } calcDeciles - function(x,colNames) { nBuckets - 10 dates - unique(x$Date) for ( date in dates) { iVec - x$Date == date xx - x[iVec,] for (colName in colNames) { data - xx[,colName] bColName - paste(bucket,colName,sep=) x[iVec,bColName] - bucket(data,nBuckets) } } x } x - calcDeciles(x,c(A,B,C)) I was wondering if it is possible to vectorize the above function to make it more efficient. I tried, rlist - tapply(x$A,x$Date,bucket) but I am not sure how to assign the contents of rlist to their appropriate slots in the original dataframe. Thanks, Maneesh __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Sorting a dataframe by one column?
Given the following dataframe: A=1:10 B=(a-5)^2 DATAFRAME=data.frame(A,B) How can I sort DATAFRAME increasing (or decreasing, for that matter) by B without making reference to A, or any other column? I've read ?order and ?sort but cannot seem to figure this out. Thank you. Mark __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] SE of parameter estimates in glmm.admb
Dear R users, Does anyone know how to get standard errors of the parameter estimates in glmm.admb? Thanks, Istvan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Sorting a dataframe by one column?
You mean like this? a-1:10 b-(a-5)^2 d-data.frame(a,b) d[order(d$b),] ?? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of mtb954 mtb954 Sent: 24 February 2006 13:55 To: r-help@stat.math.ethz.ch Subject: [R] Sorting a dataframe by one column? Given the following dataframe: A=1:10 B=(a-5)^2 DATAFRAME=data.frame(A,B) How can I sort DATAFRAME increasing (or decreasing, for that matter) by B without making reference to A, or any other column? I've read ?order and ?sort but cannot seem to figure this out. Thank you. Mark __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Sorting a dataframe by one column?
mtb954 mtb954 wrote: Given the following dataframe: A=1:10 B=(a-5)^2 DATAFRAME=data.frame(A,B) How can I sort DATAFRAME increasing (or decreasing, for that matter) by B without making reference to A, or any other column? I've read ?order and ?sort but cannot seem to figure this out. You should have tried RSiteSearch(sort dataframe) also, since there are many examples in the archives of R-help. A=1:10 B=(A-5)^2 mydata=data.frame(A,B) mydata[order(mydata$B),] mydata[rev(order(mydata$B)),] -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 452-1424 (M, W, F) fax: (917) 438-0894 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] RGtk2 install in Mac
I'm struggling installing RGtk2 on my Mac. Has anybody succeeded in doing so? This isn't probably the right place to talk about RGtk2, given that the web page suggests you should email the creator (Michael Lawrence) if you have any problems. I suspect your problem is the rather old version of R. Update to the latest version and try again. The other possible problem is that it looks like you are using fink, while we have only been testing using darwinports. Hadley __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] predicting glm on a new dataset
Hello together, I would like to predict my fitted values on a new dataset. The original dataset consists of the variable a and b (data.frame(a,b)). The dataset for prediction consists of the same variables, but variable b has a constant value (x) added towards it (data.frame (a,b+x). The prediction command returns the identical set of predicted values as for the original dataset yet I would have expected them to change due to b+x. Were have I gone wrong? Heres my code: orig.frame-data.frame(y,a,b) pred.frame-data.frame(a,b+x) attach(orig.frame) modela-glm(y~a+b,binomial) pr-predict(modela,newdata=pred.frame,type=response) many thanks Chris [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Minor documentation improvement
Gentlemen, In the documentation for reshape, in the function signature, the argument direction is not listed. However, it is explained in the explanation of parameters below. I am using R 2.2.1. Out of curiosity: Is the R core team still an all-male affair? I don't think I have seen a single lady's name. -- -- Vivek Satsangi Student, Rochester, NY USA __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] SE of parameter estimates in glmm.admb
Dear Istvan, An example library(glmmADMB) tt = glmm.admb(y ~ Base * trt + Age, random = ~Visit,group = subject, data = epil2, family = nbinom) To print the covariance matrix of the random effects vector (and the std of those estimates, see bottom) : print.glmm.admb(tt,sd_S_print=TRUE) Have a look at ?print.glmm.admb. To get the std's of the beta's (fixed effects) you type: tt$stdbeta I will try to find a better way to get access to the latter. Use names(tt) to see what objects there are. hans -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of I.Szentirmai Sent: Friday, February 24, 2006 2:56 PM To: R mailing list Subject: [R] SE of parameter estimates in glmm.admb Dear R users, Does anyone know how to get standard errors of the parameter estimates in glmm.admb? Thanks, Istvan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Help with classes and generic function
Hello R-Users I am pretty new to R and forgive me if my questions are childish , nevertheless i need help. I have some problems while trying to grasp the idea of a generic function. I understand that i have to build methods with naming syntax function.class, where class is the CLASS of an (first) object passed to the generic function, and is used to decide which method shall be invoked. Suppose i have a function say, unis - function(x,y,...){ ..function body...} and i call the function, assigning the result to an object say, results -unis(outcome, trial, ..) now i want the object, results, to have a particular CLASS say surr so that i can define methods like summary.surr plot.surr My main trouble is: what do i need to do, so that any object assigned the value from a call of the function unis has CLASS as surr Thanks Pryseley - [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] predicting glm on a new dataset
Christian Jones wrote: Hello together, I would like to predict my fitted values on a new dataset. The original dataset consists of the variable a and b (data.frame(a,b)). The dataset for prediction consists of the same variables, but variable b has a constant value (x) added towards it (data.frame (a,b+x). The prediction command returns the identical set of predicted values as for the original dataset yet I would have expected them to change due to b+x. Were have I gone wrong? Heres my code: orig.frame-data.frame(y,a,b) pred.frame-data.frame(a,b+x) attach(orig.frame) modela-glm(y~a+b,binomial) pr-predict(modela,newdata=pred.frame,type=response) Does this work for you? orig.frame - data.frame(y, a, b) pred.frame - data.frame(a, b = b + x) modela - glm(y ~ a + b, family = binomial, data = orig.frame) pr - predict(modela, newdata = pred.frame, type = response) -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 452-1424 (M, W, F) fax: (917) 438-0894 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] (Newbie) Aggregate for NA values
Folks, Sorry if this question has been answered before or is obvious (or worse, statistically bad). I don't understand what was said in one of the search results that seems somewhat related. I use aggregate to get a quick summary of the data. Part of what I am looking for in the summary is, how much influence might the NA's have had, if they were included, and is excluding them from the means causing some sort of bias. So I want the summary stat for the NA's also. Here is a simple example session (edited to remove the typos I made, comments added later): tmp_a - 1:10 tmp_b - rep(1:5,2) tmp_c - rep(1:2,5) tmp_d - c(1,1,1,2,2,2,3,3,3,4) tmp_df - data.frame(tmp_a,tmp_b,tmp_c,tmp_d); tmp_df$tmp_c[9:10] - NA ; tmp_df tmp_a tmp_b tmp_c tmp_d 1 1 1 1 1 2 2 2 2 1 3 3 3 1 1 4 4 4 2 2 5 5 5 1 2 6 6 1 2 2 7 7 2 1 3 8 8 3 2 3 9 9 4NA 3 1010 5NA 4 aggregate(tmp_df$tmp_d,by=list(tmp_df$tmp_b,tmp_df$tmp_c),mean); Group.1 Group.2 x 1 1 1 1 2 2 1 3 3 3 1 1 4 5 1 2 5 1 2 2 6 2 2 1 7 3 2 3 8 4 2 2 # Only one row for each (tmp_b, tmp_c) combination, NA's getting dropped. aggregate(tmp_df$tmp_d,by=list(tmp_df$tmp_c),mean); Group.1x 1 1 1.75 2 2 2.00 What I want in this last aggregate is, a mean for the values in tmp_d that correspond to the tmp_c values of NA. Similarly, perhaps there is a way to make the second last call to aggregate return the values of tmp_d for the NA values of tmp_c also. How can I achieve this? -- -- Vivek Satsangi Student, Rochester, NY USA __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Minor documentation improvement
Please ignore this message. I was not reading carefully enough, the parameter is in there. Vivek On 2/24/06, Vivek Satsangi [EMAIL PROTECTED] wrote: Gentlemen, In the documentation for reshape, in the function signature, the argument direction is not listed. However, it is explained in the explanation of parameters below. I am using R 2.2.1. Out of curiosity: Is the R core team still an all-male affair? I don't think I have seen a single lady's name. -- -- Vivek Satsangi Student, Rochester, NY USA -- -- Vivek Satsangi Student, Rochester, NY USA __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] (Newbie) Aggregate for NA values
I think it makes perfect sense for R to drop it since 'NA' represents uninformative information. I do not know if there is a elegant solution but I would suggest that you make these 'NA' into an informative value. Here is one possibility: df - data.frame( AA=1:10, BB=rep(1:5,2), CC=rep(1:2,5), DD=rnorm(10) ) df[ 9:10, CC ] - NA df[is.na(df)] - lala ## change NA's into informative category ## aggregate( df$DD, by=list( df$CC ), mean ) Group.1 x 1 1 1.1533763 2 2 0.6427338 3lala -0.2745249 aggregate( df$DD, by=list( df$BB, df$CC ), mean ) Group.1 Group.2 x 11 1 0.47264081 22 1 0.63795211 33 1 1.66756015 45 1 1.83535232 51 2 0.89914287 62 2 1.11102134 73 2 0.22268699 84 2 0.33808394 94lala -0.60154608 10 5lala 0.05249622 Regards, Adai On Fri, 2006-02-24 at 10:16 -0500, Vivek Satsangi wrote: Folks, Sorry if this question has been answered before or is obvious (or worse, statistically bad). I don't understand what was said in one of the search results that seems somewhat related. I use aggregate to get a quick summary of the data. Part of what I am looking for in the summary is, how much influence might the NA's have had, if they were included, and is excluding them from the means causing some sort of bias. So I want the summary stat for the NA's also. Here is a simple example session (edited to remove the typos I made, comments added later): tmp_a - 1:10 tmp_b - rep(1:5,2) tmp_c - rep(1:2,5) tmp_d - c(1,1,1,2,2,2,3,3,3,4) tmp_df - data.frame(tmp_a,tmp_b,tmp_c,tmp_d); tmp_df$tmp_c[9:10] - NA ; tmp_df tmp_a tmp_b tmp_c tmp_d 1 1 1 1 1 2 2 2 2 1 3 3 3 1 1 4 4 4 2 2 5 5 5 1 2 6 6 1 2 2 7 7 2 1 3 8 8 3 2 3 9 9 4NA 3 1010 5NA 4 aggregate(tmp_df$tmp_d,by=list(tmp_df$tmp_b,tmp_df$tmp_c),mean); Group.1 Group.2 x 1 1 1 1 2 2 1 3 3 3 1 1 4 5 1 2 5 1 2 2 6 2 2 1 7 3 2 3 8 4 2 2 # Only one row for each (tmp_b, tmp_c) combination, NA's getting dropped. aggregate(tmp_df$tmp_d,by=list(tmp_df$tmp_c),mean); Group.1x 1 1 1.75 2 2 2.00 What I want in this last aggregate is, a mean for the values in tmp_d that correspond to the tmp_c values of NA. Similarly, perhaps there is a way to make the second last call to aggregate return the values of tmp_d for the NA values of tmp_c also. How can I achieve this? -- -- Vivek Satsangi Student, Rochester, NY USA __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Summarize by two-column factor, retaining original factors
I am having trouble doing the following. I have a data.frame like this, where x and y are a variable that I want to do calculations on: Name Year x y ab 2001 15 3 ab 2001 10 2 ab 2002 12 8 ab 2003 7 10 dv 2002 10 15 dv 2002 3 2 dv 2003 1 15 Before I do all the other things I need to do with this data, I need to summarize or collapse the data by name and year. I've found that I can do things like nameyear-interaction(name,year) dataframe$nameyear-nameyear tapply(dataframe$x,dataframe$nameyear,sum) tapply(dataframe$y,dataframe$nameyear,sum) and then bind those together. But my problem is that I need to somehow retain the original Names in my collapsed dataset, so that later I can do analyses with the Name factors. All I can think of is something like tapply(dataframe$Name,dataframe$nameyear, somefunction?) but nothing seems to work. I'm actually trying to convert a SAS program, and I can't get out of that mindset. There, it's a simple Proc Means, By Name Year. Thanks for any help or suggestions on the right way to go about this. Matt Crawford __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Summarize by two-column factor, retaining original factors
On Fri, 2006-02-24 at 08:18 -0800, Matt Crawford wrote: I am having trouble doing the following. I have a data.frame like this, where x and y are a variable that I want to do calculations on: Name Year x y ab 2001 15 3 ab 2001 10 2 ab 2002 12 8 ab 2003 7 10 dv 2002 10 15 dv 2002 3 2 dv 2003 1 15 Before I do all the other things I need to do with this data, I need to summarize or collapse the data by name and year. I've found that I can do things like nameyear-interaction(name,year) dataframe$nameyear-nameyear tapply(dataframe$x,dataframe$nameyear,sum) tapply(dataframe$y,dataframe$nameyear,sum) and then bind those together. But my problem is that I need to somehow retain the original Names in my collapsed dataset, so that later I can do analyses with the Name factors. All I can think of is something like tapply(dataframe$Name,dataframe$nameyear, somefunction?) but nothing seems to work. I'm actually trying to convert a SAS program, and I can't get out of that mindset. There, it's a simple Proc Means, By Name Year. Thanks for any help or suggestions on the right way to go about this. Matt Crawford Matt, Just use aggregate(): aggregate(MyDF[, 3:4], list(Name = MyDF$Name, Year = MyDF$Year), sum) Name Year x y 1 ab 2001 25 5 2 ab 2002 12 8 3 dv 2002 13 17 4 ab 2003 7 10 5 dv 2003 1 15 See ?aggregate for more information. HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Summarize by two-column factor, retaining original factors
Or even aggregate(DF[3:4], DF[1:2], sum) On 2/24/06, Marc Schwartz (via MN) [EMAIL PROTECTED] wrote: On Fri, 2006-02-24 at 08:18 -0800, Matt Crawford wrote: I am having trouble doing the following. I have a data.frame like this, where x and y are a variable that I want to do calculations on: Name Year x y ab 2001 15 3 ab 2001 10 2 ab 2002 12 8 ab 2003 7 10 dv 2002 10 15 dv 2002 3 2 dv 2003 1 15 Before I do all the other things I need to do with this data, I need to summarize or collapse the data by name and year. I've found that I can do things like nameyear-interaction(name,year) dataframe$nameyear-nameyear tapply(dataframe$x,dataframe$nameyear,sum) tapply(dataframe$y,dataframe$nameyear,sum) and then bind those together. But my problem is that I need to somehow retain the original Names in my collapsed dataset, so that later I can do analyses with the Name factors. All I can think of is something like tapply(dataframe$Name,dataframe$nameyear, somefunction?) but nothing seems to work. I'm actually trying to convert a SAS program, and I can't get out of that mindset. There, it's a simple Proc Means, By Name Year. Thanks for any help or suggestions on the right way to go about this. Matt Crawford Matt, Just use aggregate(): aggregate(MyDF[, 3:4], list(Name = MyDF$Name, Year = MyDF$Year), sum) Name Year x y 1 ab 2001 25 5 2 ab 2002 12 8 3 dv 2002 13 17 4 ab 2003 7 10 5 dv 2003 1 15 See ?aggregate for more information. HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Summarize by two-column factor, retaining original factors
Matt Crawford wrote: I am having trouble doing the following. I have a data.frame like this, where x and y are a variable that I want to do calculations on: Name Year x y ab 2001 15 3 ab 2001 10 2 ab 2002 12 8 ab 2003 7 10 dv 2002 10 15 dv 2002 3 2 dv 2003 1 15 Before I do all the other things I need to do with this data, I need to summarize or collapse the data by name and year. I've found that I can do things like nameyear-interaction(name,year) dataframe$nameyear-nameyear tapply(dataframe$x,dataframe$nameyear,sum) tapply(dataframe$y,dataframe$nameyear,sum) and then bind those together. But my problem is that I need to somehow retain the original Names in my collapsed dataset, so that later I can do analyses with the Name factors. All I can think of is something like tapply(dataframe$Name,dataframe$nameyear, somefunction?) but nothing seems to work. I'm actually trying to convert a SAS program, and I can't get out of that mindset. There, it's a simple Proc Means, By Name Year. Thanks for any help or suggestions on the right way to go about this. mydata - data.frame( Name = c(ab,ab,ab,ab,dv,dv,dv), Year = c(2001,2001,2002,2003,2002,2002,2003), x = c(15,10,12,7,10,3,1), y = c(3,2,8,10,15,2,15)) aggregate(mydata[,c(x, y)], list(Name = mydata$Name, Year = mydata$Year), sum) Name Year x y 1 ab 2001 25 5 2 ab 2002 12 8 3 dv 2002 13 17 4 ab 2003 7 10 5 dv 2003 1 15 ?aggregate -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 452-1424 (M, W, F) fax: (917) 438-0894 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] dist() between groups of data
Henrik, If I understand your question, what you want is: x - runif(9) y - runif(9) z - rep(c(0,1,2), each=3) xyz - cbind(x,y,z) xyz d.all - dist(xyz[,c(x,y)]) d.all xyz.02 - subset(xyz, z == 0 | z == 2) xyz.02 d.02 - dist(xyz.02[,c(x,y)]) d.02 Marc -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Henrik Parn Sent: Thursday, February 23, 2006 8:40 AM To: r-help@stat.math.ethz.ch Subject: [R] dist() between groups of data Dear all, I have a data set with x and y positions of nests. Each nest can be grouped according to a factor z. I have made a small dummy data set, where the grouping variable z is 0 or 1: x - runif(6) y - runif(6) z - rep(c(0,1), each=3) xyz - cbind(x,y,z) xyz x y z [1,] 0.7176801 0.760944688 0 [2,] 0.2377928 0.080622524 0 [3,] 0.9450770 0.022039470 0 [4,] 0.8725492 0.971996677 1 [5,] 0.6356198 0.001569859 1 [6,] 0.8949670 0.066044377 1 First of all, I suppose that this is the correct way to calculate the Euclidean distance between /all/ nests: xy - cbind(x,y) d.all - dist(xy) However, I would like to obtain a distance matrix for distances between nests belonging to certain groups. For example calculate all distances from nests where z equals something, to nests where z equals something else. Is it best to split the data in two matrices according to the value of z in the two groups to be compared, and then try to follow the suggestions by Gabor Grothendieck* Date:* Wed 07 Jan 2004 - 15:16:37 EST , or are there other ways that can be applied straight to one matrix? Thanks in advance! Henrik -- Henrik Pärn Department of Biology NTNU 7491 Trondheim Norway +47 735 96282 (office) +47 909 89 255 (mobile) +47 735 96100 (fax) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Summarize by two-column factor, retaining original factors
The summaryBy function in the doBy package might help you: summaryBy(x+y~Year, data=..., FUN=c(mean,var)) Best regards Søren Fra: [EMAIL PROTECTED] på vegne af Matt Crawford Sendt: fr 24-02-2006 17:18 Til: r-help@stat.math.ethz.ch Emne: [R] Summarize by two-column factor, retaining original factors I am having trouble doing the following. I have a data.frame like this, where x and y are a variable that I want to do calculations on: Name Year x y ab 2001 15 3 ab 2001 10 2 ab 2002 12 8 ab 2003 7 10 dv 2002 10 15 dv 2002 3 2 dv 2003 1 15 Before I do all the other things I need to do with this data, I need to summarize or collapse the data by name and year. I've found that I can do things like nameyear-interaction(name,year) dataframe$nameyear-nameyear tapply(dataframe$x,dataframe$nameyear,sum) tapply(dataframe$y,dataframe$nameyear,sum) and then bind those together. But my problem is that I need to somehow retain the original Names in my collapsed dataset, so that later I can do analyses with the Name factors. All I can think of is something like tapply(dataframe$Name,dataframe$nameyear, somefunction?) but nothing seems to work. I'm actually trying to convert a SAS program, and I can't get out of that mindset. There, it's a simple Proc Means, By Name Year. Thanks for any help or suggestions on the right way to go about this. Matt Crawford __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Minor documentation improvement
On 2/24/2006 9:44 AM, Vivek Satsangi wrote: Gentlemen, In the documentation for reshape, in the function signature, the argument direction is not listed. However, it is explained in the explanation of parameters below. I see it between drop and new.row.names: reshape(data, varying = NULL, v.names = NULL, timevar = time, idvar = id, ids = 1:NROW(data), times = seq(length = length(varying[[1]])), drop = NULL, direction, new.row.names = NULL, split = list(regexp=\., include=FALSE)) in the reshape man page. Did you overlook it, or are you looking somewhere else? I am using R 2.2.1. Out of curiosity: Is the R core team still an all-male affair? I don't think I have seen a single lady's name. It's been several years since I've seen some of them, but as far as I've heard, they're all still male. Duncan Murdoch __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] help with optimize statement
Can some help me spot what I'm doing wrong here. I have two equations, one a michalis-menton eqn and one a straight line. I need to work out where they cross. I created the function: solveEqn-function(x,vals){ Vmax-vals[1] Ks-vals[2] m-vals[3] c-vals[4] diff-0 mmVal-exp(Vmax+x/(Ks+x)) slVal-x*m+c diff-mmVal-slVal return(diff) } optim(c(200,500),solveEqn,vals=c(2.4591201,-0.4015233,5.924e-5,3.437)) Error in optim(c(200, 500), solveEqn, vals = c(2.4591201, -0.4015233, : objective function in optim evaluates to length 2 not 1 If i replace return(diff) with sum(diff) then the optim function runs but returns the wrong value (which should be about 290). Many thanks Tom __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Sorting alphanumerically
I'm trying to sort a DATAFRAME by a column ID that contains alphanumeric data. Specifically,ID contains integers all preceeded by the character g as in: g1, g6, g3, g19, g100, g2, g39 I am using the following code: DATAFRAME=DATAFRAME[order(DATAFRAME1$ID),] and was hoping it would sort the dataframe by ID in the following manner g1, g2, g3, g6, g19, g39, g100 but it doesn't sort at all. Could anyone point out my mistake? Thank you. Mark __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Sorting alphanumerically
This was just discussed recently. Try: library(gtools) ?mixedorder On 2/24/06, mtb954 mtb954 [EMAIL PROTECTED] wrote: I'm trying to sort a DATAFRAME by a column ID that contains alphanumeric data. Specifically,ID contains integers all preceeded by the character g as in: g1, g6, g3, g19, g100, g2, g39 I am using the following code: DATAFRAME=DATAFRAME[order(DATAFRAME1$ID),] and was hoping it would sort the dataframe by ID in the following manner g1, g2, g3, g6, g19, g39, g100 but it doesn't sort at all. Could anyone point out my mistake? Thank you. Mark __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Sorting alphanumerically
On Fri, 2006-02-24 at 12:54 -0600, mtb954 mtb954 wrote: I'm trying to sort a DATAFRAME by a column ID that contains alphanumeric data. Specifically,ID contains integers all preceeded by the character g as in: g1, g6, g3, g19, g100, g2, g39 I am using the following code: DATAFRAME=DATAFRAME[order(DATAFRAME1$ID),] and was hoping it would sort the dataframe by ID in the following manner g1, g2, g3, g6, g19, g39, g100 but it doesn't sort at all. Could anyone point out my mistake? Thank you. Mark The values are being sorted by character based ordering, which may be impacted upon by your locale. Thus, on my system, you end up with something like the following: ID[order(ID)] [1] g1 g100 g19 g2 g3 g39 g6 What you can do, based upon the presumption that the prefix of 'g' is present as you describe above, is: ID[order(as.numeric((gsub(g, , ID] [1] g1 g2 g3 g6 g19 g39 g100 What this does is to use gsub() to strip the 'g' and then order by numeric value. HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Sorting alphanumerically
Does this help? ID - paste(g, sample(1:100, 100, replace=FALSE), sep=) ID [1] g88 g5 g79 g67 g43 g21 g66 [8] g9 g38 g86 g12 g85 g74 g34 [15] g52 g95 g6 g22 g70 g87 g7 [22] g83 g63 g42 g26 g65 g16 g97 [29] g76 g2 g90 g23 g15 g82 g75 [36] g58 g17 g20 g96 g91 g31 g33 [43] g48 g32 g93 g54 g49 g36 g81 [50] g57 g27 g14 g62 g10 g80 g71 [57] g28 g37 g89 g8 g94 g68 g56 [64] g92 g41 g11 g4 g99 g55 g60 [71] g18 g69 g19 g64 g39 g1 g53 [78] g44 g24 g100 g35 g3 g40 g47 [85] g51 g46 g61 g45 g50 g25 g13 [92] g73 g77 g30 g84 g78 g29 g59 [99] g72 g98 ID[order(as.numeric(substr(ID, start=2, stop=nchar(ID] [1] g1 g2 g3 g4 g5 g6 g7 [8] g8 g9 g10 g11 g12 g13 g14 [15] g15 g16 g17 g18 g19 g20 g21 [22] g22 g23 g24 g25 g26 g27 g28 [29] g29 g30 g31 g32 g33 g34 g35 [36] g36 g37 g38 g39 g40 g41 g42 [43] g43 g44 g45 g46 g47 g48 g49 [50] g50 g51 g52 g53 g54 g55 g56 [57] g57 g58 g59 g60 g61 g62 g63 [64] g64 g65 g66 g67 g68 g69 g70 [71] g71 g72 g73 g74 g75 g76 g77 [78] g78 g79 g80 g81 g82 g83 g84 [85] g85 g86 g87 g88 g89 g90 g91 [92] g92 g93 g94 g95 g96 g97 g98 [99] g99 g100 The idea is to drop the leading g, convert to numeric, and then order. mtb954 mtb954 wrote: I'm trying to sort a DATAFRAME by a column ID that contains alphanumeric data. Specifically,ID contains integers all preceeded by the character g as in: g1, g6, g3, g19, g100, g2, g39 I am using the following code: DATAFRAME=DATAFRAME[order(DATAFRAME1$ID),] and was hoping it would sort the dataframe by ID in the following manner g1, g2, g3, g6, g19, g39, g100 but it doesn't sort at all. Could anyone point out my mistake? Thank you. Mark __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 452-1424 (M, W, F) fax: (917) 438-0894 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Multiple plots on the same pdf file
Is there a way to output multiple plots generated with a high level plot function such as plot() to the same pdf file? The following does not work (in windows XP): pdf(filename) plot(...) # first plot plot(...) # second plot . plot(...) # n-th plot dev.off() Thanks for your help! __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] R script autoload at startup
Yes. It would be nice and useful to save the users the task of loading the source R-TcltK code everytime they start up R. Because, in principle they are going to use R just for this. But the R GUI must remains open Javier --- El Viernes, 24 de Febrero de 2006 16:39, Frank Samuelson escribió: Do you need the user to interact with the Rgui after the code has run? -Frank Javier Garcia-Pintado wrote: Hello; I'm now using mainly R for windows, mainly because I'm writing a tcl/Tk interface for some people, and I've got two questions. I'm an absolute beginner with tctk or tcktk use under the R GUI. 1) Is it posible to create a shorcut that launchs the R GUI and automatically reads the source code of the tcl/tk script to also launch the tcltk interface? 2) Is the RGUI programmed with tcltk? In this case, is it possible for an user like me to create a menu entry at the R GUI to call the source code in this R/tcl/Tk script? Any of the two options would be very good for us. Thanks and best regards, Javier -- javier garcía-pintado __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Multiple plots on the same pdf file
You need to say more explicitly what `does not work' means (as the Posting Guide asks). What you've stated will generate plots in separate pages in the PDF file. If that's not what you want, then tell us exactly what you are looking for. Andy From: Juan Lewinger Is there a way to output multiple plots generated with a high level plot function such as plot() to the same pdf file? The following does not work (in windows XP): pdf(filename) plot(...) # first plot plot(...) # second plot . plot(...) # n-th plot dev.off() Thanks for your help! __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Multiple plots on the same pdf file (clarification)
I wanted to output each plot to a separate page on the same pdf file. Contrary to what I stated in my original question, the code below does do the job. I now identified my problem as Acrobat's (my installation), not R. Thanks for the help - Original Message - From: Liaw, Andy [EMAIL PROTECTED] Date: Friday, February 24, 2006 11:41 am Subject: RE: [R] Multiple plots on the same pdf file To: 'Juan Lewinger' [EMAIL PROTECTED], r-help@stat.math.ethz.ch You need to say more explicitly what `does not work' means (as the PostingGuide asks). What you've stated will generate plots in separate pages in the PDF file. If that's not what you want, then tell us exactly what you are looking for. Andy From: Juan Lewinger Is there a way to output multiple plots generated with a high level plot function such as plot() to the same pdf file? The following does not work (in windows XP): pdf(filename) plot(...) # first plot plot(...) # second plot . plot(...) # n-th plot dev.off() Thanks for your help! __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html --- --- Notice: This e-mail message, together with any attachments, contains information of Merck Co., Inc. (One Merck Drive, Whitehouse Station, New Jersey, USA 08889), and/or its affiliates (which may be known outside the United States as Merck Frosst, Merck Sharp Dohme or MSD and in Japan, as Banyu) that may be confidential, proprietary copyrighted and/or legally privileged. It is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please notify us immediately by reply e-mail and then delete it from your system. --- --- __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] R script autoload at startup
See ?Startup for how to do this via .Rprofile or etc/Rprofile.site. The answer to your second question is that RGui is not written in tcltk (can't you tell from the speed with which it works?), but there are documented R functions for you to add menu items, such as winMenuAdd. (I do wonder how you missed these in the searches for help, as all the terms I tried found the answers.) On Fri, 24 Feb 2006, javier garcia-pintado wrote: Yes. It would be nice and useful to save the users the task of loading the source R-TcltK code everytime they start up R. Because, in principle they are going to use R just for this. But the R GUI must remains open Javier --- El Viernes, 24 de Febrero de 2006 16:39, Frank Samuelson escribió: Do you need the user to interact with the Rgui after the code has run? -Frank Javier Garcia-Pintado wrote: Hello; I'm now using mainly R for windows, mainly because I'm writing a tcl/Tk interface for some people, and I've got two questions. I'm an absolute beginner with tctk or tcktk use under the R GUI. 1) Is it posible to create a shorcut that launchs the R GUI and automatically reads the source code of the tcl/tk script to also launch the tcltk interface? 2) Is the RGUI programmed with tcltk? In this case, is it possible for an user like me to create a menu entry at the R GUI to call the source code in this R/tcl/Tk script? Any of the two options would be very good for us. Thanks and best regards, Javier -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] help with optimize statement
Hi Tom, first I can't see, why you think the crossing-point should be 290, look at the plot x - seq(200, 500, 10) plot( exp(2.4591201+x/(-0.4015233+x)) ~ x, ylim=c(0,40), type=l) lines(5.924e-5*x+3.437 ~x) Maybe your vals are wrong? 2) For optimizing a function of 1 parameter, you should use optimize instead of optim 3) As your Function return the difference of the michaelis-menton eqn and the line, optimize will maximize the difference, you could use the sum of squares: solveEqn-function(x,vals){ Vmax-vals[1] Ks-vals[2] m-vals[3] c-vals[4] diff-0 mmVal-exp(Vmax+x/(Ks+x)) slVal-x*m+c diff-mmVal-slVal return((mmVal-slVal)^2) } optimize(solveEqn,c(0,1e6),vals=c(2.4591201,-0.4015233,5.924e-5,3.437)) x - seq(0, 1e6, len=100) plot( exp(2.4591201+x/(-0.4015233+x)) ~ x, ylim=c(0,40), type=l) lines(5.924e-5*x+3.437 ~x) Jost Burkardt tom wright wrote: Can some help me spot what I'm doing wrong here. I have two equations, one a michalis-menton eqn and one a straight line. I need to work out where they cross. I created the function: solveEqn-function(x,vals){ Vmax-vals[1] Ks-vals[2] m-vals[3] c-vals[4] diff-0 mmVal-exp(Vmax+x/(Ks+x)) slVal-x*m+c diff-mmVal-slVal return(diff) } optim(c(200,500),solveEqn,vals=c(2.4591201,-0.4015233,5.924e-5,3.437)) Error in optim(c(200, 500), solveEqn, vals = c(2.4591201, -0.4015233, : objective function in optim evaluates to length 2 not 1 If i replace return(diff) with sum(diff) then the optim function runs but returns the wrong value (which should be about 290). Many thanks Tom __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] R and marine protected areas: algorithms for site selection
Hi - I looked briefly a little while ago for R interaction with linear programming tools. There is limited support for the lp_solve solver (http://sourceforge.net/projects/lpsolve) in the package lpSolve, but it doesn't give full access to the external solver's capabilities. Other than that, you may want to look at the Gnu Linear Programming Kit (http://www.gnu.org/software/glpk/glpk.html) and MathProg or Zimpl (http://www.zib.de/koch/zimpl/), and be prepared to get R to write text files that can then be run externally. Ugly, but you may get somewhere. If you find anything better that integrates R and linear programming, I'd be interested to hear about it. Regards, Rich Dear listers, a central problem in conservation biology is the selection of sites in reserve network design. many algorithms have been published, and I was wondering any have been implemented in R. I did not seen anything on CRAN or R-help, or on the web in general. Best regards, Eric Eric Pante Rich Grenyer, Ph.D. Biology Department - University of Virginia Gilmer Hall Charlottesville, Virginia VA 22904 United States of America tel: (+1) 434 982 5629 fax: (+1) 434 982 5626 http://faculty.virginia.edu/gittleman/rich __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Time on x-axis
Hello, Thank you! It worked!! Now I have another query; I have about 300 data entries, and I dont think it would be possible to quote everything under tt-c() or x-c(). Is there any way to plot the graph, without having to manually quote all the data items in the array? Thank you. Sangeetha = Original Message From Gabor Grothendieck [EMAIL PROTECTED] = Try this: # test data tt - c(23:05:02, 23:10:02, 23:15:03, 23:20:03, 23:25:03, 23:30:03, 23:35:03, 23:40:03, 23:45:04, 23:50:04, 23:55:03, 23:55:03) x - c(0.575764, 0.738379, 0.567414, 0.663436, 0.599834, 0.679571, 0.88141, 0.868848, 0.969271, 0.878968, 0.990972, 0.990972) library(zoo) library(chron) z - zoo(x, times(tt)) plot(z) Read the R Help Desk article in R News 4/1 about dates and times and also read the chron article in its references. Also read the zoo vignette which you can access like this: library(zoo) vignette(zoo) and also read ?axis in case you want to customize the axes. On 2/20/06, Sangeetha Swaminathan [EMAIL PROTECTED] wrote: Hello, I just started using the GNU R. I am having trouble plotting my data. I am tryin to plot the following data: TIMESTAMPLOGIN-TIME (hh:mm:ss) (s) 23:55:03 0.990972 23:55:03 0.990972 23:50:04 0.878968 23:45:04 0.969271 23:40:03 0.868848 23:35:030.88141 23:30:03 0.679571 23:25:03 0.599834 23:20:03 0.663436 23:15:03 0.567414 23:10:02 0.738379 23:05:02 0.575764 with TIMESTAMP on the x-axis. The plot() function assumes the x-axis as the total number of events, and plots the desired graph. But I want the TIMESTAMP on the x-axis. If I try to change the x-axis, the y-axis gets modified too, and all I get is just a dot as a plot. Can someone tell me how I can make R plot my graph, with TIMESTAMP as my x-axis and LOGIN_TIME as my y-axis? Thank you. Sangeetha -- Sangeetha Swaminathan Graduate Assistant Innovative Technology Center (ITC) 2444 Dunford Hall The University of Tennessee Knoxville, TN 37996 Phone [O]:(865) 974-9672 [R]:(865) 946-4340 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Sangeetha Swaminathan Graduate Assistant Innovative Technology Center (ITC) 2444 Dunford Hall The University of Tennessee Knoxville, TN 37996 Phone [O]:(865) 974-9672 [R]:(865) 946-4340 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Read SAS .sd2 file into R?
Does anyone know how to import a SAS .sd2 file into R? I can't see anything in library(foreign). Thank you. Mark __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Read SAS .sd2 file into R?
mtb954 mtb954 [EMAIL PROTECTED] writes: Does anyone know how to import a SAS .sd2 file into R? I can't see anything in library(foreign). The SAS dataset file formats are not publicly available. You need either SAS itself (on a Windows machine) or a specialized tool like DBMS/Copy to converti it. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Time on x-axis
See: library(zoo) ?read.zoo On 2/24/06, Sangeetha Swaminathan [EMAIL PROTECTED] wrote: Hello, Thank you! It worked!! Now I have another query; I have about 300 data entries, and I dont think it would be possible to quote everything under tt-c() or x-c(). Is there any way to plot the graph, without having to manually quote all the data items in the array? Thank you. Sangeetha = Original Message From Gabor Grothendieck [EMAIL PROTECTED] = Try this: # test data tt - c(23:05:02, 23:10:02, 23:15:03, 23:20:03, 23:25:03, 23:30:03, 23:35:03, 23:40:03, 23:45:04, 23:50:04, 23:55:03, 23:55:03) x - c(0.575764, 0.738379, 0.567414, 0.663436, 0.599834, 0.679571, 0.88141, 0.868848, 0.969271, 0.878968, 0.990972, 0.990972) library(zoo) library(chron) z - zoo(x, times(tt)) plot(z) Read the R Help Desk article in R News 4/1 about dates and times and also read the chron article in its references. Also read the zoo vignette which you can access like this: library(zoo) vignette(zoo) and also read ?axis in case you want to customize the axes. On 2/20/06, Sangeetha Swaminathan [EMAIL PROTECTED] wrote: Hello, I just started using the GNU R. I am having trouble plotting my data. I am tryin to plot the following data: TIMESTAMPLOGIN-TIME (hh:mm:ss) (s) 23:55:03 0.990972 23:55:03 0.990972 23:50:04 0.878968 23:45:04 0.969271 23:40:03 0.868848 23:35:030.88141 23:30:03 0.679571 23:25:03 0.599834 23:20:03 0.663436 23:15:03 0.567414 23:10:02 0.738379 23:05:02 0.575764 with TIMESTAMP on the x-axis. The plot() function assumes the x-axis as the total number of events, and plots the desired graph. But I want the TIMESTAMP on the x-axis. If I try to change the x-axis, the y-axis gets modified too, and all I get is just a dot as a plot. Can someone tell me how I can make R plot my graph, with TIMESTAMP as my x-axis and LOGIN_TIME as my y-axis? Thank you. Sangeetha -- Sangeetha Swaminathan Graduate Assistant Innovative Technology Center (ITC) 2444 Dunford Hall The University of Tennessee Knoxville, TN 37996 Phone [O]:(865) 974-9672 [R]:(865) 946-4340 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Sangeetha Swaminathan Graduate Assistant Innovative Technology Center (ITC) 2444 Dunford Hall The University of Tennessee Knoxville, TN 37996 Phone [O]:(865) 974-9672 [R]:(865) 946-4340 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Time on x-axis
And also, read 1. R News 4/1 help desk article on dates and times, 2. the zoo vignette: library(zoo) vignette(zoo) and 3. re-read the Introduction to R manual: http://cran.r-project.org/doc/manuals/R-intro.pdf On 2/24/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: See: library(zoo) ?read.zoo On 2/24/06, Sangeetha Swaminathan [EMAIL PROTECTED] wrote: Hello, Thank you! It worked!! Now I have another query; I have about 300 data entries, and I dont think it would be possible to quote everything under tt-c() or x-c(). Is there any way to plot the graph, without having to manually quote all the data items in the array? Thank you. Sangeetha = Original Message From Gabor Grothendieck [EMAIL PROTECTED] = Try this: # test data tt - c(23:05:02, 23:10:02, 23:15:03, 23:20:03, 23:25:03, 23:30:03, 23:35:03, 23:40:03, 23:45:04, 23:50:04, 23:55:03, 23:55:03) x - c(0.575764, 0.738379, 0.567414, 0.663436, 0.599834, 0.679571, 0.88141, 0.868848, 0.969271, 0.878968, 0.990972, 0.990972) library(zoo) library(chron) z - zoo(x, times(tt)) plot(z) Read the R Help Desk article in R News 4/1 about dates and times and also read the chron article in its references. Also read the zoo vignette which you can access like this: library(zoo) vignette(zoo) and also read ?axis in case you want to customize the axes. On 2/20/06, Sangeetha Swaminathan [EMAIL PROTECTED] wrote: Hello, I just started using the GNU R. I am having trouble plotting my data. I am tryin to plot the following data: TIMESTAMPLOGIN-TIME (hh:mm:ss) (s) 23:55:03 0.990972 23:55:03 0.990972 23:50:04 0.878968 23:45:04 0.969271 23:40:03 0.868848 23:35:030.88141 23:30:03 0.679571 23:25:03 0.599834 23:20:03 0.663436 23:15:03 0.567414 23:10:02 0.738379 23:05:02 0.575764 with TIMESTAMP on the x-axis. The plot() function assumes the x-axis as the total number of events, and plots the desired graph. But I want the TIMESTAMP on the x-axis. If I try to change the x-axis, the y-axis gets modified too, and all I get is just a dot as a plot. Can someone tell me how I can make R plot my graph, with TIMESTAMP as my x-axis and LOGIN_TIME as my y-axis? Thank you. Sangeetha -- Sangeetha Swaminathan Graduate Assistant Innovative Technology Center (ITC) 2444 Dunford Hall The University of Tennessee Knoxville, TN 37996 Phone [O]:(865) 974-9672 [R]:(865) 946-4340 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Sangeetha Swaminathan Graduate Assistant Innovative Technology Center (ITC) 2444 Dunford Hall The University of Tennessee Knoxville, TN 37996 Phone [O]:(865) 974-9672 [R]:(865) 946-4340 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] graphing dilemna
I want to create a graph that combines both stacked and side-by-side bars, is this possible? If more information is need: I have five age categories which are further divided by gender (the male and female bars lie side by side and then all the age groups are side by side). I want to further divide just the youngest category into two smaller age groups and retain the sex division -- stack the ages but have the sexes side by side. Help! Sloan -- ___ Surf the Web in a faster, safer and easier way: Download Opera 8 at http://www.opera.com __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Sorting alphanumerically
Thank you all, for your help. Mark On 2/24/06, Chuck Cleland [EMAIL PROTECTED] wrote: Does this help? ID - paste(g, sample(1:100, 100, replace=FALSE), sep=) ID [1] g88 g5 g79 g67 g43 g21 g66 [8] g9 g38 g86 g12 g85 g74 g34 [15] g52 g95 g6 g22 g70 g87 g7 [22] g83 g63 g42 g26 g65 g16 g97 [29] g76 g2 g90 g23 g15 g82 g75 [36] g58 g17 g20 g96 g91 g31 g33 [43] g48 g32 g93 g54 g49 g36 g81 [50] g57 g27 g14 g62 g10 g80 g71 [57] g28 g37 g89 g8 g94 g68 g56 [64] g92 g41 g11 g4 g99 g55 g60 [71] g18 g69 g19 g64 g39 g1 g53 [78] g44 g24 g100 g35 g3 g40 g47 [85] g51 g46 g61 g45 g50 g25 g13 [92] g73 g77 g30 g84 g78 g29 g59 [99] g72 g98 ID[order(as.numeric(substr(ID, start=2, stop=nchar(ID] [1] g1 g2 g3 g4 g5 g6 g7 [8] g8 g9 g10 g11 g12 g13 g14 [15] g15 g16 g17 g18 g19 g20 g21 [22] g22 g23 g24 g25 g26 g27 g28 [29] g29 g30 g31 g32 g33 g34 g35 [36] g36 g37 g38 g39 g40 g41 g42 [43] g43 g44 g45 g46 g47 g48 g49 [50] g50 g51 g52 g53 g54 g55 g56 [57] g57 g58 g59 g60 g61 g62 g63 [64] g64 g65 g66 g67 g68 g69 g70 [71] g71 g72 g73 g74 g75 g76 g77 [78] g78 g79 g80 g81 g82 g83 g84 [85] g85 g86 g87 g88 g89 g90 g91 [92] g92 g93 g94 g95 g96 g97 g98 [99] g99 g100 The idea is to drop the leading g, convert to numeric, and then order. mtb954 mtb954 wrote: I'm trying to sort a DATAFRAME by a column ID that contains alphanumeric data. Specifically,ID contains integers all preceeded by the character g as in: g1, g6, g3, g19, g100, g2, g39 I am using the following code: DATAFRAME=DATAFRAME[order(DATAFRAME1$ID),] and was hoping it would sort the dataframe by ID in the following manner g1, g2, g3, g6, g19, g39, g100 but it doesn't sort at all. Could anyone point out my mistake? Thank you. Mark __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 452-1424 (M, W, F) fax: (917) 438-0894 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html