Re: [R] simplification of code using stamp?
hadley wickham wrote: I get the following, which is not what I am looking for. test[1:10,] expertxx seeds runvalue 1 BW x001025 1 rsqs, slope, d.slope, intercept, d.intercept 2 BW x001025 2 rsqs, slope, d.slope, intercept, d.intercept 3 BW x001025 3 rsqs, slope, d.slope, intercept, d.intercept 4 BW x001025 4 rsqs, slope, d.slope, intercept, d.intercept 5 BW x001025 5 rsqs, slope, d.slope, intercept, d.intercept 6 BW x001028 1 rsqs, slope, d.slope, intercept, d.intercept 7 BW x001028 2 rsqs, slope, d.slope, intercept, d.intercept 8 BW x001028 3 rsqs, slope, d.slope, intercept, d.intercept 9 BW x001028 4 rsqs, slope, d.slope, intercept, d.intercept 10 BW x001028 5 rsqs, slope, d.slope, intercept, d.intercept That's because stamp doesn't produce great output at the moment (have a look at the str(test) to see that you have a data frame containing a list of vectors) The following code should put it a more reasonable form: tidy - function(x) { bind - function(i) data.frame(x[i, -ncol(x),drop=FALSE], t(a$value[[i]])) l - lapply(1:nrow(x), bind) do.call(rbind.fill, l) } tidy(test) Thanks Hadley - I'll look at the code. (but unless you provide a reproducible example I can't be sure that it works with your data) Regards, Hadley -- Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT) Department of Conservation Ecology and Entomology University of Stellenbosch Matieland 7602 South Africa Tel:+27 - (0)72 808 2975 (w) Fax:+27 - (0)21 808 3304 Cell: +27 - (0)83 9479 042 email: [EMAIL PROTECTED] [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 and provide commented, minimal, self-contained, reproducible code.
[R] Error bars in ggplot?
Hi Is it possible to put error bars in ggplot? I couldn't find anything so far. Rainer -- Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT) Department of Conservation Ecology and Entomology University of Stellenbosch Matieland 7602 South Africa Tel:+27 - (0)72 808 2975 (w) Fax:+27 - (0)21 808 3304 Cell: +27 - (0)83 9479 042 email: [EMAIL PROTECTED] [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 and provide commented, minimal, self-contained, reproducible code.
[R] Installation of RGrace
Hi I try to install RGrace, but always get the following error below. Might it have to do that RGtk is not installed and where can I find it to install it? I have GTK 1.2.10 installed. My R version and platform: version _ platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major 2 minor 4.0 year 2006 month 10 day03 svn rev39566 language R version.string R version 2.4.0 (2006-10-03) 09:26:46 (1.32 MB/s) - `/tmp/RtmpDCW8km/downloaded_packages/RGrace_0.5-5.tar.gz' saved [164119/164119] * Installing *source* package 'RGrace' ... ** libs gcc -I/usr/lib/R/include -I/usr/lib/R/include -I/usr/include/gtk-1.2 -I/usr/include/glib-1.2 -I/usr/lib/glib/include -I/usr/local/include -fpic -c gdk_draw.c -o gdk_draw.o gdk_draw.c:3:21: error: gdk/gdk.h: No such file or directory gdk_draw.c:4:21: error: gtk/gtk.h: No such file or directory gdk_draw.c: In function ‘draw_rubber_box’: gdk_draw.c:9: error: ‘GtkWidget’ undeclared (first use in this function) gdk_draw.c:9: error: (Each undeclared identifier is reported only once gdk_draw.c:9: error: for each function it appears in.) gdk_draw.c:9: error: ‘drawing_widget’ undeclared (first use in this function) gdk_draw.c:9: error: syntax error before ‘)’ token gdk_draw.c:10: error: ‘GdkColor’ undeclared (first use in this function) gdk_draw.c:11: error: ‘GdkGC’ undeclared (first use in this function) gdk_draw.c:11: error: ‘gc1’ undeclared (first use in this function) gdk_draw.c:12: error: ‘Color’ undeclared (first use in this function) gdk_draw.c:17: error: ‘GDK_XOR’ undeclared (first use in this function) gdk_draw.c:19: error: ‘GDK_LINE_SOLID’ undeclared (first use in this function) gdk_draw.c:19: error: ‘GDK_CAP_PROJECTING’ undeclared (first use in this function) gdk_draw.c:19: error: ‘GDK_JOIN_MITER’ undeclared (first use in this function) gdk_draw.c:20: error: ‘GDK_SOLID’ undeclared (first use in this function) make: *** [gdk_draw.o] Error 1 ERROR: compilation failed for package 'RGrace' ** Removing '/usr/lib/R/library/RGrace' -- Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT) Department of Conservation Ecology and Entomology University of Stellenbosch Matieland 7602 South Africa Tel:+27 - (0)72 808 2975 (w) Fax:+27 - (0)21 808 3304 Cell: +27 - (0)83 9479 042 email: [EMAIL PROTECTED] [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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Read.csv
Hi On 26 Oct 2006 at 10:31, Wang, Joshua (EQS) wrote: Date sent: Thu, 26 Oct 2006 10:31:00 +0900 From: Wang, Joshua (EQS) [EMAIL PROTECTED] To: Murray Pung [EMAIL PROTECTED] Copies to: r-help@stat.math.ethz.ch Subject:Re: [R] Read.csv Mr. Pung, Thank you. It works in terms of loading the data. Except that there is a header in the file that I would like to load it to be the names in the data.frame. You probably shall set row.names=NULL parameter in read.csv as stated in help page row.names a vector of row names. This can be a vector giving the actual row names, or a single number giving the column of the table which contains the row names, or character string giving the name of the table column containing the row names. If there is a header and the first row contains one fewer field than the number of columns, the first column in the input is used for the row names. Otherwise if row.names is missing, the rows are numbered. Using row.names = NULL forces row numbering. However you probably will always get some row numbering as it is an attribute of data.frame. HTH Petr Regards, Josh From: Murray Pung [mailto:[EMAIL PROTECTED] Sent: Thursday, October 26, 2006 10:26 AM To: Wang, Joshua (EQS) Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Read.csv Try: read.csv(name.csv, header = F) On 26/10/06, Wang, Joshua (EQS) [EMAIL PROTECTED] wrote: Are there ways to load a csv file without row.names by read.csv? Thanks. [[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 and provide commented, minimal, self-contained, reproducible code. -- Murray Pung Statistician, Datapharm Australia Pty Ltd 0404 273 283 [[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 and provide commented, minimal, self-contained, reproducible code. Petr Pikal [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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Read.csv
On Thu, Oct 26, 2006 at 09:41:25AM +0900, Wang, Joshua (EQS) wrote: Are there ways to load a csv file without row.names by read.csv? Thanks. Have a look at ?read.csv. Somewhere in there you will find an explanation for the option row.name. In your case, you probably want to set it to NULL. cu Philipp -- Dr. Philipp PagelTel. +49-8161-71 2131 Dept. of Genome Oriented Bioinformatics Fax. +49-8161-71 2186 Technical University of Munich Science Center Weihenstephan 85350 Freising, Germany and Institute for Bioinformatics / MIPS Tel. +49-89-3187 3675 GSF - National Research Center Fax. +49-89-3187 3585 for Environment and Health Ingolstädter Landstrasse 1 85764 Neuherberg, Germany http://mips.gsf.de/staff/pagel __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Read.csv
Petr Pikal [EMAIL PROTECTED] writes: Hi On 26 Oct 2006 at 10:31, Wang, Joshua (EQS) wrote: Date sent:Thu, 26 Oct 2006 10:31:00 +0900 From: Wang, Joshua (EQS) [EMAIL PROTECTED] To: Murray Pung [EMAIL PROTECTED] Copies to:r-help@stat.math.ethz.ch Subject: Re: [R] Read.csv Mr. Pung, Thank you. It works in terms of loading the data. Except that there is a header in the file that I would like to load it to be the names in the data.frame. You probably shall set row.names=NULL parameter in read.csv as stated in help page ... However you probably will always get some row numbering as it is an attribute of data.frame. And JW should probably have avoided the two times probably by giving a concrete example of an input file and the intended result -- 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to improve the efficiency of the following lapply codes [Broadcast]
Make good use of Rprof(): It has helped me a great deal in pinpointing bottlenecks where I would not have suspected. Cheers, Andy From: Weiwei Shi object.size(intersect.matrix) 41314204 but my machine has 4 G memory, so it should be ok since after 12 hours, it finishes 16k out of 60k but still slow non-linearly. I am thinking to chop 60k into multiple 5k data.frames to run the program. but just wondering is there a way around it? version _ platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major 2 minor 3.1 year 2006 month 06 day01 svn rev38247 language R version.string Version 2.3.1 (2006-06-01) [EMAIL PROTECTED] ox]$ more /proc/meminfo total:used:free: shared: buffers: cached: Mem: 4189724672 3035549696 11541749760 282836992 2057129984 Swap: 4293586944 645042176 3648544768 [EMAIL PROTECTED] ox]$ more /proc/cpuinfo processor : 0 vendor_id : GenuineIntel cpu family : 15 model : 4 model name : Intel(R) Xeon(TM) CPU 3.60GHz stepping: 3 cpu MHz : 3591.419 cache size : 2048 KB thanks. On 10/25/06, Weiwei Shi [EMAIL PROTECTED] wrote: Hi, I have a series of lda analysis using the following lapply function: n - dim(intersect.matrix)[1] net1.lda - lapply(1:(n), function(k) i.lda(data.list, intersect.matrix, i=k, w)) i.lda is function to do the real lda analysis. intersect.matrix is a nx1026 matrix, n can be a really huge number like 60k. The target is perform a random search. Building a n=120k matrix is impossible for my machine. When n=5k, the task can be done in 30 min while n=60k, it is estimated to take 5 days. So I am wondering where my coding problem is, which causes this to be a nonlinearity. If more info is needed, I will provide. thanks -- Weiwei Shi, Ph.D Research Scientist GeneGO, Inc. Did you always know? No, I did not. But I believed... ---Matrix III -- Weiwei Shi, Ph.D Research Scientist GeneGO, Inc. Did you always know? No, I did not. But I believed... ---Matrix III __ 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 and provide commented, minimal, self-contained, reproducible code. -- Notice: This e-mail message, together with any attachments,...{{dropped}} __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] Quantile regression questions
I am relatively new to R, but am intrigued by its flexibility. I am interested in quantile regression and quantile estimation as regards to cotton fiber length distributions. The length distribution affects spinning and weaving properties, so it is desirable to select for certain distribution types. The AFIS fiber testing machinery outputs a vector for each sample of type c(12, 235, 355, . . . n) with the number of fibers in n=40 1/16 inch length categories. My question is what would be the best way to convert the raw output to quantiles and whether it would be appropriate to use quantile regression to look at whether location, variety, replication, etc. modify the length distribution. __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error bars in ggplot?
Is it possible to put error bars in ggplot? I couldn't find anything so far. Have a look at ggerrorbar. 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error bars in ggplot?
hadley wickham wrote: Is it possible to put error bars in ggplot? I couldn't find anything so far. Have a look at ggerrorbar. Thanks - exactly what I was looking for. By the way - ggerrorbar is not mentioned in ?ggplot. Rainer 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 and provide commented, minimal, self-contained, reproducible code. -- Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT) Department of Conservation Ecology and Entomology University of Stellenbosch Matieland 7602 South Africa Tel:+27 - (0)72 808 2975 (w) Fax:+27 - (0)21 808 3304 Cell: +27 - (0)83 9479 042 email: [EMAIL PROTECTED] [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 and provide commented, minimal, self-contained, reproducible code.
[R] legends in ggplot
Is it possible to change the legend title in ggplot that is generated by a colour (other than by changing the name of the variable)? For example, this produces a legend title, tip/total_bill. How can that title be changed? ggpoint(ggplot(tips,aesthetics=list(y=tip,x=total_bill,colour=tip/total_bill)) ) Thanks. -- = David Barron Said Business School University of Oxford Park End Street Oxford OX1 1HP __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] distance between legend title and legend box
Hi, I've looked at the parameters available for the legend function and cannot find a way to change the distance between the top of the box surrounding a legend and the legend's title. I have a math expression that raises the height of my title. If you don't mind the non-sensical title I give to the legend for this plot (Figure 3.20 in R Graphics): with(iris, plot(Sepal.Length, Sepal.Width, pch=as.numeric(Species), cex=1.2)) legend(6.5, 4.2, c(setosa, versicolor, virginica), cex=1, pch=1:3, title=expression(kg/km^2)) The result depends on the device, but I think any device will show the box needs to be raised a bit (in quartz, the top of the box passes in the middle of the 2, in pdf it is acceptable, but just (the top of the box lightly touches the top of the 2). Sincerely, Denis Chabot __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] Measurements of 3000 criminals
Hallo everyone, excuse me if this is not a genuine R question but I do not know where to ask else. Referring to e.g. https://stat.ethz.ch/pipermail/r-help/2004-December/062114.html I wonder if these measurements of 3000 criminals (raw data) are available anywhere. At least I didn't find them in the R datasets package or by means of Google. What I did find was a table of frequencies of the central values for *grouped* classifications (finger lenghts) in the Handbook of Small Data Sets. Thank you in advance. D. Trenkler -- Dietrich Trenkler c/o Universitaet Osnabrueck Rolandstr. 8; D-49069 Osnabrueck, Germany 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] distance between legend title and legend box
I don't know if there is a nice, easy way of doing this, but this method will work: with(iris, plot(Sepal.Length, Sepal.Width, pch=as.numeric(Species), cex=1.2)) lg-legend(6.5, 4.2, c(setosa, versicolor, virginica), cex=1, pch=1:3, title=expression(kg/km^2), bty=n) x1 - lg$rect$left y1 - lg$rect$top - lg$rect$h x2 - x1 + lg$rect$w y2 - lg$rect$top + .1 # change the .1 to get more or less space rect(x1,y1,x2,y2) On 26/10/06, Denis Chabot [EMAIL PROTECTED] wrote: Hi, I've looked at the parameters available for the legend function and cannot find a way to change the distance between the top of the box surrounding a legend and the legend's title. I have a math expression that raises the height of my title. If you don't mind the non-sensical title I give to the legend for this plot (Figure 3.20 in R Graphics): with(iris, plot(Sepal.Length, Sepal.Width, pch=as.numeric(Species), cex=1.2)) legend(6.5, 4.2, c(setosa, versicolor, virginica), cex=1, pch=1:3, title=expression(kg/km^2)) The result depends on the device, but I think any device will show the box needs to be raised a bit (in quartz, the top of the box passes in the middle of the 2, in pdf it is acceptable, but just (the top of the box lightly touches the top of the 2). Sincerely, Denis Chabot __ 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 and provide commented, minimal, self-contained, reproducible code. -- = David Barron Said Business School University of Oxford Park End Street Oxford OX1 1HP __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legends in ggplot
Is it possible to change the legend title in ggplot that is generated by a colour (other than by changing the name of the variable)? For example, this produces a legend title, tip/total_bill. How can that title be changed? ggpoint(ggplot(tips,aesthetics=list(y=tip,x=total_bill,colour=tip/total_bill)) ) You need to add a colour scale, and specify the name to appear on the legend (by default it just uses the name of the variable): p - ggpoint(ggplot(tips,aesthetics=list(y=tip,x=total_bill,colour=tip/total_bill)) ) sccolour(p, Tip rate) sccolour(p, This is a very long label\nsplit over two lines) you can also use expressions to create mathematical annotations: sccolour(p, expression(beta * x^2)) Regards, 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Measurements of 3000 criminals
Dietrich Trenkler Dietrich.Trenkler at uni-osnabrueck.de writes: Hallo everyone, excuse me if this is not a genuine R question but I do not know where to ask else. Referring to e.g. https://stat.ethz.ch/pipermail/r-help/2004-December/062114.html I wonder if these measurements of 3000 criminals (raw data) are available anywhere. At least I didn't find them in the R datasets package or by means of Google. What I did find was a table of frequencies of the central values for *grouped* classifications (finger lenghts) in the Handbook of Small Data Sets. Thank you in advance. D. Trenkler The original paper on JSTOR (Biometrika Vol I, no 2, 1902, W. R. Macdonell) gives tables of bivariate distributions (head length vs head breadth, height vs head breadth, height vs left middle finger length) for the 3000-criminal sample, a 1306-criminal subsample, and for a sample of 1000 Cambridge men. It would be an interesting challenge for a historian of science ... Ben Bolker __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to specify a constant in gnls{nlme}
Hi, It works for me if i encapsulate the formula within a function a =1; b=1; f1 - function(x,v,w) {a/(b+(x/v)^w)} fm2 = gnls( y ~ f1(x,v,w), start=list( v=1, w=1)) Regards, Jost hong qin [EMAIL PROTECTED] writes: Hi All, I have question about speficifying a constant in gnls() from package nlme. Here is a testing code: # library(nlme) x = exp( rnorm(100)) y = 1/(1+x) + rnorm(100)/10 plot( y ~ x) fm1 = gnls( y ~ 1/(1+(x/v)^w), start=list( v=1, w=1)) a =1; b=1; fm2 = gnls( y ~ a/(b+(x/v)^w), start=list( v=1, w=1)) #This won't work because I don't know to set $a$ and $b$ as constant. Thanks, HQ [[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 and provide commented, minimal, self-contained, reproducible code. __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] Up- or downsampling time series in R
Hi I have data that is sampled (in time) with a certain frequency and I would like to express this time series as a time series of a higher (or lower) frequency with the newly added time points being filled in with NA, 0, or perhaps interpolated. My data might be regularly or irregularly spaced. For example, I might have quarterly data that I would like to handle as a monthly time series with NAs filled in for the missing months. RSiteSearch(upsample) gave one link to a function in the waveslim package that I'm not familiar with. It seems to me that this would be a fairly common time series task and thus am hoping to find something in the more common time series packages/classes such as ts, zoo, tseries, etc... I will now give some example code. If I am lucky enough that my data is irregularly spaced, then a combination of zoo and ts already accomplishes this task. require(zoo) [1] TRUE dt - sample(c(1,3,9), 20, replace=TRUE) t - zoo(dt, as.yearmon(Sys.Date()) + cumsum(dt)/12) t Jan 2007 Feb 2007 Nov 2007 Feb 2008 Nov 2008 Dec 2008 Mar 2009 Apr 2009 Jul 2009 Aug 2009 31939131 31 Nov 2009 Feb 2010 Nov 2010 Aug 2011 May 2012 Jun 2012 Jul 2012 Oct 2012 Jul 2013 Aug 2013 33999113 91 as.ts(t) Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 2007 3 1 NA NA NA NA NA NA NA NA 9 NA 2008 NA 3 NA NA NA NA NA NA NA NA 9 1 2009 NA NA 3 1 NA NA 3 1 NA NA 3 NA 2010 NA 3 NA NA NA NA NA NA NA NA 9 NA 2011 NA NA NA NA NA NA NA 9 NA NA NA NA 2012 NA NA NA NA 9 1 1 NA NA 3 NA NA 2013 NA NA NA NA NA NA 9 1 plot(t) However if the data happens to be regularly spaced, upsampling it isn't quite as straightforward. t2 - zoo(sample(1:3, 20, replace=TRUE), as.yearmon(seq(2000, by=0.5, length=20))) t2 Jan 2000 Jul 2000 Jan 2001 Jul 2001 Jan 2002 Jul 2002 Jan 2003 Jul 2003 Jan 2004 Jul 2004 33221312 33 Jan 2005 Jul 2005 Jan 2006 Jul 2006 Jan 2007 Jul 2007 Jan 2008 Jul 2008 Jan 2009 Jul 2009 22332332 13 (t2.ts - as.ts(t2)) Time Series: Start = c(2000, 1) End = c(2009, 2) Frequency = 2 [1] 3 3 2 2 1 3 1 2 3 3 2 2 3 3 2 3 3 2 1 3 plot(t2) I would expect this to be as simple as changing the frequency attribute of t2.ts to 12 but I didn't seem to be able to find out how to do this or if it is possible. So far, the only way around this that I have found is doing it manually in the following way: t2.monthly - zoo(NA, as.yearmon(seq(from=2000, to=2009.5, by=1/12))) window(t2.monthly, as.numeric(time(t2)) ) - as.numeric(t2)# can this be done using [] indexing? t2.monthly Jan 2000 Feb 2000 Mar 2000 Apr 2000 May 2000 Jun 2000 Jul 2000 Aug 2000 Sep 2000 Oct 2000 3 NA NA NA NA NA3 NA NA NA Nov 2000 Dec 2000 Jan 2001 Feb 2001 Mar 2001 Apr 2001 May 2001 Jun 2001 Jul 2001 Aug 2001 NA NA2 NA NA NA NA NA 2 NA Sep 2001 Oct 2001 Nov 2001 Dec 2001 Jan 2002 Feb 2002 Mar 2002 Apr 2002 May 2002 Jun 2002 NA NA NA NA1 NA NA NA NA NA Jul 2002 Aug 2002 Sep 2002 Oct 2002 Nov 2002 Dec 2002 Jan 2003 Feb 2003 Mar 2003 Apr 2003 3 NA NA NA NA NA1 NA NA NA May 2003 Jun 2003 Jul 2003 Aug 2003 Sep 2003 Oct 2003 Nov 2003 Dec 2003 Jan 2004 Feb 2004 NA NA2 NA NA NA NA NA 3 NA Mar 2004 Apr 2004 May 2004 Jun 2004 Jul 2004 Aug 2004 Sep 2004 Oct 2004 Nov 2004 Dec 2004 NA NA NA NA3 NA NA NA NA NA Jan 2005 Feb 2005 Mar 2005 Apr 2005 May 2005 Jun 2005 Jul 2005 Aug 2005 Sep 2005 Oct 2005 2 NA NA NA NA NA2 NA NA NA Nov 2005 Dec 2005 Jan 2006 Feb 2006 Mar 2006 Apr 2006 May 2006 Jun 2006 Jul 2006 Aug 2006 NA NA3 NA NA NA NA NA 3 NA Sep 2006 Oct 2006 Nov 2006 Dec 2006 Jan 2007 Feb 2007 Mar 2007 Apr 2007 May 2007 Jun 2007 NA NA NA NA2 NA NA NA NA NA Jul 2007 Aug 2007 Sep 2007 Oct 2007 Nov 2007 Dec 2007 Jan 2008 Feb 2008 Mar 2008 Apr 2008 3 NA NA NA NA NA3 NA NA NA May 2008 Jun 2008 Jul 2008 Aug 2008 Sep 2008 Oct 2008 Nov 2008 Dec 2008 Jan 2009 Feb 2009 NA NA2 NA NA NA NA NA 1 NA Mar 2009 Apr 2009 May 2009 Jun 2009 Jul 2009 NA NA NA NA3 points(t2.monthly, type=p,
[R] pairs matchning
Hi All, I have two numerical matrices of 2 columns and many rows. The two coulumns of matrix (1) form a number of 'pairs' of numbers, e.g: [,1] [,2] [1,]10 [2,]34 [3,]34 [4,]58 [5,]10 [6,]10 [7,]67 Matrix (2) contains the *unique* pairs: [,1] [,2] [1,]10 [2,]34 [3,]58 [4,]67 I would like to create a vector matching the pairs in matrix (1) to the unique pairs in matrix (2), e.g: [1] 1 2 2 3 1 1 4 (done by hand) match() does not seem to be able to handle pairs, and I don't seem to be able to find an elegant solution... Cheers, Federico -- Federico C. F. Calboli Department of Epidemiology and Public Health Imperial College, St Mary's Campus Norfolk Place, London W2 1PG Tel +44 (0)20 7594 1602 Fax (+44) 020 7594 3193 f.calboli [.a.t] imperial.ac.uk f.calboli [.a.t] gmail.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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] avoiding a loop
Mark, This is hardly a one-liner. It will only help you if you call it with large objects. If you have 0 in your data it needs even more extending. Here it is: myconstruct - function(aa) { aa - c(1,1,aa,1) bb - cumprod(aa) taa - aa1 difftaa - diff(taa) starts - which(c(FALSE,difftaa==1)) ends - which(c(FALSE,difftaa==-1)) correction - rep(0,length(aa)) correction[starts] - 1/bb[starts-2] correction[ends] - -1/bb[starts-2] correction - cumsum(correction) correction[correction==0] - 1 correction bbcor - bb*correction bbcor[!taa] - aa[!taa] bbcor[c(-1,-2,-length(bbcor))] } aa - runif(1,min=.5,max=1.5) system.time(target - constructLt(aa)) system.time(found - myconstruct(aa)) identical(target,found) max(abs(target-found)) system.time(target - constructLt(aa)) [1] 0.059 0.001 0.059 0.000 0.000 system.time(found - myconstruct(aa)) [1] 0.013 0.000 0.014 0.000 0.000 identical(target,found) [1] FALSE max(abs(target-found)) [1] 4.440892e-16 Appearently the outcome is different is some low decimal, due to other calculation method. Kees On Tuesday 24 October 2006 20:36, Leeds, Mark (IED) wrote: I think I asked a similar question 3 years ago to the Splus list and I think the answer was no or noone answered so noone should spend more than 5 minutes on this because it could definitely be a waste of time. My question is whether the function below can be rewritten without a for loop. apply is fine if it can be done that way but i doubt it. I call it a lot and would prefer to not loop. #--- -- constructLt-function(invector) { outvector-invector for ( i in 2:length(invector) ) { if ( invector[i] 1 ) { outvector[i]-invector[i]*outvector[i-1] } } return(outvector) } #--- - This is not an offer (or solicitation of an offer) to buy/sell the securities/instruments mentioned or an official confirmation. Morgan Stanley may deal as principal in or own or act as market maker for securities/instruments mentioned or may advise the issuers. This is not research and is not from MS Research but it may refer to a research analyst/research report. Unless indicated, these views are the author's and may differ from those of Morgan Stanley research or others in the Firm. We do not represent this is accurate or complete and we may not update this. Past performance is not indicative of future returns. For additional information, research reports and important disclosures, contact me or see https://secure.ms.com/servlet/cls. You should not use e-mail to request, authorize or effect the purchase or sale of any security or instrument, to send transfer instructions, or to effect any other transactions. We cannot guarantee that any such requests received via ! e-mail will be processed in a timely manner. This communication is solely for the addressee(s) and may contain confidential information. We do not waive confidentiality by mistransmission. Contact me if you do not wish to receive these communications. In the UK, this communication is directed in the UK to those persons who are market counterparties or intermediate customers (as defined in the UK Financial Services Authority's rules). [[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 and provide commented, minimal, self-contained, reproducible code. __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] pairs matchning
Hi You could try to find an equivalent representation as a string and try to match those. (A - cbind(sample(1:2, 10, rep=TRUE), sample(1:2, 10, rep=TRUE))) [,1] [,2] [1,]12 [2,]12 [3,]12 [4,]22 [5,]11 [6,]12 [7,]12 [8,]11 [9,]12 [10,]11 (B - unique(A)) [,1] [,2] [1,]12 [2,]22 [3,]11 strRep - function(mat) apply(mat, 1, function(x) paste(x, collapse=;)) strRep(B) [1] 1;2 2;2 1;1 (idx - match(strRep(A), strRep(B))) [1] 1 1 1 2 3 1 1 3 1 3 B[idx, ] [,1] [,2] [1,]12 [2,]12 [3,]12 [4,]22 [5,]11 [6,]12 [7,]12 [8,]11 [9,]12 [10,]11 HTH -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Federico Calboli Sent: 26 October 2006 06:48 PM To: r-help Subject: [R] pairs matchning Hi All, I have two numerical matrices of 2 columns and many rows. The two coulumns of matrix (1) form a number of 'pairs' of numbers, e.g: [,1] [,2] [1,]10 [2,]34 [3,]34 [4,]58 [5,]10 [6,]10 [7,]67 Matrix (2) contains the *unique* pairs: [,1] [,2] [1,]10 [2,]34 [3,]58 [4,]67 I would like to create a vector matching the pairs in matrix (1) to the unique pairs in matrix (2), e.g: [1] 1 2 2 3 1 1 4 (done by hand) match() does not seem to be able to handle pairs, and I don't seem to be able to find an elegant solution... Cheers, Federico -- Federico C. F. Calboli Department of Epidemiology and Public Health Imperial College, St Mary's Campus Norfolk Place, London W2 1PG Tel +44 (0)20 7594 1602 Fax (+44) 020 7594 3193 f.calboli [.a.t] imperial.ac.uk f.calboli [.a.t] gmail.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 and provide commented, minimal, self-contained, reproducible code. Nedbank Limited Reg No 1951/09/06. The following link displays the names of the Nedbank Board of Directors and Company Secretary. [ http://www.nedbank.co.za/terms/DirectorsNedbank.htm ] This email is confidential and is intended for the addressee only. The following link will take you to Nedbank's legal notice. [ http://www.nedbank.co.za/terms/EmailDisclaimer.htm ] __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] pairs matchning
Federico, Why not 1 convert to data frame dfo - as.data.frame(mat) 2 take unique items with ?unique df- unique(dfo) 3 add an index to the unique itmes df$unique - 1:nrow(df) 4 merge the two data.frames combi - merge(dfo,df) 5 extract the index? combi$unique Kees On Thursday 26 October 2006 18:47, Federico Calboli wrote: Hi All, I have two numerical matrices of 2 columns and many rows. The two coulumns of matrix (1) form a number of 'pairs' of numbers, e.g: [,1] [,2] [1,]10 [2,]34 [3,]34 [4,]58 [5,]10 [6,]10 [7,]67 Matrix (2) contains the *unique* pairs: [,1] [,2] [1,]10 [2,]34 [3,]58 [4,]67 I would like to create a vector matching the pairs in matrix (1) to the unique pairs in matrix (2), e.g: [1] 1 2 2 3 1 1 4 (done by hand) match() does not seem to be able to handle pairs, and I don't seem to be able to find an elegant solution... Cheers, Federico __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Quantile regression questions
Brian, It is hard to say at this level of resolution of the question, but it would seem that you might be able to start by considering each sample vector as as repeated measurement of the fiber length -- so 12 obs in the first 1/16th bin, 235 in the next and so forth, all associated with some vector of covariates representing location, variety, etc, then the conventional quantile regression would serve to estimate a conditional quantile function for fiber length for each possible covariate setting --- obviously this would require some model for the way that the covariate effects fit together, linearity, possible interactions, etc etc, and it would also presume that it made sense to treat the vector of responses as independent measurements. Building in possible dependence involves some new challenges, but there is some recent experience with inferential methods for microarrays that have incorporated these effects. I'd be happy to hear more about the data and possible models, but this should be routed privately since the topic is rather too specialized for R-help. url:www.econ.uiuc.edu/~rogerRoger Koenker email[EMAIL PROTECTED]Department of Economics vox: 217-333-4558University of Illinois fax: 217-244-6678Champaign, IL 61820 On Oct 26, 2006, at 7:20 AM, Brian Gardunia wrote: I am relatively new to R, but am intrigued by its flexibility. I am interested in quantile regression and quantile estimation as regards to cotton fiber length distributions. The length distribution affects spinning and weaving properties, so it is desirable to select for certain distribution types. The AFIS fiber testing machinery outputs a vector for each sample of type c(12, 235, 355, . . . n) with the number of fibers in n=40 1/16 inch length categories. My question is what would be the best way to convert the raw output to quantiles and whether it would be appropriate to use quantile regression to look at whether location, variety, replication, etc. modify the length distribution. __ 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 and provide commented, minimal, self-contained, reproducible code. __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] pairs matchning
If all of the numbers are one-digit numbers, as your subset shows, you can create a third column equal to 10 * col 1 + col 2, and then use match() on the resulting two-digit numbers, no? If the numbers are larger than one-digit, and you know the maximum, use that rather than 10 as the multiplier. Ben -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Federico Calboli Sent: Thursday, October 26, 2006 11:48 AM To: r-help Subject: [R] pairs matchning Hi All, I have two numerical matrices of 2 columns and many rows. The two coulumns of matrix (1) form a number of 'pairs' of numbers, e.g: [,1] [,2] [1,]10 [2,]34 [3,]34 [4,]58 [5,]10 [6,]10 [7,]67 Matrix (2) contains the *unique* pairs: [,1] [,2] [1,]10 [2,]34 [3,]58 [4,]67 I would like to create a vector matching the pairs in matrix (1) to the unique pairs in matrix (2), e.g: [1] 1 2 2 3 1 1 4 (done by hand) match() does not seem to be able to handle pairs, and I don't seem to be able to find an elegant solution... Cheers, Federico -- Federico C. F. Calboli Department of Epidemiology and Public Health Imperial College, St Mary's Campus Norfolk Place, London W2 1PG Tel +44 (0)20 7594 1602 Fax (+44) 020 7594 3193 f.calboli [.a.t] imperial.ac.uk f.calboli [.a.t] gmail.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 and provide commented, minimal, self-contained, reproducible code. __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Up- or downsampling time series in R
On Thu, 26 Oct 2006, Brandt, T. (Tobias) wrote: I have data that is sampled (in time) with a certain frequency and I would like to express this time series as a time series of a higher (or lower) frequency with the newly added time points being filled in with NA, 0, or perhaps interpolated. My data might be regularly or irregularly spaced. For example, I might have quarterly data that I would like to handle as a monthly time series with NAs filled in for the missing months. Both can be done easily with zoo, examples for both are given in the package vignettes and the man pages of the package. 1. extend to a finer grid (upsampling) ## generate some time series z - zoo(sample(1:3, 20, replace=TRUE), as.yearmon(seq(2000, by=0.5, length=20))) ## generate emtpy series on finer grid z2 - zoo(,seq(start(z), end(z), by = 1/12)) ## merge (returns univariate series, by default filled with NAs) merge(z, z2) 2. aggregate to a coarser grid (downsampling) ## transform to annual data as.annual - function(x) floor(as.numeric(x)) ## average within years aggregate(z, as.annual, mean) ## first observation within year aggregate(z, as.annual, head, 1) hth, Z __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] cloud() works but wireframe() is blank
--On Wednesday, October 25, 2006 4:46 PM -0700 Deepayan Sarkar [EMAIL PROTECTED] wrote: On 10/25/06, Larry Layne [EMAIL PROTECTED] wrote: Per the message from Alexander Nervedi, 29 April 2006: I have to be making a riddiculously silly ommission. when I run the fillowing i get the cloud plot ok. But I cant figure out what I am missing out when I call wireframe. Any help would be appreciated. x-runif(100) y-rnorm(100) z-runif(100) temp -data.frame(x,y,z) wireframe(x~y*z,temp) cloud(x~y*z,temp) There is something funny about the way wireframe treats a data frame object created using data.frame vs. using expand.grid. For instance, this works: There's nothing funny about it, ?wireframe clearly says: In the case of 'wireframe', calculations are based on the assumption that the 'x' and 'y' values are evaluated on a rectangular grid defined by their unique values. Sorry about incorrectly interpreting this part of the description about wireframe. In the original example, the (x, y) values are clearly not on a grid, and in your (very strange) example below, they are not on a rectangular grid, as can be seen using xyplot(u ~ v, reggrid) One of the nice things about posting questions in a list is that it is so conveniently easy to embarrass oneself in public. The corrected code follows and works just fine: library(lattice) ###MAKE-BELIEVE DATA u - mat.or.vec(100,1) v - mat.or.vec(100,1) ij=0 for(i in 1:10) { for(j in 1:10) { ij=ij+1 u[ij]=i v[ij]=j } } z - runif(100) reggrid - data.frame(u,v,z) is.data.frame(reggrid) wireframe(z~u*v,reggrid,scales=list(arrows=FALSE),drape=TRUE,colorkey=TRUE) In addition, I would also like to do what Alexander is trying to do, which is create a wireframe from irregular lattice data. Although what I would really like to do is plot a 3D Triangulated Irregular Network (TIN) surface of the irregularly spaced points, the following sort of gets me there in the short-term: ##INTERPOLATE USING AKIMA PACKAGE AND PLOT SURFACES library(akima) library(lattice) #MAKE-BELIEVE DATA u - runif(30) v - runif(30) z - runif(30) #LINEAR INTERPOLATION reggrid - interp(u,v,z,linear=TRUE,extrap=FALSE) #WIREFRAME SURFACE PLOT FROM INTERPOLATED DATA wireframe(reggrid$z,scales=list(arrows=FALSE),drape=TRUE,colorkey=TRUE) #PLOT IMAGE, CONTOUR, AND POINTS plot(u,v) image (reggrid,add=TRUE) contour(reggrid,add=TRUE) points (u,v,pch = 3) Larry Layne __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] Header of dataframe
Hi I am fairly new to R and I would appreciate some help to hopefully a trivial problem. I created a function: summary.aggregate - function(y, ...) { temp.mean - aggregate(y, FUN=mean, ...) temp.sd - aggregate(y, FUN=sd, ...) temp.length - aggregate(y, FUN=length, ...) temp - data.frame(cbind(mean=temp.mean$x,stdev=temp.sd$x,n=temp.length$x)) } this outputs e.g.: meanstdev n 1 645.6125 65.94129 60 2 655.2121 70.64094 60 3 633.3161 80.48620 60 4 650.3897 77.59191 60 5 630.4955 84.9 60 6 656.2608 66.16100 60 7 666.1775 74.39796 60 8 663.1543 71.10769 60 Is there an easy way to add a column name to the first column? Thank you, Benjamin __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] function to normalize vectors?
Hello all. I can find no function to compute norms (even the basic two-norm) of a vector in the online help (within the GUI) or the downloadable documentation. Thanks. - dan elliott [[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 and provide commented, minimal, self-contained, reproducible code.
[R] Generating tables
I am actually trying to write something above the first column ( in the example the column with numbers 1 to 8) is this possible at all? If not, is there another way to make a table which supports this? I am merely using a data frame as a way to create a table I don't need the data to be this data type. Benjamin On 10/26/06, Leeds, Mark (IED) [EMAIL PROTECTED] wrote: I think colnames(DF)-c(meanname,sdname,nname) should work if that's what you want. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Benjamin Dickgiesser Sent: Thursday, October 26, 2006 1:08 PM To: r-help@stat.math.ethz.ch Subject: [R] Header of dataframe Hi I am fairly new to R and I would appreciate some help to hopefully a trivial problem. I created a function: summary.aggregate - function(y, ...) { temp.mean - aggregate(y, FUN=mean, ...) temp.sd - aggregate(y, FUN=sd, ...) temp.length - aggregate(y, FUN=length, ...) temp - data.frame(cbind(mean=temp.mean$x,stdev=temp.sd$x,n=temp.length$x)) } this outputs e.g.: meanstdev n 1 645.6125 65.94129 60 2 655.2121 70.64094 60 3 633.3161 80.48620 60 4 650.3897 77.59191 60 5 630.4955 84.9 60 6 656.2608 66.16100 60 7 666.1775 74.39796 60 8 663.1543 71.10769 60 Is there an easy way to add a column name to the first column? Thank you, Benjamin __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] help fo finding R package utils
Amina, The best way for entering data in R is by importing an existing data file (text, Excel etc). This will reduce time and potential data entry errors. Please read Section 7 of the Introduction to R manual for a detailed discussion of available options. The manuals are available on your system (Help menu in the R Console for Windows) or through the R web site. Regards, -Christos _ From: amna khan [mailto:[EMAIL PROTECTED] Sent: Thursday, October 26, 2006 1:21 PM To: [EMAIL PROTECTED] Subject: Re: [R] help fo finding R package utils Respected sir I have a great problem for data entry in R. using sessionInfo() utils has appeared. but while entring data there is a message of no object found. Sir is there any option for spreadsheet for data entry. I shall be thankful to you. Amina On 10/25/06, Christos Hatzis [EMAIL PROTECTED] wrote: Amina, utils is a base package and should be already installed in a functional R system. You can try sessionInfo() to verify that it is loaded. -Christos -Original Message- From: [EMAIL PROTECTED] [mailto: [EMAIL PROTECTED] On Behalf Of amna khan Sent: Thursday, October 26, 2006 12:11 AM To: R-help@stat.math.ethz.ch mailto:R-help@stat.math.ethz.ch Subject: [R] help fo finding R package utils Sir I have a problem that from which country i can assess R package utils for data entry for loading it in R Please help me in this regard. -- AMINA SHAHZADI Department of Statistics GC University Lahore, Pakistan. Email: [EMAIL PROTECTED] [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] [EMAIL PROTECTED] [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailto: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 http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- AMINA SHAHZADI Department of Statistics GC University Lahore, Pakistan. Email: [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] [[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 and provide commented, minimal, self-contained, reproducible code.
[R] Query about using table
Hi I have data of the following form ID age member_FLAG 125 Y 236.75 N 375.5N . . I want to get a histogram of this data showing distribution of member_flag in each age-bin i.e. how many values in each age bin have a member_flag of 'Y' and how many have 'N'. I was able to do the same using barplot2. However I also need similar information in a tabular form using percentages. i.e in each age bin, what is the PERCENTAGE of IDs with a member_flag of 'Y' I am trying to work with table for the same, but would appreciate some guidance regarding the above. Thanks Lalitha __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] Query about using table
Hi I have data of the following form ID age member_FLAG 125 Y 236.75 N 375.5N . . I want to get a histogram of this data showing distribution of member_flag in each age-bin i.e. how many values in each age bin have a member_flag of 'Y' and how many have 'N'. I was able to do the same using barplot2. However I also need similar information in a tabular form using percentages. i.e in each age bin, what is the PERCENTAGE of IDs with a member_flag of 'Y' I am trying to work with table for the same, but would appreciate some guidance regarding the above. Thanks Lalitha __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] help fo finding R package utils
Please reply to the list, not to me personally. When I want to import an Excel file, I usually save it as a tab-delimited text file and use read.delim to import it: my.dataframe - read.delim(file.name.txt, header=TRUE, sep=\t) See ?read.delim for further details. There are many other options, I'm sure, but this is simple and flexible and does not require any additional packages. Good luck. -Christos From: amna khan [mailto:[EMAIL PROTECTED] Sent: Thursday, October 26, 2006 2:41 PM To: [EMAIL PROTECTED] Subject: Re: [R] help fo finding R package utils sir i have downloaded poptools for excel to import data but still feeling problems. I am not understanding what I should do? On 10/26/06, Christos Hatzis [EMAIL PROTECTED] wrote: Amina, The best way for entering data in R is by importing an existing data file (text, Excel etc). This will reduce time and potential data entry errors. Please read Section 7 of the Introduction to R manual for a detailed discussion of available options. The manuals are available on your system (Help menu in the R Console for Windows) or through the R web site. Regards, -Christos From: amna khan [mailto:[EMAIL PROTECTED] Sent: Thursday, October 26, 2006 1:21 PM To: [EMAIL PROTECTED] Subject: Re: [R] help fo finding R package utils Respected sir I have a great problem for data entry in R. using sessionInfo() utils has appeared. but while entring data there is a message of no object found. Sir is there any option for spreadsheet for data entry. I shall be thankful to you. Amina On 10/25/06, Christos Hatzis [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Amina, utils is a base package and should be already installed in a functional R system. You can try sessionInfo() to verify that it is loaded. -Christos -Original Message- From: [EMAIL PROTECTED] [mailto: [EMAIL PROTECTED] On Behalf Of amna khan Sent: Thursday, October 26, 2006 12:11 AM To: R-help@stat.math.ethz.ch mailto:R-help@stat.math.ethz.ch Subject: [R] help fo finding R package utils Sir I have a problem that from which country i can assess R package utils for data entry for loading it in R Please help me in this regard. -- AMINA SHAHZADI Department of Statistics GC University Lahore, Pakistan. Email: [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailto: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 and provide commented, minimal, self-contained, reproducible code. -- AMINA SHAHZADI Department of Statistics GC University Lahore, Pakistan. Email: [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] -- AMINA SHAHZADI Department of Statistics GC University Lahore, Pakistan. Email: [EMAIL PROTECTED] [EMAIL PROTECTED] [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 and provide commented, minimal, self-contained, reproducible code.
[R] latent class model
Dear List, I try to implement the latent class model with the unknown number of classes. I wonder whether someone can provide me some sample codes. Thank you for your help. Karen [[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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Query about using table
Lalitha, Try something like with(data, table(cut(age, n), member_FLAG)) where data is a data frame with columns named age and member_FLAG and n is the number of age categories (bins) you want. This will give you the number of Ys and Ns in each bin, that you will need to convert to percentages. Also, you might want to check the help pages for table and cut. Cheers, Andy __ Andy Jaworski 518-1-01 Process Laboratory 3M Corporate Research Laboratory - E-mail: [EMAIL PROTECTED] Tel: (651) 733-6092 Fax: (651) 736-3122 lalitha viswanath lalithaviswanath @yahoo.comTo Sent by: r-help@stat.math.ethz.ch [EMAIL PROTECTED] cc at.math.ethz.ch Subject [R] Query about using table 10/26/2006 01:44 PM Hi I have data of the following form ID age member_FLAG 125 Y 236.75 N 375.5N . . I want to get a histogram of this data showing distribution of member_flag in each age-bin i.e. how many values in each age bin have a member_flag of 'Y' and how many have 'N'. I was able to do the same using barplot2. However I also need similar information in a tabular form using percentages. i.e in each age bin, what is the PERCENTAGE of IDs with a member_flag of 'Y' I am trying to work with table for the same, but would appreciate some guidance regarding the above. Thanks Lalitha __ 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 and provide commented, minimal, self-contained, reproducible code. __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] distance between legend title and legend box
Hi Denis Chabot wrote: Hi, I've looked at the parameters available for the legend function and cannot find a way to change the distance between the top of the box surrounding a legend and the legend's title. I have a math expression that raises the height of my title. If you don't mind the non-sensical title I give to the legend for this plot (Figure 3.20 in R Graphics): with(iris, plot(Sepal.Length, Sepal.Width, pch=as.numeric(Species), cex=1.2)) legend(6.5, 4.2, c(setosa, versicolor, virginica), cex=1, pch=1:3, title=expression(kg/km^2)) The result depends on the device, but I think any device will show the box needs to be raised a bit (in quartz, the top of the box passes in the middle of the 2, in pdf it is acceptable, but just (the top of the box lightly touches the top of the 2). Looking at the source for legend(), it only expects the title to be zero or 1 lines high (i.e., either no title or a title that is one line of normal text high). It needs a rewrite to allow for the exact height of the title text. Paul Sincerely, Denis Chabot __ 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 and provide commented, minimal, self-contained, reproducible code. -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 [EMAIL PROTECTED] http://www.stat.auckland.ac.nz/~paul/ __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] Newbie: Better way to do compound conditionals in subset?
There must be a better way to select the rows after 22-Apr-2004 and before 01-Sep-2004 with a temperature below 65 than this: before2sw1 - subset(energy.data, as.Date(start, format=%d-%b-%y) as.Date(01-Sep-04, format = %d-%b-%y)) before2sw2 - subset(before2sw1, as.Date(start, format=%d-%b-%y) = as.Date(22-Apr-04, format = %d-%b-%y), select=c(therms,temp,days)) before2sw - subset(before2sw2, temp 65) Is it also possible to combine in this step: attach(before2sw) before2sw.HDD - therms / (65 - temp) * days My data looks like this: head(energy.data) start therms gas KWHs elect temp days 1 10-Jun-98 9 16.84 613 63.80 75 40 2 20-Jul-98 6 15.29 721 74.21 76 29 3 18-Aug-98 7 15.73 597 62.22 76 29 4 16-Sep-98 42 35.81 460 43.98 70 33 5 19-Oct-98105 77.28 314 31.45 57 29 6 17-Nov-98106 77.01 342 33.86 48 30 Thanks for your suggestions and advice. I'm continuing to enjoy learning R. -Kevin Kevin Zembower Internet Services Group manager Center for Communication Programs Bloomberg School of Public Health Johns Hopkins University 111 Market Place, Suite 310 Baltimore, Maryland 21202 410-659-6139 __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] Turn off border on barplot
I was wondering if there was any way to completely remove the borders around each bar when using the barplot function. I understand how to change the color of the border (border=white), but I need the border to be invisible so I can plot many skinny bars right next to each other with only the bar's color visible. Thanks, Frank -- Frank McCown Old Dominion University http://www.cs.odu.edu/~fmccown/ __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Newbie: Better way to do compound conditionals in subset?
I would personally use the following method (example using the iris data included with R): data(iris) tSelect - (iris$Sepal.Length 6.0 iris$Sepal.Length 6.2 iris $Sepal.Width == 3.0) tSelectedData - iris[tSelect,] Then you can simply work with tSelectedData for whatever equation you use, i.e.: tSelectedData$Sepal.Length - tSelectedData$Sepal.Width Of course you could write all of this on one line, but that doesn't read well. Hope that helps, Jeff. On Oct 26, 2006, at 3:55 PM, Zembower, Kevin wrote: There must be a better way to select the rows after 22-Apr-2004 and before 01-Sep-2004 with a temperature below 65 than this: before2sw1 - subset(energy.data, as.Date(start, format=%d-%b-%y) as.Date(01-Sep-04, format = %d-%b-%y)) before2sw2 - subset(before2sw1, as.Date(start, format=%d-%b-%y) = as.Date(22-Apr-04, format = %d-%b-%y), select=c(therms,temp,days)) before2sw - subset(before2sw2, temp 65) Is it also possible to combine in this step: attach(before2sw) before2sw.HDD - therms / (65 - temp) * days My data looks like this: head(energy.data) start therms gas KWHs elect temp days 1 10-Jun-98 9 16.84 613 63.80 75 40 2 20-Jul-98 6 15.29 721 74.21 76 29 3 18-Aug-98 7 15.73 597 62.22 76 29 4 16-Sep-98 42 35.81 460 43.98 70 33 5 19-Oct-98105 77.28 314 31.45 57 29 6 17-Nov-98106 77.01 342 33.86 48 30 Thanks for your suggestions and advice. I'm continuing to enjoy learning R. -Kevin Kevin Zembower Internet Services Group manager Center for Communication Programs Bloomberg School of Public Health Johns Hopkins University 111 Market Place, Suite 310 Baltimore, Maryland 21202 410-659-6139 __ 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 and provide commented, minimal, self-contained, reproducible code. __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] applying order() in a for loop
Hi, with the code below I try to organize sections of a data.frame. The dataframe has 9 data columns. I'd like to order the columns of the data.frame by the sum of the columns' entries. The sections of the columns are identified by i. The order of the columns is given by the vector z. Each section of the data.frame is ordered differently. This can be seen when looking at the individual rows of h where all different z vectors are stored for later use. In a third for loop, e is calculated based on the ordering calculated before. e is the re-organized data.frame with now all column segments in descending order -- in theory. Problem: The code below does not update the z in the third for loop. It remains the initial z that I calculate the first time around. I tried re-initializing z at various places in the code, hoping to get rid of the old values but with no apparent consequences. Also in the help I could not find anything that I could relate to my problem. Does anybody have a suggestion on how to get the appropriate z to work when shuffling the data around for e? Thanks already for suggestions! Kim ### Code for (i in 11:19) { for (j in 3:ncol(data)) { a - sum(data[,j][data[,1] == i/10]) b - c(b,a) } z - order(b, decreasing = TRUE) d - length(data[,1][data[,1] == i/10]) h - rbind(h,z) ### Just to check whether I really get different orderings for the different data segments. for (l in 1:d) { e - data[((i-10)*d+l-d),(3:ncol(data))][z] ## This z does not get updated but remains the initially calculated z f - rbind(f,e) } b - NULL e - NULL z - NULL } __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Header of dataframe
names(temp)[1]=a see: ?names did you really created that function :-)? Mihai Nica 170 East Griffith St. G5 Jackson, MS 39201 601-914-0361 - Original Message From: Benjamin Dickgiesser [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Thursday, October 26, 2006 12:08:08 PM Subject: [R] Header of dataframe Hi I am fairly new to R and I would appreciate some help to hopefully a trivial problem. I created a function: summary.aggregate - function(y, ...) { temp.mean - aggregate(y, FUN=mean, ...) temp.sd - aggregate(y, FUN=sd, ...) temp.length - aggregate(y, FUN=length, ...) temp - data.frame(cbind(mean=temp.mean$x,stdev=temp.sd$x,n=temp.length$x)) } this outputs e.g.: meanstdev n 1 645.6125 65.94129 60 2 655.2121 70.64094 60 3 633.3161 80.48620 60 4 650.3897 77.59191 60 5 630.4955 84.9 60 6 656.2608 66.16100 60 7 666.1775 74.39796 60 8 663.1543 71.10769 60 Is there an easy way to add a column name to the first column? Thank you, Benjamin __ 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 and provide commented, minimal, self-contained, reproducible code. [[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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Turn off border on barplot
On Thu, 2006-10-26 at 16:13 -0400, Frank McCown wrote: I was wondering if there was any way to completely remove the borders around each bar when using the barplot function. I understand how to change the color of the border (border=white), but I need the border to be invisible so I can plot many skinny bars right next to each other with only the bar's color visible. Thanks, Frank You can try: # Set line type to blank # See ?par # First save current value lty.o - par(lty) par(lty = 0) # Also set space to 0, rather # than default 0.2, if needed for more room barplot(1:10, space = 0) # Reset to old value par(lty = lty.o) Depending upon the look you need, setting space to 0 may be sufficient and still allow you to enable a border. 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Newbie: Better way to do compound conditionals in subset?
Jeffrey Robert Spies [EMAIL PROTECTED] writes: I would personally use the following method (example using the iris data included with R): data(iris) tSelect - (iris$Sepal.Length 6.0 iris$Sepal.Length 6.2 iris $Sepal.Width == 3.0) tSelectedData - iris[tSelect,] Then you can simply work with tSelectedData for whatever equation you use, i.e.: tSelectedData$Sepal.Length - tSelectedData$Sepal.Width Of course you could write all of this on one line, but that doesn't read well. Hope that helps, But why not use subset()? For a neat way around the as.Date business, consider between - function(x,x1,x2) x = x1 x x2 begin - as.Date(2004-04-22) end - as.Date(2004-09-01) before2sw - subset(energy.data, between(as.Date(start, format=%d-%b-%y), begin, end) temp 65) Jeff. On Oct 26, 2006, at 3:55 PM, Zembower, Kevin wrote: There must be a better way to select the rows after 22-Apr-2004 and before 01-Sep-2004 with a temperature below 65 than this: before2sw1 - subset(energy.data, as.Date(start, format=%d-%b-%y) as.Date(01-Sep-04, format = %d-%b-%y)) before2sw2 - subset(before2sw1, as.Date(start, format=%d-%b-%y) = as.Date(22-Apr-04, format = %d-%b-%y), select=c(therms,temp,days)) before2sw - subset(before2sw2, temp 65) Is it also possible to combine in this step: attach(before2sw) before2sw.HDD - therms / (65 - temp) * days My data looks like this: head(energy.data) start therms gas KWHs elect temp days 1 10-Jun-98 9 16.84 613 63.80 75 40 2 20-Jul-98 6 15.29 721 74.21 76 29 3 18-Aug-98 7 15.73 597 62.22 76 29 4 16-Sep-98 42 35.81 460 43.98 70 33 5 19-Oct-98105 77.28 314 31.45 57 29 6 17-Nov-98106 77.01 342 33.86 48 30 Thanks for your suggestions and advice. I'm continuing to enjoy learning R. -Kevin Kevin Zembower Internet Services Group manager Center for Communication Programs Bloomberg School of Public Health Johns Hopkins University 111 Market Place, Suite 310 Baltimore, Maryland 21202 410-659-6139 __ 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 and provide commented, minimal, self-contained, reproducible code. __ 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 and provide commented, minimal, self-contained, reproducible code. -- 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 and provide commented, minimal, self-contained, reproducible code.
[R] Organisation of medium/large projects with multiple analyses
Dear all, I'm still new to R, but have a fair experience with general programming. All of my data is stored in postgresql, and I have a number of R files that generate tables, results, graphs etc. These are then available to be imported into powerpoint/latex etc. I'm using version control (subversion), and as with most small projects, now have an ever increasing number of R scripts, each with fairly specific features. With any enlarging project, there are always issues regarding interdependencies, shared commonality (eg accessing same data store), and old scripts stopping working with changes made elsewhere (eg to data schema). For example, I might have a specific inclusion and exclusion criteria for patients, and this SQL query may have to be included in a number of analyses; I'm tempted to factor this out into a project-specific data access library, but is that over the top? This is a very long-winded and roundabout way of asking people how they organise medium-sized projects? Do people create their own libraries for specific projects for shared functionality, or do people just liberally use source() for this kind of thing? What about namespaces? I've got unwieldy sounding functions like ataxia.repeats.plot.alleles() and often these functions are not particularly generic, and are only called three or four times, but they do save repetition. Do you go to the effort of creating a library that solves your particular problem, or only reserve that for more generic functionality? Do people keep all of their R scripts for a specific project separate, or in one big file? I can see advantages (knowing it all works) and disadvantages (time for it all to run after minor changes) in both approaches, but it is unclear to me which is better. I do know that I've set-up a variety of analyses, moved on to other things, only to find later on that old scripts have stopped working because I've changed some interdependency. Does anyone go as far as to use test suites to check for sane output (apart from doing things manually)? Note I'm not asking about how to run R on all these scripts, as people have already suggested makefiles. I realise these are vague high-level questions, and there won't be any right or wrong answers, but I'm grateful to hear about different strategies in organising R analyses/files, and how people solve these problems? I've not seen this kind of thing covered in any of the textbooks. Apologies for being so verbose! Best wishes, Mark -- Dr. Mark Wardle Clinical research fellow and Specialist Registrar in Neurology, C2-B2 link, Cardiff University, Heath Park, CARDIFF, CF14 4XN. UK __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Turn off border on barplot
Hi Marc Schwartz wrote: On Thu, 2006-10-26 at 16:13 -0400, Frank McCown wrote: I was wondering if there was any way to completely remove the borders around each bar when using the barplot function. I understand how to change the color of the border (border=white), but I need the border to be invisible so I can plot many skinny bars right next to each other with only the bar's color visible. Thanks, Frank You can try: # Set line type to blank # See ?par # First save current value lty.o - par(lty) par(lty = 0) # Also set space to 0, rather # than default 0.2, if needed for more room barplot(1:10, space = 0) # Reset to old value par(lty = lty.o) or ... barplot(1:10, border=NA) Paul Depending upon the look you need, setting space to 0 may be sufficient and still allow you to enable a border. 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 and provide commented, minimal, self-contained, reproducible code. -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 [EMAIL PROTECTED] http://www.stat.auckland.ac.nz/~paul/ __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Turn off border on barplot
barplot(1:10, border=NA) That's it! Thanks a ton, guys. Frank __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Header of dataframe
Thx for the help but again, this is not what I am looking for. I need the a to be over the first column e.g. ameanstdev n 1 645.6125 65.94129 60 2 655.2121 70.64094 60 3 633.3161 80.48620 60 4 650.3897 77.59191 60 5 630.4955 84.9 60 6 656.2608 66.16100 60 7 666.1775 74.39796 60 8 663.1543 71.10769 60 On 10/26/06, Mihai Nica [EMAIL PROTECTED] wrote: names(temp)[1]=a see: ?names did you really created that function :-)? Mihai Nica 170 East Griffith St. G5 Jackson, MS 39201 601-914-0361 - Original Message From: Benjamin Dickgiesser [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Thursday, October 26, 2006 12:08:08 PM Subject: [R] Header of dataframe Hi I am fairly new to R and I would appreciate some help to hopefully a trivial problem. I created a function: summary.aggregate - function(y, ...) { temp.mean - aggregate(y, FUN=mean, ...) temp.sd - aggregate(y, FUN=sd, ...) temp.length - aggregate(y, FUN=length, ...) temp - data.frame(cbind(mean=temp.mean$x,stdev=temp.sd$x,n=temp.length$x)) } this outputs e.g.: meanstdev n 1 645.6125 65.94129 60 2 655.2121 70.64094 60 3 633.3161 80.48620 60 4 650.3897 77.59191 60 5 630.4955 84.9 60 6 656.2608 66.16100 60 7 666.1775 74.39796 60 8 663.1543 71.10769 60 Is there an easy way to add a column name to the first column? Thank you, Benjamin __ 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 and provide commented, minimal, self-contained, reproducible code. __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Turn off border on barplot
On Fri, 2006-10-27 at 10:00 +1300, Paul Murrell wrote: Hi Marc Schwartz wrote: On Thu, 2006-10-26 at 16:13 -0400, Frank McCown wrote: I was wondering if there was any way to completely remove the borders around each bar when using the barplot function. I understand how to change the color of the border (border=white), but I need the border to be invisible so I can plot many skinny bars right next to each other with only the bar's color visible. Thanks, Frank You can try: # Set line type to blank # See ?par # First save current value lty.o - par(lty) par(lty = 0) # Also set space to 0, rather # than default 0.2, if needed for more room barplot(1:10, space = 0) # Reset to old value par(lty = lty.o) or ... barplot(1:10, border=NA) Paul Yep, that'll do it too... :-) Thanks Paul. I had forgotten about that. The only place that particular behavior seems documented is in ?par in the Color Specification section. Does it make sense to add that to relevant See Also's? Best regards, Marc __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Header of dataframe
Oh, I can see now what you mean. That's beyond me, but... why :-)? Mihai Nica 170 East Griffith St. G5 Jackson, MS 39201 601-914-0361 - Original Message From: Benjamin Dickgiesser [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Thursday, October 26, 2006 4:35:20 PM Subject: Re: [R] Header of dataframe Thx for the help but again, this is not what I am looking for. I need the a to be over the first column e.g. ameanstdev n 1 645.6125 65.94129 60 2 655.2121 70.64094 60 3 633.3161 80.48620 60 4 650.3897 77.59191 60 5 630.4955 84.9 60 6 656.2608 66.16100 60 7 666.1775 74.39796 60 8 663.1543 71.10769 60 On 10/26/06, Mihai Nica [EMAIL PROTECTED] wrote: names(temp)[1]=a see: ?names did you really created that function :-)? Mihai Nica 170 East Griffith St. G5 Jackson, MS 39201 601-914-0361 - Original Message From: Benjamin Dickgiesser [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Thursday, October 26, 2006 12:08:08 PM Subject: [R] Header of dataframe Hi I am fairly new to R and I would appreciate some help to hopefully a trivial problem. I created a function: summary.aggregate - function(y, ...) { temp.mean - aggregate(y, FUN=mean, ...) temp.sd - aggregate(y, FUN=sd, ...) temp.length - aggregate(y, FUN=length, ...) temp - data.frame(cbind(mean=temp.mean$x,stdev=temp.sd$x,n=temp.length$x)) } this outputs e.g.: meanstdev n 1 645.6125 65.94129 60 2 655.2121 70.64094 60 3 633.3161 80.48620 60 4 650.3897 77.59191 60 5 630.4955 84.9 60 6 656.2608 66.16100 60 7 666.1775 74.39796 60 8 663.1543 71.10769 60 Is there an easy way to add a column name to the first column? Thank you, Benjamin __ 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 and provide commented, minimal, self-contained, reproducible code. __ 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 and provide commented, minimal, self-contained, reproducible code. [[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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Newbie: Better way to do compound conditionals in subset?
On Thu, 2006-10-26 at 15:55 -0400, Zembower, Kevin wrote: There must be a better way to select the rows after 22-Apr-2004 and before 01-Sep-2004 with a temperature below 65 than this: before2sw1 - subset(energy.data, as.Date(start, format=%d-%b-%y) as.Date(01-Sep-04, format = %d-%b-%y)) before2sw2 - subset(before2sw1, as.Date(start, format=%d-%b-%y) = as.Date(22-Apr-04, format = %d-%b-%y), select=c(therms,temp,days)) before2sw - subset(before2sw2, temp 65) Well, the first thing that I would do is to convert 'start' to a Date: energy.data$start - as.Date(energy.data$start, format = %d-%b-%y) Then create your cutoff dates: Start - as.Date(22-Apr-04, format = %d-%b-%y) End - as.Date(01-Sep-04, format = %d-%b-%y) Then you can do this: New.DF - subset(energy.data, (start = Start) (start End) (days 65), select = c(therms, temp, days)) and then add: NewDF$HDD - with(NewDF, (therms / (65 - temp) * days)) You can also do the calculations and add a new column to the full data frame and simply add 'HDD' to the 'select' argument in subset(). Note that if you don't want to modify the original data frame, which is something that I tend to avoid for a variety of reasons, you can copy it to another first and then run the above steps on the copy for subsequent analysis. You want to generally avoid using attach(), as it can have deleterious and not immediately evident side-effects. Review the Details section of ?attach and note some of the effects seen in the Examples there. HTH, Marc Schwartz Is it also possible to combine in this step: attach(before2sw) before2sw.HDD - therms / (65 - temp) * days My data looks like this: head(energy.data) start therms gas KWHs elect temp days 1 10-Jun-98 9 16.84 613 63.80 75 40 2 20-Jul-98 6 15.29 721 74.21 76 29 3 18-Aug-98 7 15.73 597 62.22 76 29 4 16-Sep-98 42 35.81 460 43.98 70 33 5 19-Oct-98105 77.28 314 31.45 57 29 6 17-Nov-98106 77.01 342 33.86 48 30 Thanks for your suggestions and advice. I'm continuing to enjoy learning R. -Kevin __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] Adding shading to background of Time series plot
Hello All, Thank you in advance. I have looked up and down in the archives to see if I could find some help on moving the polygons to the background of a ts.plot. I've tried panel.first in the gpars(...) arguments and trellis.focus, but I get errors. Am I missing something easy here? Here is my script: ts.plot(tsdjia, tstenyield, gpars = list(xlab = , ylab = , axes=FALSE, col=c(12,14))) mtext(Time, side=1, line=3, cex = 0.75, font = 1) mtext(Yield, side=4, line=1, cex = 0.75, font = 1) mtext(Dow Jones Level, side=2, line=2, cex = 0.7, font = 1) polygon(cord.x2,cord.y1,col = gray85) polygon(cord.x3,cord.y1,col = gray85) polygon(cord.x4,cord.y1,col = gray85) polygon(cord.x5,cord.y1,col = gray85) polygon(cord.x6,cord.y1,col = gray85) __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] A faster way to calculate Trace?
I want to know how to get trace of product of matrices **faster** when the matrices are really big. Unfortunately the matrices are not symmetric. If anybody know how to get the trace of it, please help me. An example is as below. n - 2500 a - matrix(rnorm(n*n),n,n) b - matrix(rnorm(n*n),n,n) tr1 - sum(diag(a %*% b)) tr2 - sum(diag(a %*% b %*% a %*% b)) Thanks, Yongwan Chun __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Get the names of the columns in a tserie
Please, I need this information, it's important for my work Thank you. lvdtime wrote: Hello everybody, I'm a beginner in R, and I'm currently working on Tseries (analysis of a portfolio) I imported the data like this (library tseries) : X-read.ts(X.dat, start=c(1995,1), frequency=261, header=T, sep=;) There is a header which contains the names of each column (codes of shares) I'd like to know if it is possible to get the names of the columns (to display it in the plots : ylab=name of the col) To summarize, I wonder if a code like label(X[,i]) exists... Thank you for your help LVDTime -- View this message in context: http://www.nabble.com/Get-the-names-of-the-columns-in-a-tserie-tf2511355.html#a7022436 Sent from the R help mailing list archive at Nabble.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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] A faster way to calculate Trace?
G'day Yongwan, YC == YONGWAN CHUN [EMAIL PROTECTED] writes: YC I want to know how to get trace of product of matrices YC **faster** when the matrices are really big. Unfortunately the YC matrices are not symmetric. If anybody know how to get the YC trace of it, please help me. An example is as below. The first one is quite simple to speed up: n - 2500 a - matrix(rnorm(n*n),n,n) b - matrix(rnorm(n*n),n,n) sum(diag(a %*% b)) [1] 1890.638 tb - t(b) sum(a*tb) [1] 1890.638 For the second one, you may try: sum(diag(a %*% b %*% a %*% b)) [1] 10668786 cmat - a %*% b sum(cmat*t(cmat)) [1] 10668786 It gives somewhat a speedup, since you only have to multiply two huge matrices once instead of thrice, but I wonder whether further improvements are possible. Hope this helps. Cheers, Berwin == Full address Berwin A Turlach Tel.: +61 (8) 6488 3338 (secr) School of Mathematics and Statistics+61 (8) 6488 3383 (self) The University of Western Australia FAX : +61 (8) 6488 1028 35 Stirling Highway Crawley WA 6009e-mail: [EMAIL PROTECTED] Australiahttp://www.maths.uwa.edu.au/~berwin __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Tukey-Kramer test
RSiteSearch(Tukey-Kramer) produced 7 hits for me just now. Have you looked at these? If yes, please provide a commented, minimal, self-contained, reproducible example of something you've tried, explaining why it did not meet your needs, as suggested in the posting guide www.R-project.org/posting-guide.html. Hope this helps. Spencer Graves A.R. Criswell wrote: Hello All, I found the TukeyHSD() function. Is there a Tukey-Kramer test for unbalanced data? Andrew __ 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 and provide commented, minimal, self-contained, reproducible code. __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] barcharts with 2 different axes
Dear UseRs, I'm having trouble drawing a barchart with 2 quantities in different units as follows with one unit on the top axis and the other unit on the bottom. E.g., x Tonnes | . . . Row 1 Tonnes1 | xx Row 1 Litres1 | yyy Row 2 Tonnes1 | x Row 2 Litres1 | y Litres|. . . Can anybody provide an example please? Cheers, Geoff Russell [[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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Adding shading to background of Time series plot
There is an example here using plot http://www.mayin.org/ajayshah/KB/R/html/g5.html and an example here using xyplot.zoo: library(zoo) ?xyplot.zoo that would also work with xyplot.ts On 10/26/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hello All, Thank you in advance. I have looked up and down in the archives to see if I could find some help on moving the polygons to the background of a ts.plot. I've tried panel.first in the gpars(...) arguments and trellis.focus, but I get errors. Am I missing something easy here? Here is my script: ts.plot(tsdjia, tstenyield, gpars = list(xlab = , ylab = , axes=FALSE, col=c(12,14))) mtext(Time, side=1, line=3, cex = 0.75, font = 1) mtext(Yield, side=4, line=1, cex = 0.75, font = 1) mtext(Dow Jones Level, side=2, line=2, cex = 0.7, font = 1) polygon(cord.x2,cord.y1,col = gray85) polygon(cord.x3,cord.y1,col = gray85) polygon(cord.x4,cord.y1,col = gray85) polygon(cord.x5,cord.y1,col = gray85) polygon(cord.x6,cord.y1,col = gray85) __ 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 and provide commented, minimal, self-contained, reproducible code. __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] VGAM package released on CRAN
Dear useRs, upon request, the VGAM package (currently version 0.7-1) has been officially released on CRAN (the package has been at my website http://www.stat.auckland.ac.nz/~yee/VGAM for a number of years now). VGAM implements a general framework for several classes of regression models using iteratively reweighted least squares (IRLS). The key ideas are Fisher scoring, generalized linear and additive models, IRLS and vector smoothing. It is a large R package that fits many models and distributions, usually by maximum likelihood estimation. See below for a partial listing, or better, http://www.stat.auckland.ac.nz/~yee/VGAM/doc/VGAMrefcard.pdf. Some broad categories are categorical data analysis, LMS quantile regression, extreme value models, univariate and continuous distributions. The package is under continual development and definitely not complete yet. Until then it should probably be considered 'alpha software'. Nothing is cast in iron yet, so please expect lots of changes if you use it. I hope to add more functionality to certain parts of the package, especially relating to inference and model selection, soon. Re. support, this is minimal. I first have to apologize that it won't be possible for me to answer every e-mail I receive. Sorry about this. If you use VGAM please consult the online help plus the incomplete documentation found at my website. Additionally, other technical details can be found in the journal articles. On the positive side, a monographs is in the making, however it is expected to be finished in quite a while :) Suggestions, bug reports and other comments are very welcome. Best regards, Thomas Yee Thomas W. Yee, Telephone: 64-9-3737599 extn 86857 Department of Statistics, Fax: 64-9-3737000 or 3677149 University of Auckland,E-mail:[EMAIL PROTECTED] Private Bag 92019, Auckland 1001, New Zealand. Information on package 'VGAM' Description: Package: VGAM Version: 0.7-1 Date: 2006-10-24 Title: Vector Generalized Linear and Additive Models Author:Thomas W. Yee [EMAIL PROTECTED] Maintainer:Thomas Yee [EMAIL PROTECTED] Depends: R (= 2.4.0), splines, methods, stats, stats4 Description: Vector generalized linear and additive models, and associated models (Reduced-Rank VGLMs, Quadratic RR-VGLMs, Reduced-Rank VGAMs). This package fits many models and distribution by maximum likelihood estimation (MLE) or penalized MLE. Also fits constrained ordination models in ecology. URL: http://www.stat.auckland.ac.nz/~yee/VGAM Index: AA.Aa.aaThe AA-Aa-aa Blood Group System AB.Ab.aB.ab The AB-Ab-aB-ab Blood Group System AB.Ab.aB.ab2The AB-Ab-aB-ab2 Blood Group System ABO The ABO Blood Group System acatOrdinal Regression with Adjacent Categories Probabilities benini Benini Distribution Family Function betaII Beta Distribution of the Second Kind betabin.ab Beta-binomial Distribution Family Function betabinomialBeta-binomial Distribution Family Function betaff The 2-parameter Beta Distribution Family Function betageometric Beta-geometric Distribution Family Function betaprime The Beta-Prime Distribution bilogistic4 Bivariate Logistic Distribution Family Function binom2.or Bivariate Logistic Regression binom2.rho Bivariate Probit Model binomialff Binomial Family Function bisaBirnbaum-Saunders Distribution Family Function bratBradley Terry Model bratt Bradley Terry Model With Ties calibrate.qrrvglm Calibration for CQO, UQO and CAO models cao Fitting Constrained Additive Ordination (CAO) cauchy1 Cauchy Distribution Family Function cdf.lmscreg Cumulative Distribution Function for LMS Quantile Regression cexpon Censored Exponential Distribution cgumbel Censored Gumbel Distribution chisq Chi-squared Distribution cnormal1Censored Normal Distribution cqo Fitting Constrained Quadratic Ordination (CQO) cratio Ordinal Regression with Continuation Ratios cumulative Ordinal Regression with Cumulative Probabilities dagum Dagum Distribution Family Function dcnormal1 Univariate Normal Distribution with Double Censoring deplot.lmscreg Density Plot for LMS Quantile Regression dgumbel The Gumbel Distribution dirichlet Fitting a Dirichlet Distribution dirmultinomial Fitting a Dirichlet-Multinomial Distribution erlang
Re: [R] avoiding a loop
On Wednesday 25 October 2006 07:36, Leeds, Mark (IED) wrote: I think I asked a similar question 3 years ago to the Splus list and I think the answer was no or noone answered so noone should spend more than 5 minutes on this because it could definitely be a waste of time. My question is whether the function below can be rewritten without a for loop. apply is fine if it can be done that way but i doubt it. I call it a lot and would prefer to not loop. #--- -- constructLt-function(invector) { outvector-invector for ( i in 2:length(invector) ) { if ( invector[i] 1 ) { outvector[i]-invector[i]*outvector[i-1] } } return(outvector) } Depending on the nature of your data, there is a faster way. It still involves looping, but not over the entire vector. Try the following: constructLt - function(invector) { outvector - invector cs - cumsum(rle(invector 1)$lengths) if (invector[1] 1) cs - c(1, cs) for (i in 0:(length(cs)%/%2 - 1)){ starti - cs[2*i + 1] stopi - cs[starti + 1] outvector[starti:stopi] - cumprod(invector[starti:stopi]) } return(outvector) } It is in the order of 3 times as fast for random vectors of considerable length ( 1000). For random vectors of length 50 it is about the same speed as the full looping algorithm. However if the data is such that there are longer runs (than N(1, 1)), then you might expect a better speedup. HTH Ray Brownrigg __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] Dum: problem installing (Don't install at all)
I'm on mandriva 2006 I did: urpmi R-2.0.0-1mdk.i586.rpm got the message: Some asked package can't be intalled: R-2.0.0-1mdk.i586 (due to unsatified) Continue ? (Y/N) Then after I try typping R on the shell and it does work. Of course there is no R reposatory Thank Daniel ## Daniel Sarrazin B.Sc Physics [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 and provide commented, minimal, self-contained, reproducible code.
[R] How to call Fortran routin in R
Hi, all, Can anyone give me steps how to call Fortan routine from Visual Fortran in R? Many thanks Gao [[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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Header of dataframe
Benjamin Dickgiesser dickgiesser at gmail.com writes: ... Is there an easy way to add a column name to the first column? What about summary.aggregate - function(y, ...) { temp.mean - aggregate(y, FUN=mean, ...) temp.sd - aggregate(y, FUN=sd, ...) temp.length - aggregate(y, FUN=length, ...) temp - data.frame(cbind(col=names(y), mean=temp.mean$x, stdev=temp.sd$x,n=temp.length$x)) } or summary.aggregate - function(y, ...) { temp.mean - aggregate(y, FUN=mean, ...) temp.sd - aggregate(y, FUN=sd, ...) temp.length - aggregate(y, FUN=length, ...) temp - data.frame(cbind(mean=temp.mean$x, stdev=temp.sd$x,n=temp.length$x)) rownames(temp) - names(y) } Gregor __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] barcharts with 2 different axes
On 10/26/06, Geoff Russell [EMAIL PROTECTED] wrote: Dear UseRs, I'm having trouble drawing a barchart with 2 quantities in different units as follows with one unit on the top axis and the other unit on the bottom. E.g., x Tonnes | . . . Row 1 Tonnes1 | xx Row 1 Litres1 | yyy Row 2 Tonnes1 | x Row 2 Litres1 | y Litres|. So if I read this right, the relative heights of the xxx bars and the yyy bars, which you have placed side by side, are in different units and thus their comparison is meaningless. It's doable, but do you really want this sort of graph? A better and much easier to implement design seems to be something like +-+-+ Row 1 | xx | yyy | Row 2 | x | | +-+-+ Tonnes1 Litres1 Can anybody provide an example please? Please provide some example data (the form of which will matter). -Deepayan __ 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 and provide commented, minimal, self-contained, reproducible code.