Re: [R] Using sunflowerplot to add points in a xyplot panel
Ronaldo Reis Junior said the following on 8/14/2007 7:08 AM: Hi, I use panel.points to add points to a xyplot graphic. But I like to use the sunflowerplot to plot my points because this is very superimposed. It is possible to use this? I try but it dont work directly. It may be need to put this function inside a panel.??? Thanks Ronaldo You'll need to write your own panel function. Here's one shot at it. Most of the code is from ?sunflowerplot with added touches for lattice capability. HTH, --sundar panel.sunflowerplot - function(x, y, number, log = , digits = 6, rotate = FALSE, cex.fact = 1.5, size = 1/8, seg.col = 2, seg.lwd = 1.5, ...) { n - length(x) if(missing(number)) { x - signif(x, digits = digits) y - signif(y, digits = digits) orderxy - order(x, y) x - x[orderxy] y - y[orderxy] first - c(TRUE, (x[-1] != x[-n]) | (y[-1] != y[-n])) x - x[first] y - y[first] number - diff(c((1:n)[first], n + 1)) } else { if(length(number) != n) stop('number' must have same length as 'x' and 'y') np - number 0 x - x[np] y - y[np] number - number[np] } n - length(x) n.is1 - number == 1 cex - trellis.par.get(plot.symbol)$cex if(any(n.is1)) lpoints(x[n.is1], y[n.is1], cex = cex, ...) if(any(!n.is1)) { lpoints(x[!n.is1], y[!n.is1], cex = cex/cex.fact, ...) i.multi - (1:n)[number 1] ppin - par(pin) pusr - unlist(current.panel.limits()) xr - size * abs(pusr[2] - pusr[1])/ppin[1] yr - size * abs(pusr[4] - pusr[3])/ppin[2] i.rep - rep.int(i.multi, number[number 1]) z - numeric() for (i in i.multi) z - c(z, 1:number[i] + if (rotate) stats::runif(1) else 0) deg - (2 * pi * z)/number[i.rep] lsegments(x[i.rep], y[i.rep], x[i.rep] + xr * sin(deg), y[i.rep] + yr * cos(deg), col = seg.col, lwd = seg.lwd) } } library(lattice) xyplot(Petal.Width ~ Petal.Length, iris, panel = panel.sunflowerplot) __ 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] weights in lmer
Try weights = as.numeric(total) BTW, there is a SIG (Special Interest Group) for lmer. https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models HTH, --sundar Chris O'Brien said the following on 8/14/2007 11:00 AM: Dear R users, Prof. Ripley just corrected my understanding of the use of weights in glm, which I thought would allow me to correctly use lmer. However I'm still having problems. My data takes the form of # of infected and uninfected individuals that were measured over time under different treatments. I'm using lmer to adjust for the repeated measures over time. In fitting the model: model1=lmer(y~treatment+(time | ID),family=binomial,weights = total) where y = proportion of animals infected (number infected/total) total = number of infected + number uninfected this returns the error: Error in lmer(y ~ treatment + (time | ID), family = binomial, weights = total) : object `weights' of incorrect type Can anyone tell me what's wrong with the weights? cheers, Chris Chris O'Brien Sonoran Desert Research Station and School of Natural Resources Biological Sciences, room 125 University of Arizona Tucson, AZ 85721 work (520) 623-3720 [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-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] setup trellis.device to color=F inside the xyplot function
Ronaldo Reis Junior said the following on 8/5/2007 6:18 AM: Hi, it is possible to setup trellis.device(color=F) inside teh function xyplot? I try to use xyplot(ocup~tempo| nitro+estacao,col=white,ylim=c(0,0.7),par.settings=list(color=F)) But dont work, the only way that work for me is call the function trellis.device(color=F) before the xyplot, but in this way it open a new device for each run. I like that is use the same device every time, but without colors. Thanks Ronaldo Try this: library(lattice) x - 1:10 y - 1:10 g - rep(1:2, 5) # no color xyplot(y ~ x | g, par.settings = standard.theme(color = FALSE)) xyplot(y ~ x, groups = g, par.settings = standard.theme(color = FALSE)) # with color xyplot(y ~ x | g) xyplot(y ~ x, groups = g) HTH, --sundar __ 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] Tabs in PDF documents
Dennis Fisher said the following on 7/30/2007 6:25 AM: Colleagues, I am using R 2.5.1 on an Intel Mac (OS 10) to create PDF outputs using pdf(); same problem exists in Linux (RedHat 9) While adding text to the document with text() and mtext(), I encounter the following problem: In order to align the text, I have embedded tabs (\t) in some of the text. Each time I do so, I get the following error messages: Warning: font metrics unknown for character 0x9 Warning: font width unknown for character 0x9 and the tabs are ignored. I have tied par() with and without family=mono. Is there a work-around available for this? Dennis COMMANDS: pdf(junk.pdf) par(family=mono) plot(1,1) text(1,1, \txx) mtext(\txx) dev.off() __ 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. Hi, Dennis, See this thread: http://finzi.psych.upenn.edu/R/Rhelp02a/archive/96028.html HTH, --sundar __ 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] reversing the x-axis terms on a boxplot
Dylan Beaudette said the following on 7/25/2007 11:18 AM: Hi, I am able to reverse the order of plotting on regular plots (i.e. with the plot() function) by manually setting the xlim variable. Is there some trick like this which will work for a boxplot? * for example: l - sample(letters, 500, replace=TRUE) n - runif(500) boxplot(n ~ l) this will produce a plot with the x-axis ranging from a-z ... i know that these are labels, associated with an integer index-- but is there someway to reverse the plotting order? Thanks in advance, Dylan __ 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. Try this: set.seed(1) l - sample(letters, 500, replace=TRUE) n - runif(500) l - factor(l, levels = rev(letters)) boxplot(n ~ l) This is explained in the details section of ?boxplot. If multiple groups are supplied either as multiple arguments or via a formula, parallel boxplots will be plotted, in the order of the arguments or the order of the levels of the factor (see 'factor'). This means you can create any order you want by setting the factor levels explicitly. HTH, --sundar __ 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] Lattice: vertical barchart
Michael Hoffman said the following on 7/10/2007 7:06 AM: barchart(Titanic, stack=F) produces a very nice horizontal barchart. Each panel has four groups of two bars. barchart(Titanic, stack=F, horizontal=F) doesn't produce the results I would have expected, as it produces this warning message: Warning message: y should be numeric in: bwplot.formula(x = as.formula(form), data = list(Class = c(1, And it results in each panel having 22 groups of 0-2 bars. How can I produce something just like the original except with the orientation changed? Thanks in advance. Hi, Michael, It seems that barchart.table doesn't allow the horizontal = FALSE argument. With a slight modification to barchart.table this can be accomplished. Also, I don't get a warning with your original code using R-2.5.1 and lattice 0.16-1. HTH, --sundar barchart.table - function (x, data = NULL, groups = TRUE, origin = 0, stack = TRUE, horizontal = TRUE, ...) ## add horizontal argument { formula - x ocall - sys.call(sys.parent()) if (!is.null(data)) warning(explicit 'data' specification ignored) data - as.data.frame(formula) nms - names(data) freq - which(nms == Freq) nms - nms[-freq] ## SD: change formula if horizontal == FALSE form - if(horizontal) { paste(nms[1], Freq, sep = ~) } else { paste(Freq, nms[1], sep = ~) } ## SD: end change nms - nms[-1] len - length(nms) if (is.logical(groups) groups len 0) { groups - as.name(nms[len]) nms - nms[-len] len - length(nms) } else groups - NULL if (len 0) { rest - paste(nms, collapse = +) form - paste(form, rest, sep = |) } ans - barchart(as.formula(form), data, groups = eval(groups), origin = origin, stack = stack, ...) ans$call - ocall ans } barchart(Titanic, stack = FALSE) barchart(Titanic, stack = FALSE, horizontal = FALSE) __ 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 plot two variables using a secondary Y axis
Felipe Carrillo said the following on 7/10/2007 7:58 AM: Date Fo Co6/27/2007 57.1 13.96/28/2007 57.7 14.3 6/29/2007 57.8 14.36/30/2007 57 13.97/1/2007 57.1 13.9 7/2/2007 57.2 14.07/3/2007 57.3 14.17/4/2007 57.6 14.2 7/5/2007 58 14.47/6/2007 58.1 14.57/7/2007 58.2 14.6 7/8/2007 58.4 14.77/9/200758.7 14.8 Hello all: I am a newbie to R, and I was wondering how can I plot the Temperature values above using Lattice or ggplot2 code. I want Date(X axis), Degrees F(Y axis) and Degrees C( on a secondary Y axis). Thanks For lattice, see this thread: http://finzi.psych.upenn.edu/R/Rhelp02a/archive/102768.html HTH, --sundar __ 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] from character string to function body?
Atte Tenkanen said the following on 7/7/2007 8:41 AM: Dear R users, I wonder if it is possible to form a function from a character string. Here is an example: x=3 `-`(`+`(`^`(x,3),`^`(x,2)),1) # Here is my function evaluated. [1] 35 V=list(`-`,(,`+`,(,`^`,(,x,,,3,),,,`^`,(,x,,,2,),),,,1,)) # Here I construct the string, it could be vector as well? S=noquote(paste(V,collapse=)) S [1] `-`(`+`(`^`(x,3),`^`(x,2)),1) # Here is the same as a character string. Now I'd like to create a function using this string, something like this, but of course, this doesn't work: S=as.expression(S) F1-function(x){S} Is there some way to do this? Cheers, Atte Tenkanen University of Turku, Finland __ 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. How about: V - list(`-`,(,`+`,(,`^`,(,x,,,3,),,,`^`,(,x,,,2,),),,,1,)) # Here I construct the string, it could be vector as well? S - paste(V, collapse = ) F1 - function(x) {} body(F1) - parse(text = S) F1(3) # [1] 35 F1(2) # [1] 11 HTH, --sundar __ 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] abline plots at wrong abscissae after boxplot
Brian Wilfley said the following on 6/21/2007 2:44 PM: Hi folks, I'm using R 2.5.0 under ESS under Windows XP. (This also happens using the Rgui application.) I'm trying to add lines to a plot originally made with boxplot, but the lines appear in the wrong place. Below is a script that illustrates the problem # boxablinetest.R - script to show problem with abline on box plot x - c( 2, 2, 2, 3, 3, 3, 4, 4, 4) y - c( 1, 2, 3, 2, 3, 4, 3, 4, 5) xymodel - lm( y~x) boxplot( y~x) abline( xymodel)# Wrong abcissae abline( v = 2.5)# Wrong abcissa abline( h = 2.75) # Right ordinate # -- end -- Here, I'm making a box plot with abscissae that start at 2. The box plot looks fine: the numbers 2, 3, and 4 appear on the x-axis and the boxes are centered at 2, 3, and 4. When I add the first abline, the line appears too low, but actually it is too far to the right. The abscissae are being interpreted without realizing that the plot originates at 2, not 1. The second call to abline should put a vertical line between 2 and 3, but instead it shows up between 3 and 4. Again, it appears that the offset in the origin of the boxplot is not accounted for. Finally the last abline appears where it should: between 2 and 3. Evidently, ordinate values are correctly interpreted. Does anyone have any advice? Thanks very much. Brian Wilfley __ 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. That's because the x is converted to a factor (see ?boxplot). Here's what you want: ## changesd x==3 to 6 to demonstrate call to boxplot below x - c(2, 2, 2, 3, 3, 3, 6, 6, 6) y - c(1, 2, 3, 2, 3, 4, 3, 4, 5) xymodel - lm(y ~ x) boxplot(y ~ x) ## note x-labels! ## now fix your problem plot(y ~ x, type = n, xlim = c(1, 7)) bxp(boxplot(y ~ x, plot = FALSE), at = c(2, 3, 6), add = TRUE, boxwex = 0.5, boxfill = lightblue) abline(xymodel) abline(v = 2.5) abline(h = 2.75) HTH, --sundar __ 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] ievent.wait
Hi, Greg, type = 'b' won't work according to ?locator. Try type = 'o'. HTH,x --sundar Greg Snow said the following on 6/13/2007 7:27 AM: Does locator(type='l') (or type ='b') Work for you? -Original Message- From: ryestone [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch r-help@stat.math.ethz.ch Sent: 6/8/07 10:19 AM Subject: [R] ievent.wait I am working on a plot and would be like to click on a few points and then have a line connect them. Could anyone help me with this or advise me in a direction that would suit this. I know I would be using ievent.wait in iplot but not sure about this. thank you. __ 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] logical 'or' on list of vectors
Tim Bergsma said the following on 6/8/2007 5:57 AM: Suppose I have a list of logicals, such as returned by lapply: Theoph$Dose[1] - NA Theoph$Time[2] - NA Theoph$conc[3] - NA lapply(Theoph,is.na) Is there a direct way to execute logical or across all vectors? The following gives the desired result, but seems unnecessarily complex. as.logical(apply(do.call(rbind,lapply(Theoph,is.na)),2,sum)) Regards, Tim __ 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. How about: apply(sapply(Theoph, is.na), 1, any) HTH, --sundar __ 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] Opening Rgui by double-clicking R script
Hi, all, This is for R-2.5.0 on WinXP and in particular RGui. I'm trying to teach some colleagues of mine R and rather than impose Xemacs/ESS upon them I decided to simply start by showing them RGui. When R is installed, R workspaces (.RData) are automatically registered so that I can double-click on them in Explorer RGui opens with the correct working directory. However, I cannot figure a way to do the same for R scripts. In other words, I want to double-click on a .R file in Explorer, have RGui open, set the working directory to the location of where the script is saved, and load the script into the script editor. Is this possible? Thanks, --sundar __ 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] determining a parent function name
Hi, Vladimir, In general, this won't work since traceback only contains the stack from the last uncaught error (see ?traceback). When traceback is called below it would be from the previous error, not the current one. error - function() { parent - tail(capture.output(traceback()), n = 1) parent - sub(^.*:[ ]+, , parent) stop(parent) } foo - function() error() bar - function() error() foo() Error in error() : No traceback available bar() Error in error() : foo() Thanks, --sundar Vladimir Eremeev said the following on 5/31/2007 4:57 AM: Does tail(capture.output(traceback()),n=1) do what you want? that is error - function(...) { msg - paste(..., sep = ) if(!length(msg)) msg - if(require(tcltk, quiet = TRUE)) { tt - tktoplevel() tkwm.title(tt, Error) tkmsg - tktext(tt, bg = white) parent-tail(capture.output(traceback()),n=1) parent-gsub([0-9]: ,,parent) # deleting 1: from the captured string tkinsert(tkmsg, end, sprintf(Error in %s: %s, parent , msg)) tkconfigure(tkmsg, state = disabled, font = Tahoma 12, width = 50, height = 3) tkpack(tkmsg, side = bottom, fill = y) } stop(msg) } Sundar Dorai-Raj wrote: Hi, All, I'm writing a wrapper for stop that produces a popup window using tcltk. Something like: error - function(...) { msg - paste(..., sep = ) if(!length(msg)) msg - if(require(tcltk, quiet = TRUE)) { tt - tktoplevel() tkwm.title(tt, Error) tkmsg - tktext(tt, bg = white) tkinsert(tkmsg, end, sprintf(Error in %s: %s, ???, msg)) tkconfigure(tkmsg, state = disabled, font = Tahoma 12, width = 50, height = 3) tkpack(tkmsg, side = bottom, fill = y) } stop(msg) } But, I would like to know from which function error() is called. For example, if I have foo - function() stop() bar - function() error() foo() Error in foo() : bar() Error in error() : and in the tk window I get Error in ???: I need the output of bar (in the tk window only) to be Error in bar(): then it's clear where error is called. I'm not worried about the output bar() produces on the console. Hope this makes sense. Thanks, __ 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] determining a parent function name
Hi, Vladimir, Sorry, didn't see this reply. .Traceback - NULL doesn't work because of the warning in ?traceback. Warning: It is undocumented where '.Traceback' is stored nor that it is visible, and this is subject to change. Prior to R 2.4.0 it was stored in the workspace, but no longer. Thanks, --sundar Vladimir Eremeev said the following on 5/31/2007 5:10 AM: Vladimir Eremeev wrote: Does tail(capture.output(traceback()),n=1) do what you want? that is Hmmm... Seems, no... Having the earlier error() definition and bar-function() error(asdasdf) ft-function() bar() ft() I get in the tcl/tk window: Error in bar(): asdasdf bar() I get in the tcl/tk window: Error in ft(): asdasdf I get in the tcl/tk window: Error in bar(): asdasdf Some kind of the stack flushing is needed. .Traceback-NULL did not help __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Different fonts on different axes
Martin Henry H. Stevens said the following on 5/31/2007 9:59 AM: Hi Folks, How do I get red bold font on my y axis and black standard font on my x axis? plot(runif(10), ylab=Red, Bold?, xlab=Black, standard?) Any pointers or examples would be great. Thanks! Hank Dr. Hank Stevens, Assistant Professor 338 Pearson Hall Botany Department Miami University Oxford, OH 45056 Office: (513) 529-4206 Lab: (513) 529-4262 FAX: (513) 529-4243 http://www.cas.muohio.edu/~stevenmh/ http://www.muohio.edu/ecology/ http://www.muohio.edu/botany/ E Pluribus Unum __ 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. Try: plot(runif(10), xlab = , ylab = ) title(xlab = Index) title(ylab = y, font.lab = 2, col.lab = red) HTH, --sundar __ 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] determining a parent function name
Thanks for the input. I don't think this will help either since it still requires you know the error occurred in foo. I settled on passing the call to error: error - function(..., call) {} foo - function() error(some error, call = match.call()) Thanks, --sundar Martin Morgan said the following on 5/31/2007 7:51 AM: Hi sundar -- maybe myerr - function(err) err$call foo - function() stop() tryCatch({ foo() }, error=myerr) foo() suggests a way to catch errors without having to change existing code or re-invent stop? Martin Sundar Dorai-Raj [EMAIL PROTECTED] writes: Hi, Vladimir, Sorry, didn't see this reply. .Traceback - NULL doesn't work because of the warning in ?traceback. Warning: It is undocumented where '.Traceback' is stored nor that it is visible, and this is subject to change. Prior to R 2.4.0 it was stored in the workspace, but no longer. Thanks, --sundar Vladimir Eremeev said the following on 5/31/2007 5:10 AM: Vladimir Eremeev wrote: Does tail(capture.output(traceback()),n=1) do what you want? that is Hmmm... Seems, no... Having the earlier error() definition and bar-function() error(asdasdf) ft-function() bar() ft() I get in the tcl/tk window: Error in bar(): asdasdf bar() I get in the tcl/tk window: Error in ft(): asdasdf I get in the tcl/tk window: Error in bar(): asdasdf Some kind of the stack flushing is needed. .Traceback-NULL did not help __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 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] determining a parent function name
Thanks! That's the answer I was looking for. --sundar Ismail Onur Filiz said the following on 5/31/2007 12:23 PM: Hi, On Wednesday 30 May 2007 14:53:28 Sundar Dorai-Raj wrote: error - function(...) { msg - paste(..., sep = ) if(!length(msg)) msg - if(require(tcltk, quiet = TRUE)) { tt - tktoplevel() tkwm.title(tt, Error) tkmsg - tktext(tt, bg = white) tkinsert(tkmsg, end, sprintf(Error in %s: %s, ???, msg)) tkconfigure(tkmsg, state = disabled, font = Tahoma 12, width = 50, height = 3) tkpack(tkmsg, side = bottom, fill = y) } stop(msg) } as.character(sys.call(-1)[[1]]) works for me. Best... __ 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] determining a parent function name
Ismail Onur Filiz said the following on 5/31/2007 1:03 PM: Sorry for replying to myself, but: On Thursday 31 May 2007 12:23:12 Ismail Onur Filiz wrote: Hi, On Wednesday 30 May 2007 14:53:28 Sundar Dorai-Raj wrote: error - function(...) { msg - paste(..., sep = ) if(!length(msg)) msg - if(require(tcltk, quiet = TRUE)) { tt - tktoplevel() tkwm.title(tt, Error) tkmsg - tktext(tt, bg = white) tkinsert(tkmsg, end, sprintf(Error in %s: %s, ???, msg)) tkconfigure(tkmsg, state = disabled, font = Tahoma 12, width = 50, height = 3) tkpack(tkmsg, side = bottom, fill = y) } stop(msg) } as.character(sys.call(-1)[[1]]) works for me. you can furthermore do: options(error=error) and remove the stop(msg) call in the last line of the function. Then your function will become the error handler. Best... Thanks, with the minor change to sys.call(-2) that does exactly what I want. thanks, --sundar __ 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] separate y-limits in xYplot panels
Nitin Jain said the following on 5/30/2007 8:12 AM: Hello, I would like to get the scales of y-axes dependent only on the data points in a particular panel. Have attached a test example below. When using 'relation=free', it does not make the scales 'free', however when using 'relation=sliced', I get a warning Explicitly specified limits ignored in: limitsFromLimitlist(have.lim = have.ylim, lim = ylim, relation = y.relation, (although in this particular case, I get the desired result, but in my real data, I do not get the free y-scale for each panel). Can you please let me know what should be correct syntax? Thanks. -Nitin library(Hmisc) test1 - data.frame( y = c(rnorm(33), rnorm(33, mean=10), rnorm(34, mean=100)), x = 1:100, f = factor(c(rep(a, 33), rep(b, 33), rep(c, 34))), g = factor(sample(LETTERS[1:2], size=100, replace=TRUE)) ) CI - rnorm(100) lb - test1$y - CI ub - test1$y + CI xYplot(Cbind(y, lb,ub )~x|f, groups=g, scales = list(relation=free), ## Changing it to sliced gives warning data=test1) You want scales = list(y = list(relation = free)) HTH, --sundar __ 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] determining a parent function name
Hi, All, I'm writing a wrapper for stop that produces a popup window using tcltk. Something like: error - function(...) { msg - paste(..., sep = ) if(!length(msg)) msg - if(require(tcltk, quiet = TRUE)) { tt - tktoplevel() tkwm.title(tt, Error) tkmsg - tktext(tt, bg = white) tkinsert(tkmsg, end, sprintf(Error in %s: %s, ???, msg)) tkconfigure(tkmsg, state = disabled, font = Tahoma 12, width = 50, height = 3) tkpack(tkmsg, side = bottom, fill = y) } stop(msg) } But, I would like to know from which function error() is called. For example, if I have foo - function() stop() bar - function() error() foo() Error in foo() : bar() Error in error() : and in the tk window I get Error in ???: I need the output of bar (in the tk window only) to be Error in bar(): then it's clear where error is called. I'm not worried about the output bar() produces on the console. Hope this makes sense. Thanks, --sundar __ 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] trouble understanding why ...==NaN isn't true
Hi, Andrew, Looks like you're reading the data incorrectly. If using ?read.table or the like, try to add a na.strings = c(NA, NaN) argument. Second, Bert's comment: use ?is.nan, rather than ==. --sundar Andrew Yee said the following on 5/29/2007 3:39 PM: Okay, it turns out that there were leading spaces, so that in the data, it was represented asNaN, hence the expression ==NaN was coming back as false. Is there a way to find out preemptively if there are leading spaces? Thanks, Andrew On 5/29/07, Andrew Yee [EMAIL PROTECTED] wrote: I have the following data: dataset[2,Sample.227] [1]NaN 1558 Levels: -0.000 -0.001 -0.002 -0.003 -0.004 -0.005 -0.006 -0.007 - 0.008 -0.009 ... 2.000 However, I'm not sure why this expression is coming back as FALSE: dataset[2,Sample.227]==NaN [1] FALSE Similarly: dataset[2,Sample.227]==NaN [1] NA It seems that since NaN is represented as a character, this expression ==NaN should be TRUE, but it's returning as FALSE. Thanks, Andrew [[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] learning lattice graphics
I would also suggest Paul Murrell's book R Graphics. http://www.amazon.com/Graphics-Computer-Science-Data-Analysis/dp/158488486X/ --sundar Tyler Smith said the following on 5/27/2007 1:27 PM: On 2007-05-27, Adrian Dragulescu [EMAIL PROTECTED] wrote: Check the documentation link from http://cm.bell-labs.com/cm/ms/departments/sia/project/trellis/software.writing.html Thanks Adrian, that looks great! Tyler __ 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] Reducing the size of pdf graphics files produced with R
You need not buy Acrobat. There are two free software programs that will compress pdf files: http://www.cutepdf.com http://www.cs.wisc.edu/~ghost/ (and in particular GSView) They both allow several levels of compression. Thanks, --sundar Chabot Denis said the following on 5/22/2007 3:32 AM: Hi, Without trying to print 100 points (see http:// finzi.psych.upenn.edu/R/Rhelp02a/archive/42105.html), I often print maps for which I do not want to loose too much of coastline detail, and/or plots with 1000-5000 points (yes, some are on top of each other, but using transparency (i.e. rgb colors with alpha information) this actually comes through as useful information. But the files are large (not as large as in the thread above of course, 800 KB to about 2 MB), especially when included in a LaTeX document by the dozen. Acrobat (not the reader, the full program) has an option reduce file size. I don't know what it does, but it shrinks most of my plots to about 30% or original size, and I cannot detect any loss of detail even when zooming several times. But it is a pain to do this with Acrobat when you generate many plots... And you need to buy Acrobat. Is this something the pdf device could do in a future version? I tried the million points example from the thread above and the 55 MB file was reduced to 6.9 MB, an even better shrinking I see on my usual plots. 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-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] Abline in dotplot
Thompson, Valeria V said the following on 5/16/2007 12:04 PM: Hello, I have trouble adding an abline to a dotplot() from lattice package. For example, I would like to draw a line at x=3: library(lattice) x-1:5 names(x) - c(a, b, c, d, e) dotplot(sample(x)) panel.abline(v=3) Produces a line on the left hand side of the origin. What would be a correct way to do this? Thank you, Valeria V. Thompson Applied Statistics Group Mathematics Computing Technology The Boeing Company (425) 373-2740 __ 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. Try this instead: library(lattice) x-1:5 names(x) - c(a, b, c, d, e) dotplot(sample(x), panel = function(...) { panel.dotplot(...) panel.abline(v=3) }) HTH, --sundar __ 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] what fun I need to put in this tapply
Weiwei Shi said the following on 5/14/2007 11:04 AM: Hi, I happened to need generate the following t1 V1 V2 count count2 1 1 11 2 3 2 1 12 2 2 3 2 11 1 3 4 3 13 3 1 5 3 11 3 3 6 3 12 3 2 from V1 V2 1 1 11 2 1 12 3 2 11 4 3 13 5 3 11 6 3 12 I am wondering what function of funx I need to put into tapply(t1[,2], t1[,2] funx) to get that? If I use length, I probabaly need to do merge by myself. Is there a better way? thanks. I think ?ave would be more useful here: x - V1 V2 1 1 11 2 1 12 3 2 11 4 3 13 5 3 11 6 3 12 y - read.table(textConnection(x)) y$count - ave(y[, 1], y[, 1], FUN = length) y$count2 - ave(y[, 2], y[, 2], FUN = length) HTH, --sundar __ 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] like apply(x,1,sum), but using multiplication?
Jose Quesada said the following on 5/7/2007 11:25 AM: Hi, I need to multiply all columns in a matrix so something like apply(x,2,sum), but using multiplication should do. I have tried apply(x,2,*) I know this must be trivial, but I get: Error in FUN(newX[, i], ...) : invalid unary operator The help for apply states that unary operators must be quoted. I tried single quotes too, with the same results. Thanks, -Jose Try: apply(x,2,prod) HTH, --sundar __ 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] Bad optimization solution
Paul Smith said the following on 5/7/2007 3:25 PM: On 5/7/07, Paul Smith [EMAIL PROTECTED] wrote: I think the problem is the starting point. I do not remember the details of the BFGS method, but I am almost sure the (.5, .5) starting point is suspect, since the abs function is not differentiable at 0. If you perturb the starting point even slightly you will have no problem. Paul Smith [EMAIL PROTECTED] To Sent by: R-help r-help@stat.math.ethz.ch [EMAIL PROTECTED] cc at.math.ethz.ch Subject [R] Bad optimization solution 05/07/2007 04:30 PM Dear All I am trying to perform the below optimization problem, but getting (0.5,0.5) as optimal solution, which is wrong; the correct solution should be (1,0) or (0,1). Am I doing something wrong? I am using R 2.5.0 on Fedora Core 6 (Linux). Thanks in advance, Paul -- myfunc - function(x) { x1 - x[1] x2 - x[2] abs(x1-x2) } optim(c(0.5,0.5),myfunc,lower=c(0,0),upper=c(1,1),method=L-BFGS-B,control=list(fnscale=-1)) Yes, with (0.2,0.9), a correct solution comes out. However, how can one be sure in general that the solution obtained by optim is correct? In ?optim says: Method 'L-BFGS-B' is that of Byrd _et. al._ (1995) which allows _box constraints_, that is each variable can be given a lower and/or upper bound. The initial value must satisfy the constraints. This uses a limited-memory modification of the BFGS quasi-Newton method. If non-trivial bounds are supplied, this method will be selected, with a warning. which only demands that the initial value must satisfy the constraints. Furthermore, X^2 is everywhere differentiable and notwithstanding the reported problem occurs with myfunc - function(x) { x1 - x[1] x2 - x[2] (x1-x2)^2 } optim(c(0.2,0.2),myfunc,lower=c(0,0),upper=c(1,1),method=L-BFGS-B,control=list(fnscale=-1)) Paul Then perhaps supply the gradient: mygrad - function(x) { x1 - x[1] x2 - x[2] c(2, -2) * c(x1, x2) } optim(c(0.2,0.2),myfunc,mygrad,lower=c(0,0),upper=c(1,1), method=L-BFGS-B,control=list(fnscale=-1)) HTH, --sundar __ 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] Alternatives to unlist()
Jacques Wagnor said the following on 5/4/2007 8:53 AM: Given the following, one of the things I am trying to see is what % of draws are below a certain number: lambda - 3 rate - 5 n - 5 set.seed(123) v - replicate(n, rexp(rpois(1,lambda), rate)) vv - unlist(v) cat(% of draws below 0.1:, round(length(subset(vv, vv 0.1))/length(vv)*100,0), %\n) In actuality, my lambda, rate, and n are 26, 10, 100, respectively; which in effect makes the length of vv roughly equal 26'000'000. When I run cat(...), I get the following: Error: cannot allocate vector of size 101540 Kb In addition: Warning messages: 1: Reached total allocation of 1015Mb: see help(memory.size) 2: Reached total allocation of 1015Mb: see help(memory.size) Rather than keep the code as is and resort to memory.limit(), I would like to see how the code can be modified (i.e., alternatives to unlist()) such that I could still see what % of draws are below a certain number. I'd appreciate any suggestions. Regards, platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major2 minor2.1 year 2005 month12 day 20 svn rev 36812 language R __ 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. This works for me on R-2.5.0 on Win XP with 1GB RAM. system.time({ set.seed(1) lambda - 26 rate - 10 n - 100 v - replicate(n, rexp(rpois(1, lambda), rate)) vbar - sapply(v, function(x) mean(x 0.1)) vlen - sapply(v, length) }) # user system elapsed # 75.671.13 96.85 (m - weighted.mean(vbar, vlen)) # [1] 0.6320496 cat(% of draws below 0.1: , round(m * 100), %\n, sep = ) Note your version R is almost a year and half old. Please upgrade. It's easy and free. --sundar __ 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] R package development in windows
Doran, Harold said the following on 5/3/2007 11:32 AM: I'm attempting to build an R package for distribution and am working from the directions found at http://www.maths.bris.ac.uk/~maman/computerstuff/Rhelp/Rpackages.html#Wi n-Win I've read through Writing R Extensions and various other helpful web sites. I've installed all relevant software (perl, cygwin, mingwin, hhc.exe). Here is what I have done so far: 1) Sourced data and functions into R 2) Used package.skeleton 3) Edited Description file 4) Edited my windows path to ensure the new programs (e.g., perl) are in the path 5) Then, I open DOS and do the following in the script below C:\Program Files\R\R-2.4.1\binRcmd build --force --binary g:\foo * checking for file 'g:\foo/DESCRIPTION' ... OK * preparing 'g:\foo': * checking DESCRIPTION meta-information ...'sh' is not recognized as an internal or external command, operable program or batch file. OK * removing junk files 'sh' is not recognized as an internal or external command, operable program or batch file. 'sh' is not recognized as an internal or external command, operable program or batch file. 'sh' is not recognized as an internal or external command, operable program or batch file. Error: cannot open file 'foo/DESCRIPTION' for reading I'ver read through about as much documentation as I can find, and I'm just not sure what I should do from here. I admit that I have reached a point of frustration and must apologize if the problem would be evident if I read documentation further, but I'm about tapped out after a few days of experimentation. Can anyone suggest how I could resolve this and what the next steps would be? Thanks: I'm using Windows XP and R 2.4.1 Harold Do you have Rtools installed and in your system path? You should read all the documentation on that page. http://www.murdoch-sutherland.com/Rtools/ HTH, --sundar __ 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] stringification magic in subset?
ivo welch said the following on 5/2/2007 8:13 AM: dear R wizards: I am trying to replace subset() with my own version that first checks that each name in the select statement has a corresponding name in the data set. preferably, it would have the same syntax and semantics as subset() otherwise. alas, subset works in interesting ways: subset(d, select=col1) works just like subset(d, select=col1) somehow, subset manages to stringify its argument in such cases. Is it possible to duplicate the subset method one-for-one? a minor question---where do I find the source definition such as that of subset(), which is defined in subset function (x, ...) UseMethod(subset) environment: namespace:base any help, as usual, appreciated. regards, /ivo __ 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. Try: methods(subset) which will point you to subset.data.frame. The latter code will answer your questions. HTH, --sundar __ 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] upgrade to 2.5
Iasonas Lamprianou said the following on 5/2/2007 8:25 AM: Hi I am using R version 2.4.1. How can I upgrade to version 2.5 without having to install all the packages again? Thanks Jason You may find the following link relevant. http://finzi.psych.upenn.edu/R/Rhelp02a/archive/75359.html HTH, --sundar __ 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] upgrade to 2.5
Robert A LaBudde said the following on 5/2/2007 2:39 PM: At 01:41 PM 5/2/2007, you wrote: On 5/2/07, Sundar Dorai-Raj [EMAIL PROTECTED] wrote: Iasonas Lamprianou said the following on 5/2/2007 8:25 AM: Hi I am using R version 2.4.1. How can I upgrade to version 2.5 without having to install all the packages again? Thanks Jason You may find the following link relevant. http://finzi.psych.upenn.edu/R/Rhelp02a/archive/75359.html if you use Windows XP. This link was useful to me, as I am new to R. (Win2000, R-2.5.0) What I have been doing is using a file compare utility (Beyond Compare in my case) to move files in the old library directory to the new one, if the files are missing in the new one. Then I perform an update.packages command. This procedure appears to work without problem. It would seem much preferable to have all packages saved in an installation-independent directory, instead of a library directory under R's installation directory. Then, of course, no update would be necessary. I can't find how this option is settable in R, other than a direct argument to library() or install.package(). How does one shift the R default libraries location to a particular directory? Set an environment variable R_LIBS. See the R Installation and Administration manual (Section 6). HTH, --sundar __ 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] Is R's fast fourier transform function different from fft2 in Matlab?
Li Li said the following on 5/2/2007 4:06 PM: Hi All, I found mvfft in R and fft2 in Matlab give different result and can't figure out why. My example is: In R: matrix(c(1,4,2,20), nrow=2) [,1] [,2] [1,]12 [2,]4 20 mvfft(matrix(c(1,4,2,20), nrow=2)) [,1] [,2] [1,] 5+0i 22+0i [2,] -3+0i -18+0i In Matlab: fft2([1,2;4,20]) ans= 27 -17 -21 15 Does any function in R generate teh same result as what from Matlab? Thanks, Li I don't know Matlab or any of its functions, but the following produces the same output. z - matrix(c(1, 4, 2, 20), nrow = 2) Re(fft(z)) And from ?fft: When 'z' contains an array, 'fft' computes and returns the multivariate (spatial) transform. HTH, --sundar __ 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] Is R's fast fourier transform function different from fft2 in Matlab?
Li Li said the following on 5/2/2007 7:53 PM: Thanks for both replies. Then I found the ifft2 from Matlab gives different result from fft( , inverse=T) from R. An example: in R: temp - matrix(c(1,4,2, 20), nrow=2) fft(temp) [,1] [,2] [1,] 27+0i -17+0i [2,] -21+0i 15+0i fft(temp,inverse=T) [,1] [,2] [1,] 27+0i -17+0i [2,] -21+0i 15+0i In Matlab: A = [1,2;4,20]; fft2(A) Ans = 27-17 -21 15 ifft2(A) Ans= 6.7500-4.2500 -5.2500 3.7500 I also tried mvfft with inverse but can't get same result with ifft2. Does any function work? This is easily explained if you read ?fft and the description of the 'inverse' argument in the Value section. Please do read the help pages as the posting guide suggests. Re(fft(temp, inverse = TRUE)/4) --sundar __ 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] xyplot() and controlling panel.polygon()
Michael Kubovy said the following on 4/26/2007 7:20 AM: Dear R-helpers, How do I tell panel.polygon what greoup and panel it applies to whithin xyplot(y ~ x | c, groups = g panel = function(x, y, groups, ...){ panel.polygon(x = xpol[c, g], y = ypol[c, g], default.units = 'native') panel.xYplot(x, y, groups, ...) llines(x = c(1, 6), y = c(-24.28, 35.941667), lwd = 2, lty = 3, col = 4) } x[c, g] and y[c, g] describe the polygon I want plotted for group g in panel c. _ Professor Michael Kubovy University of Virginia Department of Psychology USPS: P.O.Box 400400Charlottesville, VA 22904-4400 Parcels:Room 102Gilmer Hall McCormick RoadCharlottesville, VA 22903 Office:B011+1-434-982-4729 Lab:B019+1-434-982-4751 Fax:+1-434-982-4766 WWW:http://www.people.virginia.edu/~mk9y/ __ 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. I believe you can just do: panel = function(x, y, subscripts, groups, ...) { ## note addition of subscripts to arguments panel.superpose(xpol, ypol, subscripts, groups, panel.groups = panel.polygon, default.units = native, ...) panel.xYplot(x, y, subscripts, groups, ...) llines(x = c(1, 6), y = c(-24.28, 35.941667), lwd = 2, lty = 3, col = 4) } Also, it would be easier to provide tested answers if you gave a reproducible example. HTH, --sundar __ 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] xyplot source file only work with echo=TRUE
Read FAQ 7.22 http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f --sundar Ronaldo Reis Junior said the following on 4/24/2007 6:38 AM: Hi, I write several xyplot graphics on a source file. When I try to use source(graphics.R) the source don't work, but if I use source(graphics.R,echo=T) it work. Generally some commands work without echo=T, but xyplot dont work. Why it dont work without echo=T? It is possible to write a source that dont need echo=T on source command? Thanks Ronaldo __ 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] xyplot: Combining 'subscripts' and 'allow.multiple=T'
Søren Højsgaard said the following on 4/20/2007 3:57 AM: Dear all, Consider this plot xyplot(Sepal.Length + Sepal.Width ~ Petal.Length | Species, data = iris, allow.multiple=T, outer=F, panel = function(x,y,...) { panel.xyplot(x,y,...) } ) I want to *add* some things to each panel and what I want to add involves using the data for each panel, so I try to take this subset of data out with subscripts: xyplot(Sepal.Length + Sepal.Width ~ Petal.Length | Species, data = iris, allow.multiple=T, outer=F, panel = function(x,y,subscripts,...) { panel.xyplot(x,y,...) subiris - iris[subscripts,] # Something using this ... } ) and then I get Error in NextMethod([) : argument subscripts is missing, with no default Does anyone know how to obtain this?? By the way: The doc on xyplot says: The value of subscripts becomes slightly more complicated when allow.multiple is in effect. Details can be found in the source code of the function latticeParseFormula.. Sure. Best regards Søren [[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. Hi, Søren, Since you add subscripts to your panel arguments, you now need to explicitly pass it on to panel.xyplot. Try: xyplot(Sepal.Length + Sepal.Width ~ Petal.Length | Species, data = iris, allow.multiple=T, outer=F, panel = function(x,y,subscripts,...) { panel.xyplot(x,y,subscripts=subscripts,...) subiris - iris[subscripts,] # Something using this ... }) HTH, --sundar __ 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] xyplot: Combining 'subscripts' and 'allow.multiple=T'
Deepayan Sarkar said the following on 4/20/2007 11:42 AM: On 4/20/07, Sundar Dorai-Raj [EMAIL PROTECTED] wrote: Søren Højsgaard said the following on 4/20/2007 3:57 AM: Dear all, Consider this plot xyplot(Sepal.Length + Sepal.Width ~ Petal.Length | Species, data = iris, allow.multiple=T, outer=F, panel = function(x,y,...) { panel.xyplot(x,y,...) } ) I want to *add* some things to each panel and what I want to add involves using the data for each panel, so I try to take this subset of data out with subscripts: xyplot(Sepal.Length + Sepal.Width ~ Petal.Length | Species, data = iris, allow.multiple=T, outer=F, panel = function(x,y,subscripts,...) { panel.xyplot(x,y,...) subiris - iris[subscripts,] # Something using this ... } ) and then I get Error in NextMethod([) : argument subscripts is missing, with no default Interesting. I get Error in panel.superpose(x, y, type = type, groups = groups, pch = pch, : argument subscripts is missing, with no default which is somewhat more informative. Hi, Deepayan, Neither Søren nor I mentioned sessionInfo, which may be the reason our error messages differ from yours: sessionInfo() R version 2.4.1 (2006-12-18) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] grid stats graphics grDevices utils datasets [7] methods base other attached packages: lattice 0.14-17 --sundar Does anyone know how to obtain this?? By the way: The doc on xyplot says: The value of subscripts becomes slightly more complicated when allow.multiple is in effect. Details can be found in the source code of the function latticeParseFormula.. Sure. Maybe a better thing to say would be: The documented value of 'subscripts' does not hold when using an extended formula (with terms separated by '+'). which while entirely useless, is completely accurate and at least wouldn't give you anything to complain about. Would you prefer that? In any case, you can always do something like panel = function(x, y, subscripts, ...) { print(subscripts) ## debug }, R is a programming language after all, and if you are not prepared to use it as such, may be you shouldn't be writing complicated panel functions. -Deepayan Best regards Søren [[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. Hi, Søren, Since you add subscripts to your panel arguments, you now need to explicitly pass it on to panel.xyplot. Try: xyplot(Sepal.Length + Sepal.Width ~ Petal.Length | Species, data = iris, allow.multiple=T, outer=F, panel = function(x,y,subscripts,...) { panel.xyplot(x,y,subscripts=subscripts,...) subiris - iris[subscripts,] # Something using this ... }) HTH, --sundar __ 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] Positioning in xyplot
Michael Kubovy said the following on 4/10/2007 5:54 PM: On Apr 10, 2007, at 7:07 PM, Deepayan Sarkar wrote: On 4/10/07, Michael Kubovy [EMAIL PROTECTED] wrote: Dear R-helpers, I have an xyplot of the following kind: xYplot(y ~ x | p, groups = factor(gg, levels = c('1', '5', '2', '4', '3')), strip = strip.custom(var.name = 'g', factor.levels = c(1', '5', '2', '4', '3'), strip.levels = T, strip.names = T, sep = ' = ', shingle.intervals = NULL), data = df, type = 'b', label.curves = F, layout = c(2, 3), ) Currently this puts the panels as follows 3 2 4 1 5 I need: 3 2 4 1 5 How can I do this? Any help will be much appreciated. I don't understand what you mean. If you meant this: +---+ | | +---+---+ | | | +---+---+ | | | +---+---+ then see Sundar's answer. If you meant this: +---+ | | +-+---+-+ | | | +---+---+ | | | +---+---+ then you are out of luck (unless you are willing to do some low level coding). I guess I'm out of luck (I understood your two figures after turning them into fixed width font). At least you put me out of *this* misery. Thanks so much, Michael _ Professor Michael Kubovy University of Virginia Department of Psychology USPS: P.O.Box 400400Charlottesville, VA 22904-4400 Parcels:Room 102Gilmer Hall McCormick RoadCharlottesville, VA 22903 Office:B011+1-434-982-4729 Lab:B019+1-434-982-4751 Fax:+1-434-982-4766 WWW:http://www.people.virginia.edu/~mk9y/ [[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. Seems like you may get a workaround (albeit kludgey) by using ?print.trellis. Here's another example: library(lattice) z - expand.grid(x = 1:10, p = 1:5, r = 1:10) z$y - rnorm(nrow(z)) z$p - factor(z$p, levels = c(1, 5, 2, 4, 3)) bot - xyplot(y ~ x | p, z, groups = r, layout = c(2, 2), type = l, scales = list(alternating = 1), subset = p != 3) top - xyplot(y ~ x | p, z, groups = r, type = l, xlab = , scales = list(alternating = 2), subset = p == 3) print(bot, c(0, 0, 1, 11/16)) print(top, c(1/5, 7/12, 4/5, 1), newpage = FALSE) --sundar __ 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] Positioning in xyplot
Deepayan Sarkar said the following on 4/11/2007 1:55 PM: On 4/11/07, Sundar Dorai-Raj [EMAIL PROTECTED] wrote: Seems like you may get a workaround (albeit kludgey) by using ?print.trellis. Here's another example: library(lattice) z - expand.grid(x = 1:10, p = 1:5, r = 1:10) z$y - rnorm(nrow(z)) z$p - factor(z$p, levels = c(1, 5, 2, 4, 3)) bot - xyplot(y ~ x | p, z, groups = r, layout = c(2, 2), type = l, scales = list(alternating = 1), subset = p != 3) top - xyplot(y ~ x | p, z, groups = r, type = l, xlab = , scales = list(alternating = 2), subset = p == 3) print(bot, c(0, 0, 1, 11/16)) print(top, c(1/5, 7/12, 4/5, 1), newpage = FALSE) Here's another hack (thanks to Sundar for the reproducible example): library(grid) ## this is a safer version of current.panel.limits() current.limits - function () { xlim - convertX(unit(c(0, 1), npc), native, valueOnly = TRUE) ylim - convertY(unit(c(0, 1), npc), native, valueOnly = TRUE) if (any(!is.finite(xlim))) xlim - c(0, 1) if (any(!is.finite(ylim))) ylim - c(0, 1) list(xlim = xlim, ylim = ylim) } ## this calls 'fun' after moving its viewport if panel.number() == 5 callAfterMoving - function(fun, border = TRUE, move.x = 1, ...) { if (panel.number() == 5) { fun(...) if (border) grid.rect() } else { cpl - current.limits() pushViewport(viewport(x = move.x, width = unit(1, npc), xscale = cpl$xlim, yscale = cpl$ylim, clip = off)) fun(...) if (border) grid.rect() upViewport() } } ## this almost works, except for the axes on the left, because in the ## context in which it is drawn (the strip on the left, invisible in ## this example), information about how much to move right is not ## available. xyplot(y ~ x | p, z, groups = r, layout = c(2, 3), type = l, par.settings = list(axis.line = list(col = transparent), strip.border = list(col = transparent)), panel = function(...) { callAfterMoving(panel.xyplot, ...) }, strip = function(...) { callAfterMoving(strip.default, ...) }, axis = function(..., line.col) { callAfterMoving(axis.default, border = FALSE, line.col = 'black', ...) }) ## one way to bail out is simply not draw the left axes. It can also be ## added back explicitly by adding a call to panel.axis inside the ## panel function (see below) xyplot(y ~ x | p, z, groups = r, layout = c(2, 3), type = l, par.settings = list(axis.line = list(col = transparent), strip.border = list(col = transparent)), panel = function(...) { callAfterMoving(panel.xyplot, ...) }, strip = function(...) { callAfterMoving(strip.default, ...) }, axis = function(..., line.col, side) { if (side != left || panel.number() != 5) { callAfterMoving(axis.default, border = FALSE, line.col = 'black', side = side, ...) } }) ## panel function with axes on the left: panel.leftaxes - function(...) { if (panel.number() == 5) panel.axis(left, outside = TRUE, line.col = black) panel.xyplot(...) } xyplot(y ~ x | p, z, groups = r, layout = c(2, 3), type = l, par.settings = list(axis.line = list(col = transparent), strip.border = list(col = transparent)), panel = function(...) { callAfterMoving(panel.leftaxes, ...) }, strip = function(...) { callAfterMoving(strip.default, ...) }, axis = function(..., line.col, side) { if (side != left || panel.number() != 5) { callAfterMoving(axis.default, border = FALSE, line.col = 'black', side = side, ...) } }) -Deepayan Hi, Deepayan, See the attached image for what your code produced. Not sure if this is what you intended. Thanks, --sundar sessionInfo() R version 2.4.1 (2006-12-18) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] grid stats graphics grDevices utils datasets [7] methods base other attached packages: lattice 0.14-17 __ 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
Re: [R] Positioning in xyplot
Michael Kubovy said the following on 4/10/2007 3:21 PM: Dear R-helpers, I have an xyplot of the following kind: xYplot(y ~ x | p, groups = factor(gg, levels = c('1', '5', '2', '4', '3')), strip = strip.custom(var.name = 'g', factor.levels = c(1', '5', '2', '4', '3'), strip.levels = T, strip.names = T, sep = ' = ', shingle.intervals = NULL), data = df, type = 'b', label.curves = F, layout = c(2, 3), ) Currently this puts the panels as follows 3 2 4 1 5 I need: 3 2 4 1 5 How can I do this? Any help will be much appreciated. _ Professor Michael Kubovy University of Virginia Department of Psychology USPS: P.O.Box 400400Charlottesville, VA 22904-4400 Parcels:Room 102Gilmer Hall McCormick RoadCharlottesville, VA 22903 Office:B011+1-434-982-4729 Lab:B019+1-434-982-4751 Fax:+1-434-982-4766 WWW:http://www.people.virginia.edu/~mk9y/ __ 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. Hi, Michael, Use the skip argument. library(lattice) z - expand.grid(x = 1:10, y = 1:10, p = 1:5) z$p - factor(z$p, levels = c(1, 5, 2, 4, 3)) xyplot(y ~ x | p, z, layout = c(2, 3), skip = c(FALSE, FALSE, FALSE, FALSE, TRUE, FALSE)) Also you are using xYplot (presumably from Hmisc) and not lattice::xyplot. Thanks, --sundar __ 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] Annotate a levelplot (using abline) - Difficulty with trellis.
Dan Bolser said the following on 4/4/2007 7:52 AM: My question was thus; Given library(lattice) my.m - matrix(seq(1,100,1),nrow=10) levelplot(my.m) How can I add a diagonal line onto the resulting 'color square'? The answer I found was to hack the 'panel.levelplot' function. Here is the diff between the old (panel.levplot) and the new (my.panel.levplot) functions; *** *** 72,77 --- 82,89 shrinky[2], fullZrange), default.units = native, gp = gpar(fill = col.regions[zcol], lwd = 1e-05, col = transparent, alpha = alpha.regions)) + ## Added by Dan + panel.abline(0,1,col=white) if (contour) { if (is.logical(labels) !labels) labels - NULL And then use... library(lattice) my.m - matrix(seq(1,100,1),nrow=10) levelplot(my.m, panel=my.panel.levelplot) I accidentally started to talk to Charilaos Skiadas 'off-list', so thanks to him for help. Dan. [[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. Hi, Dan, This can be more easily done using the following: library(lattice) my.m - matrix(seq(1, 100, 1), nrow = 10) my.panel.levelplot - function(...) { panel.levelplot(...) panel.abline(0, 1, col = white) } levelplot(my.m, panel = my.panel.levelplot) HTH, --sundar __ 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] options(error=recover) in .Rprofile
Andy Jacobson said the following on 3/28/2007 4:01 PM: Hi, I'd like to try using options(error=recover) in my ~/.Rprofile, but it appears that the function recover is not defined during R startup when the .Rprofile is processed. recover is defined after I get an R prompt, however. Can anyone shed light on why this is, and whether a work-around is possible? I've tested this on a variety of systems including recent linux and OSX, using R 2.4.0. Seems to be pretty generic. Thanks, Andy Perhaps this thread will help: http://finzi.psych.upenn.edu/R/Rhelp02a/archive/84872.html BTW, I found this using RSiteSearch(recover) in R. HTH, --sundar __ 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] impose points on lattice plot
Luis Ridao Cruz said the following on 3/27/2007 6:15 AM: R-help, I'm using the lattice package to plot 2 variables (vekt ~ aldur) conditioned to a third (kyn * 2 categories). I use the following: xyplot(vekt ~ aldur|kyn, , data = sexSu) I want to superimpose the average(vekt) by 'aldur' conditioned to kyn by using something like: xyplot(vekt~aldur|kyn, subset = aldur = 12 , data = sexSu, panel = function(x, y) { panel.xyplot(x, y) panel.points(x,mean(y),col=2,cex=2 ) }) but th output is just a horozontal line ( the average of 'vekt') in both panels I guess) How can be done? An working example would be nice. But here's one possible solution if I understand your question correctly: xyplot(vekt~aldur|kyn, subset = aldur = 12 , data = sexSu, panel = function(x, y) { panel.xyplot(x, y) mx - sort(unique(x)) my - tapply(y, x, mean) o - order(mx) panel.points(mx[o],my[o],col=2,cex=2 ) }) but th output Thanks in advance version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 4.1 year 2006 month 12 day18 svn rev40228 language R version.string R version 2.4.1 (2006-12-18) __ 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] Replacement in an expression - can't use parse()
Daniel Berg said the following on 3/27/2007 6:56 AM: Dear all, Suppose I have a very long expression e. Lets assume, for simplicity, that it is e = expression(u1+u2+u3) Now I wish to replace u2 with x and u3 with 1. I.e. the 'new' expression, after replacement, should be: e expression(u1+x+1) My question is how to do the replacement? I have tried using: e = parse(text=gsub(u2,x,e)) e = parse(text=gsub(u3,1,e)) Even though this works fine in this simple example, the use of parse when e is very long will fail since parse has a maximum line length and will cut my expressions. I need to keep mode(e)=expression since I will use e further in symbolic derivation and division. Any suggestions are most welcome. Thank you. Regards, Daniel Berg __ 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. Take a look at ?substitute (or ?bquote) as.expression(substitute(u1+u2+u3, list(u1 = quote(x expression(x + u2 + u3) as.expression(bquote(u1+u2+.(u3), list(u3 = 1))) expression(u1 + u2 + 1) HTH, --sundar __ 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 drop variables using a wildcard and logic...
Alternatively, you can use ?glob2rx test[, grep(glob2rx(*[tT]), names(test))] which allows for wildcards. --sundar Benilton Carvalho said the following on 3/26/2007 12:19 PM: if 'test' is your data frame... test[, grep([tT]$, names(test))] b On Mar 26, 2007, at 3:06 PM, [EMAIL PROTECTED] wrote: Dear R users I would like to make a new dataframe from an existing dataframe, retaining ONLY those variables that end in the letter t I have searched the help archives and consulted several reference books but cannot seem to find an example. Any ideas...? Thanks! Mark [[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-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] lattice key (legend) with both points and lines
Peter McMahan said the following on 3/20/2007 3:16 PM: Hello, I'm running into a frustrating problem with the legend on a lattice plot I'm working with. The plot is a stripplot with a panel.linejoin () line running through the mean of each of the categories. Thus there are both points and lines in the plot. In trying to make a key for the plot, I can't figure out how to make a legend for both the points and the lines. What I'd like is something like: prices* means - in which there are two rows in the legend, one with the point and its label and one with the line and its label. By supplying this type of argument to stripplot: key=list(text=list(lab=prices), points=list(...), text=list(lab=means), lines=list(...)) I can get a legend that looks like: prices* means - But this looks awkward with my plot Is there any way to have the plot elements and their labels be in the same column? Thanks, Peter __ 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. You can try: library(lattice) xyplot(1:10 ~ 1:10, key = list(text = list(c(prices, means)), lines = list( pch = c(*, ), type = c(p, l), cex = 2, col = red, lwd = 3))) HTH, --sundar __ 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 in upgrade
Giovanni Parrinello said the following on 3/15/2007 6:43 AM: Dear All, update.packages(ask='graphics') --- Please select a CRAN mirror for use in this session --- Error in .readRDS(pfile) : unknown input format. ??? TIA Giovanni I cannot replicate this in R-2.4.1. What version of R and repository are you using? update.packages(ask = graphics, repos = http://cran.cnr.berkeley.edu;) --sundar __ 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] lattice: put key where unused panel would have been
Benjamin Tyner said the following on 1/22/2007 3:18 PM: Hi, Say I have z-data.frame(y=runif(190), x=runif(190), f=gl(5,38), g=gl(19,10)) plot-xyplot(y~x|g, data=z, layout=c(5,4), groups=f, auto.key=TRUE) How might one place the key in the empty space where the twentieth panel would have been? Thanks, Ben __ 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. You can try supplying x and y coordinates to auto.key xyplot(y ~ x | g, data = z, layout = c(5, 4), groups = f, auto.key = list(x = .85, y = .9)) HTH, --sundar __ 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 get correct integration in C for step function?
Hi, Lynette, A few pointers: 1. Not an R question. 2. Not an ESS question. 3. No reproducible example. 4. (x = 1/4) is comparing a pointer. Surely, this is not what you intended to do. Plus, if you're using void* then this is not even a C function called by R. And I'm not familiar with Rdqags. 5. Please use the posting guide in the future. http://www.R-project.org/posting-guide.html HTH, --sundar Lynette said the following on 1/21/2007 5:24 PM: Dear all, I am using Rdqags in C to realize the integration. It seems for the continous C function I can get correct results. However, for step functions, the results are not correct. For example, the following one, when integrated from 0 to 1 gives 1 instead of the correct 1.5 void func( double *x, int n, void *ex ) { int i; for(i=0;in;i++) { x[i]=( ((x=1/4)(x=3/4)) ? 2:1 ) ; } return; } while the following one when integrated from 0 to 1 gives the correct 0.7853983 void func( double *x, int n, void *ex ) { int i; for(i=0;in;i++) { x[i]= pow(1-x[i]*x[i],.5); } return; } Please advise the problems. Thanks a lot. Best, Lynette __ 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] .C interface and Strings...
Stephane Cruveiller said the following on 1/12/2007 4:15 AM: Dear R users, I am trying to include C code into R via the .C interface. I have read that arguments passed to a C function have to be correctly DEreferenced. This is something that can be easily done for numbers (integers or float) by adding a * before the reference like for instance: #includeR.h void hellofct(int *n) { int i; for (i=0;i*n;i++) { Rprintf(Hello, world!\n); } } However, I can not figure out how that can be achieved for strings. My prototype function would be something like: #includeR.h void displaystring(char *str) { Rprintf(String displayed:%s\n, ); } any hints? Yes, Section 5.2 in Writing R Extensions. untested displaystring.c: #includeR.h void displaystring(char **str, int *n) { int i; for(i = 0; i *n; i++) Rprintf(String displayed:%s\n, str[i]); } displaystring.dll: R CMD SHLIB displaystring.c displaystring.R: dyn.load(displaystring) displaystring - function(x) { .C(displaystring, x, length(x)) invisible() } displaystring(c(A, B)) /untested HTH, --sundar __ 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] extract standard errors, write them to file
Indermaur Lukas said the following on 1/12/2007 7:55 AM: Hello I want to repeatedly extract coefficients and standard errors from a GLM and write them into a file (1row=all coefficients of model A, 2 row=all coefficients of model B, etc.). I can extract coefficients but not standard errors. furthermore I fail to write extracted values line by line into the predifined matrix G. I appreciate any idea to solve the problem best regards Lukas #-start code global - formula(logHRS~Ri + E + Co + LWD +Alwd +W + T2 + A + N + Sex + y) #1 richness_evenness- formula(logHRS~Ri + E + D1 + D2 +D3 +D4 + D5 + D6 + N + Sex + y)#2 all_models - c(global, richness_evenness) for (i in 1:length(all_models)) { ts.model - glm(all_models[[i]],family=gaussian,data=t.data) G- matrix(NA,length(all_models),length(all_models)) G- coefficients(ts.model) #regression coefficents (betas) } write.table(G, paste(t.url, file=Coefficients.txt), sep=\t, quote=F) #-end code- °°° Lukas Indermaur, PhD student eawag / Swiss Federal Institute of Aquatic Science and Technology ECO - Department of Aquatic Ecology Überlandstrasse 133 CH-8600 Dübendorf Switzerland Phone: +41 (0) 71 220 38 25 Fax: +41 (0) 44 823 53 15 Email: [EMAIL PROTECTED] www.lukasindermaur.ch __ 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. Your code is barely readable because of poor spacing, but I believe you want: coef(summary(ts.model))[, 1:2] --sundar __ 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] sapply problem
Joerg van den Hoff said the following on 12/14/2006 7:30 AM: I have encountered the following problem: I need to extract from a list of lists equally named compenents who happen to be 'one row' data frames. a trivial example would be: a - list(list( df = data.frame(A = 1, B = 2, C = 3)), list(df = data.frame(A = 4,B = 5,C = 6))) I want the extracted compenents to fill up a matrix or data frame row by row. the obvious thing to do seems: b - sapply(a, [[, df) b - t(b) now `b' looks all right: b class(b) but it turns out that all elements in this matrix are one element lists: class(b[1,1]) which prevents any further standard processing of `b' (like `colMeans', e.g.) question 1: is their a straightforward way to enforce that `b' contains simple numbers as elements right from the start (instead of something like apply(b, 1:2, class-, numeric) afterwards)? Try this: a - list(list(df = data.frame(A = 1, B = 2, C = 3)), list(df = data.frame(A = 4, B = 5, C = 6))) b - do.call(rbind, sapply(a, [, df)) b question 2: should not sapply do this further 'simplification' anyway in a situation like this (matrix elements turn out to be one-element lists)? I think it does as it much as it knows how. I think you might believe that matrix elements can only contain numeric values. This is not a valid assumption. Take this example: a - list(1) b - list(2) (m - matrix(c(a, b), 2, 1)) [,1] [1,] 1 [2,] 2 class(m[1, 1]) [1] list class(m[2, 1]) [1] list HTH, --sundar regards joerg __ 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] How to use read.xls in R
Lisa Wang said the following on 12/7/2006 3:01 PM: Hello there, In gdata package, read.xls is to be used for reading excel data (from windows). The following is my code:('C:/session/sampledata.xls' is where the file is stored) data1-read.xls('C:/session/sampledata.xls',sheet=1) and I got the following error message: Error in system(cmd, intern = !verbose) : perl not found Could you please tell me what I have done wrong and how I should do it? Thanks a lot Lisa Wang Princess Margaret Hospital, Toronto, Ca tel:416 946 4551 __ 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. Please reread ?read.xls. Quote from the Note section: Either a working version of Perl must be present in the executable search path, or the exact path of the perl executable must be provided via the perl argument. See the examples below for an illustration. You need to install perl. http://www.activestate.com/Products/ActivePerl/Download.html HTH, --sundar __ 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] lattice plots - variables in columns
Matt Pocernich said the following on 12/4/2006 12:32 PM: I an using xyplot in lattice. I have data in a dataframe. Some columns contains data, each from a different group. Is there a direct way to specify a range of column names as a grouping variables? Currently, I am stacking the data and creating a column with names. Thanks, Matt Hi, Matt, Yes. Try this: my.data - data.frame(x = 1:10, y1 = 1:10, y2 = 11:20) xyplot(y1 + y2 ~ x, my.data) ## or if you want y1,y2 in panels xyplot(y1 + y2 ~ x, my.data, outer = TRUE) HTH, --sundar __ 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] Question about error message - or is it a bug?
Carmen Meier said the following on 11/10/2006 9:46 AM: Hi to all ... the same code, but another question. I changed only the type='n' to type='l' and debugged the function xy.coords. with type = 'l' : there are the correct values of x and y inside the function xy.coords but the y value is filled with NA seems that the length is matching now because of the NAs with type = 'n' : there are the wrong values of x in the function xy.coords and the y value is not filled with NA So there is a length mismatch additionally to the wrong x values Maybe anybody could evaluate whether this is an error (some kind of misunderstanding) from me or a bug Regards Carmen see codes below Hi, Carmen The problem is not in xy.coords, but in chron:::plot.times. Why do you set y to c(0, 10)? This is not the same length as x which is why you are getting this error. Since it's not clear what type of plot you expect, it's difficult to comment further. Try: debug(chron:::plot.times) to see how your function call is being interpreted by the code. Also, in the future, please tell us where to find non-base functions such as times. Thanks, --sundar #--- Code --- time - c(2:25:00,2:26:00,2:27:00,2:28:00,2:29:00,2:30:00,2:31:00, 2:32:00,2:33:00,2:34:00,2:35:00,2:36:00,2:37:00,2:38:00, 2:39:00,2:40:00,2:41:00,2:42:00,2:43:00,2:44:00,2:45:00, 2:46:00,2:47:00,2:48:00,2:49:00,2:50:00,2:51:00,2:52:00, 2:53:00,2:54:00,2:55:00,2:56:00,2:57:00,2:58:00,2:59:00, 3:00:00,3:01:00,3:02:00,3:03:00,3:04:00,3:05:00,3:06:00, 3:07:00,3:08:00,3:09:00,3:10:00,3:11:00,3:12:00,3:13:00, 3:14:00) y - c(0,10) plot(times(time), y, type='n') #-- Debugging --- debug(xy.coords) plot(times(time), y, type='l') debug: if (is.null(y)) { ylab - xlab if (is.language(x)) { if (inherits(x, formula) length(x) == 3) { ylab - deparse(x[[2]]) xlab - deparse(x[[3]]) y - eval(x[[2]], environment(x), parent.frame()) x - eval(x[[3]], environment(x), parent.frame()) } else stop(invalid first argument) } else if (inherits(x, ts)) { y - if (is.matrix(x)) x[, 1] else x x - stats::time(x) xlab - Time } else if (is.complex(x)) { y - Im(x) x - Re(x) xlab - paste(Re(, ylab, ), sep = ) ylab - paste(Im(, ylab, ), sep = ) } else if (is.matrix(x) || is.data.frame(x)) { x - data.matrix(x) if (ncol(x) == 1) { xlab - Index y - x[, 1] x - seq_along(y) } else { colnames - dimnames(x)[[2]] if (is.null(colnames)) { xlab - paste(ylab, [,1], sep = ) ylab - paste(ylab, [,2], sep = ) } else { xlab - colnames[1] ylab - colnames[2] } y - x[, 2] x - x[, 1] } } else if (is.list(x)) { xlab - paste(ylab, $x, sep = ) ylab - paste(ylab, $y, sep = ) y - x[[y]] x - x[[x]] } else { if (is.factor(x)) x - as.numeric(x) xlab - Index y - x x - seq_along(x) } } Browse[1] debug: if (inherits(x, POSIXt)) x - as.POSIXct(x) Browse[1] debug: if (length(x) != length(y)) { if (recycle) { if ((nx - length(x)) (ny - length(y))) x - rep(x, length.out = ny) else y - rep(y, length.out = nx) } else stop('x' and 'y' lengths differ) } Browse[1] x [1] 0.1006944 0.1013889 0.1020833 0.1027778 0.1034722 0.1041667 0.1048611 0.106 0.1062500 [10] 0.1069444 0.1076389 0.108 0.1090278 0.1097222 0.1104167 0.111 0.1118056 0.1125000 [19] 0.1131944 0.1138889 0.1145833 0.1152778 0.1159722 0.117 0.1173611 0.1180556 0.1187500 [28] 0.119 0.1201389 0.1208333 0.1215278 0.122 0.1229167 0.1236111 0.1243056 0.125 [37] 0.1256944 0.1263889 0.1270833 0.128 0.1284722 0.1291667 0.1298611 0.1305556 0.1312500 [46] 0.1319444 0.1326389 0.133 0.1340278 0.1347222 attr(,format) [1] h:m:s Browse[1] y [1] 0 10 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA [31] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA Browse[1] #-- debug(xy.coords) plot(times(time), y, type='n') debug: if (length(x) != length(y)) { if (recycle) { if ((nx - length(x)) (ny - length(y))) x - rep(x, length.out = ny) else y - rep(y, length.out = nx) } else stop('x' and 'y' lengths differ) }
Re: [R] combining dataframes with different numbers of columns
hadley wickham said the following on 11/7/2006 8:46 PM: On 11/7/06, Denis Chabot [EMAIL PROTECTED] wrote: Dear list members, I have to combine dataframes together. However they contain different numbers of variables. It is possible that all the variables in the dataframe with fewer variables are contained in the dataframe with more variables, though it is not always the case. There are key variables identifying observations. These could be used in a merge statement, although this won't quite work for me (see below). I was hoping to find a way to combine dataframes where I needed only to ensure the key variables were present. The total number of variables in the final dataframe would be the total number of different variables in both initial dataframes. Variables that were absent in one dataframe would automatically get missing values in the joint dataframe. Have a look at rbind.fill in the reshape package. library(reshape) rbind.fill(data.frame(a=1), data.frame(b=2)) rbind.fill(data.frame(a=1), data.frame(a=2, b=2)) 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. Or, try this: http://finzi.psych.upenn.edu/R/Rhelp02a/archive/77358.html HTH, --sundar __ 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] nontabular logistic regression
Jeffrey Stratford said the following on 10/13/2006 9:28 AM: Hi. I'm attempting to fit a logistic/binomial model so I can determine the influence of landscape on the probability that a box gets used by a bird. I've looked at a few sources (MASS text, Dalgaard, Fox and google) and the examples are almost always based on tabular predictor variables. My data, however are not. I'm not sure if that is the source of the problems or not because the one example that includes a continuous predictor looks to be coded exactly the same way. Looking at the output, I get estimates for each case when I should get a single estimate for purbank. Any suggestions? Many thanks, Jeff THE DATA: (200 boxes total, used [0 if unoccupied, 1 occupied], the rest are landscape variables). box use purbank purban2 purban1 pgrassk pgrass2 pgrass1 grassdist grasspatchk 1 1 0.003813435 0.02684564 0.06896552 0.3282487 0.6845638 0.7586207 0 3.73 2 1 0.04429451 0.1610738 0.1724138 0.1534174 0.3825503 0.6551724 0 1.023261 3 1 0.04458785 0.06040268 0 0.1628043 0.5570470.7586207 0 0.9605769 4 1 0.06072162 0.2080537 0.06896552 0.01936052 0 0 323.10990.2284615 5 0 0.6080962 0.6979866 0.6896552 0.03168084 0.1275168 0.2413793 30 0.2627027 6 1 0.6060428 0.6107383 0.3448276 0.04077442 0.2885906 0.4482759 30 0.2978571 7 1 0.3807568 0.4362416 0.6896552 0.06864183 0.03355705 0 94.868330.468 8 0 0.3649164 0.3154362 0.4137931 0.06277501 0.1275168 0 120 0.4585714 THE CODE: box.use- read.csv(c:\\eabl\\2004\\use_logistic2.csv, header=TRUE) attach(box.use) box.use - na.omit(box.use) use - factor(use, levels=0:1) levels(use) - c(unused, used) glm1 - glm(use ~ purbank, binomial) THE OUTPUT: Coefficients: Estimate Std. Error z value Pr(|z|) (Intercept)-4.544e-16 1.414e+00 -3.21e-161.000 purbank02.157e+01 2.923e+04 0.0010.999 purbank0.001173365 2.157e+01 2.067e+04 0.0010.999 purbank0.001466706 2.157e+01 2.923e+04 0.0010.999 purbank0.001760047 6.429e-16 2.000e+00 3.21e-161.000 purbank0.002346729 2.157e+01 2.923e+04 0.0010.999 purbank0.003813435 2.157e+01 2.923e+04 0.0010.999 purbank0.004106776 2.157e+01 2.067e+04 0.0010.999 purbank0.004693458 2.157e+01 2.067e+04 0.0010.999 Jeffrey A. Stratford, Ph.D. Postdoctoral Associate 331 Funchess Hall Department of Biological Sciences Auburn University Auburn, AL 36849 334-329-9198 FAX 334-844-9234 http://www.auburn.edu/~stratja __ 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. That's not what I get: lines - box,use,purbank,purban2,purban1,pgrassk,pgrass2,pgrass1,grassdist,grasspatchk 1,1,0.003813435,0.02684564,0.06896552,0.3282487,0.6845638,0.7586207,0,3.73 2,1,0.04429451,0.1610738,0.1724138,0.1534174,0.3825503,0.6551724,0,1.023261 3,1,0.04458785,0.06040268,0,0.1628043,0.557047,0.7586207,0,0.9605769 4,1,0.06072162,0.2080537,0.06896552,0.01936052,0,0,323.1099,0.2284615 5,0,0.6080962,0.6979866,0.6896552,0.03168084,0.1275168,0.2413793,30,0.2627027 6,1,0.6060428,0.6107383,0.3448276,0.04077442,0.2885906,0.4482759,30,0.2978571 7,1,0.3807568,0.4362416,0.6896552,0.06864183,0.03355705,0,94.86833,0.468 8,0,0.3649164,0.3154362,0.4137931,0.06277501,0.1275168,0,120,0.4585714 box.use - read.csv(textConnection(lines)) box.use - na.omit(box.use) box.use$use - factor(box.use$use, levels=0:1) levels(box.use$use) - c(unused, used) (glm1 - glm(use ~ purbank, binomial, box.use)) You need to check why purbank is being interpreted as a factor in your code. Also, I removed your use of attach because I find it dangerous (especially with no detach). Better to be explicit. HTH, --sundar __ 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 error bars to lattice plots
Daniel E. Bunker said the following on 10/12/2006 11:48 AM: Dear R users, About a year ago Deepayan offered a suggestion to incorporate error bars into a dotplot using the singer data as an example http://finzi.psych.upenn.edu/R/Rhelp02a/archive/63875.html. When I try to utilize this code with a grouping variable, I get an error stating that the subscripts argument is missing. I have tried to insert them in various ways, but cannot figure out where they should go. Deepayan's original code follows, with additions from me for factor, grouping and by variables. (Note that I could use xYplot (Dotplot), but I need my response variable on the vertical axis.) Any suggestions would be greatly appreciated. Thanks, Dan prepanel.ci - function(x, y, lx, ux, subscripts, ...) { x - as.numeric(x) lx - as.numeric(lx[subscripts]) ux - as.numeric(ux[subscripts]) list(xlim = range(x, ux, lx, finite = TRUE)) } panel.ci - function(x, y, lx, ux, subscripts, pch = 16, ...) { x - as.numeric(x) y - as.numeric(y) lx - as.numeric(lx[subscripts]) ux - as.numeric(ux[subscripts]) panel.abline(h = unique(y), col = grey) panel.arrows(lx, y, ux, y, col = 'black', length = 0.25, unit = native, angle = 90, code = 3) panel.xyplot(x, y, pch = pch, ...) } singer.split - with(singer, split(height, voice.part)) singer.ucl - sapply(singer.split, function(x) { st - boxplot.stats(x) c(st$stats[3], st$conf) }) singer.ucl - as.data.frame(t(singer.ucl)) names(singer.ucl) - c(median, lower, upper) singer.ucl$voice.part - factor(rownames(singer.ucl), levels = rownames(singer.ucl)) # add factor, grouping and by variables singer.ucl$fac1=c(level1,level1, level2, level2) singer.ucl$by1=c(two,one) singer.ucl$group1=c(rep(letters[1],4),rep(letters[2],4)) ## show the data frame singer.ucl # Deepayan's original example with(singer.ucl, xyplot(voice.part ~ median, lx = lower, ux = upper, prepanel = prepanel.ci, panel = panel.ci), horizontal=FALSE) # with by variable, works fine with(singer.ucl, xyplot(voice.part ~ median|by1, lx = lower, ux = upper, prepanel = prepanel.ci, panel = panel.ci)) # with groups, fails for lack of subscripts. with(singer.ucl, xyplot(voice.part ~ median, groups=group1, lx = lower, ux = upper, prepanel = prepanel.ci, panel = panel.ci)) # what I need, ultimately, is something like this, with error bars: with(singer.ucl, dotplot(median~fac1|by1, groups=group1)) __ 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. Hi, Daniel, Try this panel function: panel.ci - function(x, y, lx, ux, subscripts, groups = NULL, pch = 16, ...) { x - as.numeric(x) y - as.numeric(y) lx - as.numeric(lx[subscripts]) ux - as.numeric(ux[subscripts]) par - if(is.null(groups))plot.symbol else superpose.symbol sym - trellis.par.get(par) col - sym$col groups - if(!is.null(groups)) { groups[subscripts] } else { rep(1, along = x) } ug - unique(groups) for(i in seq(along = ug)) { subg - groups == ug[i] y.g - y[subg] x.g - x[subg] lx.g - lx[subg] ux.g - ux[subg] panel.abline(h = unique(y.g), col = grey) panel.arrows(lx.g, y.g, ux.g, y.g, col = 'black', length = 0.25, unit = native, angle = 90, code = 3) panel.xyplot(x.g, y.g, pch = pch, col = col[i], ...) } } __ 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] R not responding for nested glm model
Yuval Sapir said the following on 10/12/2006 1:08 PM: Hi, I'm trying to perform a glm model on count data (poisson distribution of the errors) where data are nested. glmmodel-glm(y~x/z,poisson) x and z are factors, z nested within x, y is count data. In that point the R just stuck and not respond anymore. I tried glmmodel-glm(y~x,poisson) and there were no problems. Trying glmmodel-glm(y~x/z) gave the same no response. Similar problem with continuous data (normal distribution of the errors). I am using R 2.3.1 on Windows XP Thanks Yuval Please see the signature and provide commented, minimal, self-contained, reproducible code. Namely, what is 'x' and 'z'? My guess is ~x/z produces so large a model matrix you are approaching your limits of memory. But, there's no way to tell without more information. HTH, --sundar __ 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] xyplot
Osman Al-Radi said the following on 10/5/2006 3:43 PM: Hi, for the data below: time-c(rep(1:10,5)) y-time+rnorm(50,5,2) subject-c(rep('a',10),rep('b',10),rep('c',10),rep('d',10),rep('e',10)) group-c(rep('A',30),rep('B',20)) df-data.frame(subject,group,time,y) I'd like to produce a plot with a single pannel with two loess curves one for each group. the code below does that but on two different pannels, I'd like to have both curves on the same pannel with different colors. xyplot(y~time|group, groups=subject, panel=function(...){ panel.loess(...) } ,data=df) Simple: xyplot(y ~ time | group, data = df, groups = subject, panel = function(...) { panel.superpose(...) panel.superpose(panel.groups = panel.loess, ...) }) HTH, --sundar __ 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] safe prediction from lm
Spencer Jones said the following on 9/28/2006 10:44 AM: I am fitting a regression model with a bs term and then making predictions based on the model. According to some info on the internet at http://www.stat.auckland.ac.nz/~yee/smartpred/DummiesGuide.txt there are some problems with using predict.lm when you have a model with terms such as bs,ns,or poly. However when I used one of the examples they said would illustrate the problems I get virtually the same results using the standard predict function and safe prediction method they propose. Has lm been updated so that it can handle terms such as bs,ns, and poly automatically? I am using R 2.3.0 this is their example: n - 100 set.seed(86) # For reproducibility of the random numbers x - sort(runif(n)) y - sort(runif(n)) fit - lm(y ~ bs(x, df=5)) plot(x, y,col=blue) lines(x, fitted(fit), col=black) newx - seq(0, 1, len=n) points(newx, predict(fit, data.frame(x=newx)), type=l, col=red, err=-1) thanks, Spencer [[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. Hi, Spencer, That website is for S-PLUS and not R. When I run the code in S-PLUS 6.2, I do indeed see different curves. HTH, --sundar __ 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] Single Precision (4 byte) floats with readBin
Peter Lauren said the following on 9/27/2006 3:11 PM: I would like to use readBin to read a binary data file. Most of the data is 4-byte floating point but, for some reason, only double precision appears to be offered. I tried fVariable=readBin(iFile,what=single()); and got 35.87879 which looks believable except that the correct value is 3.030303. I then tried fVariable=readBin(iFile,what=single(),4); and got [1] 3.83e+10 6.657199e+10 -5.592394e+29 -5.592397e+29 For the second call, there were two more single precision floats of value 3.030303 followed by two more with values 40.46 and 0.00 respectively. Is there any way around this problem other than to make the input data double (which I definitely do not want to do)? Many thanks in advance, Peter. __ 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. Hi, Peter, I believe you can use readBin(file, double(), size = 4) Thanks, --sundar __ 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] Print and supressing printing in function
Marc Schwartz said the following on 9/24/2006 1:56 PM: On Sun, 2006-09-24 at 11:31 -0700, Jonathan Greenberg wrote: Another newbie question for you all: In a function, say I have: countme - function() { for(i in 1:10) { i } } How do I get R to print i as it runs (e.g. By calling countme) -- right now it seems to supress most output. On a related note, my program uses remove.vars, which always prints its output -- how to I *supress* that output? Thanks! You need to explicitly print() the value. Thus: countme - function() { for(i in 1:10) { print(i) } } countme() [1] 1 [1] 2 [1] 3 [1] 4 [1] 5 [1] 6 [1] 7 [1] 8 [1] 9 [1] 10 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. (Answering remove.vars question) Please read ?remove.vars. (You neglected to mention this function is part of the gdata package.) There is an info argument you want to set to FALSE. HTH, --sundar __ 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] Double integral
Caio Lucidius Naberezny Azevedo said the following on 9/22/2006 4:40 PM: Hi all, I need to solve double integrals with no closed solution. Calling x and y the two variables we have x ~ Normal(y*v,1) and y ~Half-Normal(0,1). In fact, given a joint funcion g(x,y), I need evaluate the integral of this function under that random structure. Could anyone suggest me a package or even a suitable method to solve this problem? Thanks all, Caio - [[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. Have you tried RSiteSearch(double integral) as the posting guide suggests? --sundar __ 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] Matrix from a vector?
kone said the following on 9/21/2006 2:30 PM: Hi, Is there some function, which generates this kind of n x n -matrix from a vector? rhset [1] 1792 256 13312 512 1024 2048 8192 4096 m=matrix(nrow=length(rhset),ncol=length(rhset)) for(i in 1:length(rhset)) + { + m[,i]=rhset + rhset=c(rhset[length(rhset)], rhset[2:length(rhset)-1]) + } m [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,] 1792 4096 8192 2048 1024 512 13312 256 [2,] 256 1792 4096 8192 2048 1024 512 13312 [3,] 13312 256 1792 4096 8192 2048 1024 512 [4,] 512 13312 256 1792 4096 8192 2048 1024 [5,] 1024 512 13312 256 1792 4096 8192 2048 [6,] 2048 1024 512 13312 256 1792 4096 8192 [7,] 8192 2048 1024 512 13312 256 1792 4096 [8,] 4096 8192 2048 1024 512 13312 256 1792 Atte Tenkanen University of Turku, Finland __ 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. Does this work for you? rhsel - c(1792, 256, 13312, 512, 1024, 2048, 8192, 4096) n - length(rhsel) i - sapply(1:n, function(i) (1:n - i)%%n + 1) matrix(rhsel[i], n, n) HTH, --sundar __ 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] Add percentage to pie (was (no subject))
ERICK YEGON said the following on 9/18/2006 8:22 AM: Hi Gurus, i have a small problem with working with graphs on R. Say i have data say bull-c(34,23,7,4) and i assign names to the elements in the brackets if i do Pie(bull) i get a pie chart of bull togtjer with the names. Question. How can i add values (percentages) in the graph Thanks __ 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. (Please use a sensible subject line!) Where do you want to add percentages? If next to the labels, then just use: bull - c(34, 23, 7, 4) names(bull) - LETTERS[seq(along = bull)] lbl - sprintf(%s = %3.1f%s, names(bull), bull/sum(bull)*100, %) pie(bull, lbl) --sundar __ 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] acos(0.5) == pi/3 FALSE
Iñaki Murillo Arcos said the following on 9/18/2006 12:31 PM: Hello, I don't know if the result of acos(0.5) == pi/3 is a bug or not. It looks strange to me. Inaki Murillo __ 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. This is a FAQ: http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f acos(.5) [1] 1.047198 pi/3 [1] 1.047198 acos(0.5) == pi/3 [1] FALSE all.equal(acos(0.5), pi/3) [1] TRUE --sundar __ 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] dotplot, dropping unused levels of 'y'
Benjamin Tyner said the following on 9/15/2006 2:36 PM: In dotplot, what's the best way to suppress the unused levels of 'y' on a per-panel basis? This is useful for the case that 'y' is a factor taking perhaps thousands of levels, but for a given panel, only a handfull of these levels ever present. Thanks, Ben __ 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. Hi, Ben, Use scales(x = list(relation = free)) in your call to dotplot: library(lattice) z - data.frame(x = rep(LETTERS[1:20], each = 4), y = 1:80, g = gl(4, 20)) dotplot(y ~ x | g, z, scales = list(x = list(relation = free))) HTH, --sundar __ 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] converting strings to expressions
Deepayan Sarkar said the following on 9/14/2006 2:31 PM: Hi, consider this: -- estr - c(2^4, alpha[1]) eexp - expression(2^4, alpha[1]) ## Is it possible to get 'eexp' starting from 'estr'? The closest I could ## get was: do.call(expression, lapply(estr, as.name)) ## but it is not quite the same; e.g. the following behave differently: library(lattice) xyplot(1:10 ~ 1:10, scales = list(x = list(at = c(3, 6), labels = eexp))) xyplot(1:10 ~ 1:10, scales = list(x = list(at = c(3, 6), labels = do.call(expression, lapply(estr, as.name) --- This happens in both 2.3.1 and pre-2.4.0. Deepayan sessionInfo() Version 2.3.1 Patched (2006-08-27 r39012) x86_64-unknown-linux-gnu attached base packages: [1] methods stats graphics grDevices utils datasets [7] base other attached packages: lattice 0.13-10 sessionInfo() R version 2.4.0 Under development (unstable) (2006-08-30 r39022) x86_64-unknown-linux-gnu locale: C attached base packages: [1] methods stats graphics grDevices utils datasets [7] base other attached packages: lattice 0.14-3 __ 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. Hi, Deepayan, Will this work for you? estr - c(2^4, alpha[1]) eexp - expression(2^4, alpha[1]) library(lattice) xyplot(1:10 ~ 1:10, scales = list(x = list(at = c(3, 6), labels = eexp))) estr.2 - sprintf(expression(%s), paste(estr, collapse = ,)) eexp.2 - eval(parse(text = estr.2)) xyplot(1:10 ~ 1:10, scales = list(x = list(at = c(3, 6), labels = eexp.2))) Works in both R-2.3.1 and R-2.4.0dev. Typically, I don't like using eval(parse(text=...)), but I've run into this problem before I could not see another way. Perhaps Gabor will enlighten us with something slicker. HTH, --sundar __ 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] S in cor.test(..., method=spearman)
Dietrich Trenkler said the following on 9/13/2006 9:44 AM: Dear HelpeRs, I have some data: ice - structure(c(0.386, 0.374, 0.393, 0.425, 0.406, 0.344, 0.327, 0.288, 0.269, 0.256, 0.286, 0.298, 0.329, 0.318, 0.381, 0.381, 0.47, 0.443, 0.386, 0.342, 0.319, 0.307, 0.284, 0.326, 0.309, 0.359, 0.376, 0.416, 0.437, 0.548, 41, 56, 63, 68, 69, 65, 61, 47, 32, 24, 28, 26, 32, 40, 55, 63, 72, 72, 67, 60, 44, 40, 32, 27, 28, 33, 41, 52, 64, 71), .Dim = as.integer(c(30, 2))) Using cor.test(ice[,1],ice[,2],method=spearman) I get (apart from a warning message due to ties) Spearman's rank correlation rho data: ice[, 1] and ice[, 2] S = 769.4403, p-value = 1.543e-08 alternative hypothesis: true rho is not equal to 0 sample estimates: rho 0.828823 I wonder what S is. I presume it is sum((rank(ice[,1])-rank(ice[,2]))^2), but this delivers 768.5. Is it the way ranks are computed in cor.test? Thank you in advance. D. Trenkler Looking at the code will help. Try stats:::cor.test.default This reveals that S is determined by: x - ice[, 1] y - ice[, 2] n - nrow(ice) r - cor(rank(x), rank(y)) S - (n^3 - n) * (1 - r)/6 S ## [1] 769.4403 See ?cor.test as to definition of S. HTH, --sundar __ 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] levels of factor when subsetting the factor
Yes. I do this periodically: dat.new - dat[1:6, ] dat.new[] - lapply(dat.new, function(x) if(is.factor(x)) factor(x) else x) HTH, --sundar Afshartous, David said the following on 9/12/2006 11:00 AM: thanks to all for the quick replies! if the factor is part of a dataframe, I can apply the subsetting to the entire dataframe, and then use drop=True to the factor separately and then put it back into the new dataframe (code below). is there a way to do this in a single step? dat -data.frame(fact = as.factor(c(rep(A, 3),rep(B, 3), rep(C, 3))),Y = rnorm(9)) dat.new = dat[1:6, ] dat.new$fact = dat$fact[1:6, drop = T] -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Peter Dalgaard Sent: Tuesday, September 12, 2006 11:45 AM To: Afshartous, David Cc: r-help@stat.math.ethz.ch Subject: Re: [R] levels of factor when subsetting the factor Afshartous, David [EMAIL PROTECTED] writes: All, When I take a subset of a factor the reduced factor still maintains all the original levels of the factor when say forming the key in a plot. The data is correct, but the variable still remembers the original levels. See below for reproducible code. Does anyone know how to fix this? cheers, dave fact = as.factor(c(rep(A, 3),rep(B, 3), rep(C, 3))) new.fact = fact[1:6] new.fact [1] A A A B B B Levels: A B C## should only show A B Just use factor(new.fact) [1] A A A B B B Levels: A B or fact[1:6, drop=T] [1] A A A B B B Levels: A B And, no, it is not a bug. The fact that a subsample happens to consist only of males does not turn gender into a one-level factor... (Apart from the philosophy, it makes a real difference in tabulation.) __ 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] Basic help needed: group bunch of lines in a list (matrix)
Emmanuel Levy said the following on 9/12/2006 3:50 PM: Hello, I'd like to group the lines of a matrix so that: A 1.0 200 A 3.0 800 A 2.0 200 B 0.5 20 B 0.9 50 C 5.0 70 Would give: A 2.0 400 B 0.7 35 C 5.0 70 So all lines corresponding to a letter (level), become a single line where all the values of each column are averaged. I've done that with a loop but it doesn't sound right (it is very slow). I imagine there is a sort of apply shortcut but I can't figure it out. Please note that it is not exactly a matrix I'm using, the function typeof tells me it's a list, however I access to it like it was a matrix. Could someone help me with the right function to use, a help topic or a piece of code? Thanks, Emmanuel __ 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. Try aggregate: aggregate(x[1], x[2:3], mean) where `x' is your data.frame. --sundar __ 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] exactly representable numbers
Robin Hankin said the following on 9/11/2006 3:52 AM: Hi Given a real number x, I want to know how accurately R can represent numbers near x. In particular, I want to know the infinum of exactly representable numbers greater than x, and the supremum of exactly representable numbers less than x. And then the interesting thing is the difference between these two. I have a little function that does some of this: f - function(x,FAC=1.1){ delta - x while(x+delta x){ delta - delta/FAC } return(delta*FAC) } But this can't be optimal. Is there a better way? I believe this is what .Machine$double.eps is. From ?.Machine double.eps: the smallest positive floating-point number 'x' such that '1 + x != 1'. It equals 'base^ulp.digits' if either 'base' is 2 or 'rounding' is 0; otherwise, it is '(base^ulp.digits) / 2'. See also .Machine$double.neg.eps. Is this what you need? --sundar __ 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] legend problems in lattice
Ernst O Ahlberg Helgee wrote: Hi! Im sorry to bother you but I cant fix this. I use the lattice function levelplot and I want the colorkey at the bottom, how do I get it there? I have tried changing colorkey.space and changing in legend but I cant get it right, plz help btw I'd like to speceify strings to appear at the tick marks and also there I fail any thoughts? cheers Ernst __ 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. Hi, Ernst, Please read ?levelplot. Under the argument for colorkey you will see: colorkey: logical specifying whether a color key is to be drawn alongside the plot, or a list describing the color key. The list may contain the following components: 'space': location of the colorkey, can be one of 'left', 'right', 'top' and 'bottom'. Defaults to 'right'. So the answer to your first question is: levelplot(..., colorkey = list(space = bottom)) For your second question, use the scale argument. See ?xyplot for details. For example, levelplot(..., scale = list(x = list(at = 1:4, labels = letters[1:4]))) HTH, --sundar __ 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] Extracting column name in apply/lapply
Nick Desilsky wrote: Hi, any good trick to get the column names for title() aside from running lapply on the column indexes? Thanks Nick. apply(X[,numCols],2,function(x){ nunqs - length(unique(x)) nnans - sum(is.na(x)) info - paste(uniques:,nunqs,(,nunqs/n,),NAs:,nnans,(,nnans/n,)) hist(x,xlab=info) # -- title(???) }) - [[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. This is where a for loop is much more useful (and readable): for(i in numCols) { nunqs - length(unique(X[, i])) nnans - sum(is.na(X[, i])) ## `n' is missing from this example info - paste(uniques:,nunqs,(,nunqs/n,),NAs:,nnans,(,nnans/n,)) hist(X[, i],xlab=info) title(colnames(X)[i]) } HTH, --sundar __ 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] generating an expression for a formula automatically
Maria Montez wrote: Hi! I would like to be able to create formulas automatically. For example, I want to be able to create a function that takes on two values: resp and x, and then creates the proper formula to regress resp on x. My code: fit.main - function(resp,x) { form - expression(paste(resp, ~ ,paste(x,sep=,collapse= + ),sep=)) z - lm(eval(form)) z } main - fit.main(y,c(x1,x2,x3,x4)) and I get this error: Error in terms.default(formula, data = data) : no terms component Any suggestions? Thanks, Maria __ 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. Hi, Maria, Try regr - paste(x, collapse = +) form - as.formula(sprintf(%s ~ %s, resp, regr)) HTH, --sundar __ 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] fitting truncated normal distribution
Hi, Markus, One other suggestion is to add the lower argument to fitdistr: fitdistr(x, dtnorm0, start = list(mean = 0, sd = 1), lower = 0) where dtnorm0 is defined as before. This indicates to fitdistr that the optimization should be constrained. See ?optim for details. --sundar Schweitzer, Markus wrote: Thank you Sundar, Yes, always integers. By demand data I meant the amount of ordered products in a certain period. Therefore, x is a vector of periods (i.e. Weeks in a year) In my example we could see an article, that has only been ordered in two weeks within one year. All the zeros show, that nobody has ordered the items in these periods. (First half of the year/first 24 weeks) Since the orders cannot be negative, some literature recommended to use a truncated normal distribution (Poisson and negative binomial are also recommended). My x is just a sample out of the dataset. There might be other time series with better attributes for a truncated normal distribution. My problem is simply, that I only get an error message when I use fitdistr. Error in [-(`*tmp*`, x = lower x = upper, value = numeric(0)) nothing to replace. I hope, there is a way fitdistr can also compute difficult data. Best regards, markus -Original Message- From: Sundar Dorai-Raj [mailto:[EMAIL PROTECTED] Sent: Donnerstag, 17. August 2006 16:47 To: Schweitzer, Markus Cc: r-help@stat.math.ethz.ch Subject: Re: [R] fitting truncated normal distribution Hi, Markus, Are these always integers? Why do you think they should be normal or Weibull? Seems more like a mixture with a point mass at 0 and something else (e.g. Poisson, negative binomial, normal). Though it's hard to tell with what you have provided. If that's the case you'll have to write your own likelihood function or, if they are integers, use zip (zero-inflated Poisson) or zinb (zero-inflated negative binomial). Do an RSiteSearch to find many packages will do these fits. RSiteSearch(zero-inflated) Again, this is pure speculation based on your x below alone and no other information (I'm not sure what demand-data means). HTH, --sundar Schweitzer, Markus wrote: Sorry, that I forgot an example. I have demand-data which is either 0 or a positive value. When I have an article which is not ordered very often, it could look like this: x=c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1280,0,0,0,0,640,0 ,0 ,0,0,0,0,0,0,0) library(MASS) ## for fitdistr library(msm) ## for dtnorm dtnorm0 - function(x, mean = 0, sd = 1, log = FALSE) { dtnorm(x, mean, sd, 0, Inf, log) } fitdistr(x,dtnorm0,start=list(mean=0,sd=1)) Unfortunately I get the same error message. I found a function, that works for a weibull distribution and tried to apply it but it didn't work neither # truncated weibull distribution #dweibull.trunc - #function(x, shape, scale=1, trunc.=Inf, log=FALSE){ #ln.dens - (dweibull(x, shape, scale, log=TRUE) #-pweibull(trunc., shape, scale = 1, lower.tail = TRUE, log.p = #TRUE)) #if(any(oops - (xtrunc.))) #ln.dens[oops] - (-Inf) #if(log)ln.dens else exp(ln.dens) #} # #x - rweibull(100, 1) #range(x) #x4 - x[x=4] #fitdistr(x4, dweibull.trunc, start=list(shape=1, scale=1), trunc=4) ## ## # truncated normal distribution dtnorm0 - function(x, mean, sd, a=0, log = FALSE) { ln.dens - (dnorm(x, mean, sd) - pnorm(a, mean, sd, lower.tail=TRUE, log.p =TRUE)) if(any(oops - (xa))) ln.dens[oops] - (-Inf) if(log)ln.dens else exp(ln.dens) } fitdistr(x, dtnorm0, start = list(mean = 0, sd = 1)) Maybe, when I alter mean and sd, I get an answer, which is not really satisfactory. I hope, there is a solution possible And thank you in advance markus Sorry, didn't notice that you *did* mention dtnorm is part of msm. Ignore that part of the advice... --sundar Sundar Dorai-Raj wrote: [EMAIL PROTECTED] wrote: Hello, I am a new user of R and found the function dtnorm() in the package msm. My problem now is, that it is not possible for me to get the mean and sd out of a sample when I want a left-truncated normal distribution starting at 0. fitdistr(x,dtnorm, start=list(mean=0, sd=1)) returns the error message Fehler in [-(`*tmp*`, x = lower x = upper, value = numeric(0)) :nichts zu ersetzen I don't know, where to enter the lower/upper value. Is there a possibility to program the dtnorm function by myself? Thank you very much in advance for your help, markus --- Versendet durch aonWebmail (webmail.aon.at) __ 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
Re: [R] fitting truncated normal distribution
Hi, Markus, Are these always integers? Why do you think they should be normal or Weibull? Seems more like a mixture with a point mass at 0 and something else (e.g. Poisson, negative binomial, normal). Though it's hard to tell with what you have provided. If that's the case you'll have to write your own likelihood function or, if they are integers, use zip (zero-inflated Poisson) or zinb (zero-inflated negative binomial). Do an RSiteSearch to find many packages will do these fits. RSiteSearch(zero-inflated) Again, this is pure speculation based on your x below alone and no other information (I'm not sure what demand-data means). HTH, --sundar Schweitzer, Markus wrote: Sorry, that I forgot an example. I have demand-data which is either 0 or a positive value. When I have an article which is not ordered very often, it could look like this: x=c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1280,0,0,0,0,640,0,0 ,0,0,0,0,0,0,0) library(MASS) ## for fitdistr library(msm) ## for dtnorm dtnorm0 - function(x, mean = 0, sd = 1, log = FALSE) { dtnorm(x, mean, sd, 0, Inf, log) } fitdistr(x,dtnorm0,start=list(mean=0,sd=1)) Unfortunately I get the same error message. I found a function, that works for a weibull distribution and tried to apply it but it didn't work neither # truncated weibull distribution #dweibull.trunc - #function(x, shape, scale=1, trunc.=Inf, log=FALSE){ #ln.dens - (dweibull(x, shape, scale, log=TRUE) #-pweibull(trunc., shape, scale = 1, lower.tail = TRUE, log.p = #TRUE)) #if(any(oops - (xtrunc.))) #ln.dens[oops] - (-Inf) #if(log)ln.dens else exp(ln.dens) #} # #x - rweibull(100, 1) #range(x) #x4 - x[x=4] #fitdistr(x4, dweibull.trunc, start=list(shape=1, scale=1), trunc=4) # truncated normal distribution dtnorm0 - function(x, mean, sd, a=0, log = FALSE) { ln.dens - (dnorm(x, mean, sd) - pnorm(a, mean, sd, lower.tail=TRUE, log.p =TRUE)) if(any(oops - (xa))) ln.dens[oops] - (-Inf) if(log)ln.dens else exp(ln.dens) } fitdistr(x, dtnorm0, start = list(mean = 0, sd = 1)) Maybe, when I alter mean and sd, I get an answer, which is not really satisfactory. I hope, there is a solution possible And thank you in advance markus Sorry, didn't notice that you *did* mention dtnorm is part of msm. Ignore that part of the advice... --sundar Sundar Dorai-Raj wrote: [EMAIL PROTECTED] wrote: Hello, I am a new user of R and found the function dtnorm() in the package msm. My problem now is, that it is not possible for me to get the mean and sd out of a sample when I want a left-truncated normal distribution starting at 0. fitdistr(x,dtnorm, start=list(mean=0, sd=1)) returns the error message Fehler in [-(`*tmp*`, x = lower x = upper, value = numeric(0)) :nichts zu ersetzen I don't know, where to enter the lower/upper value. Is there a possibility to program the dtnorm function by myself? Thank you very much in advance for your help, markus --- Versendet durch aonWebmail (webmail.aon.at) __ 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. Hi, Markus, You should always supply the package name where dtnorm is located. My guess is most don't know (as I didn't) it is part of the msm package. Also, you should supply a reproducible example so others may understand your particular problem. For example, when I ran your code on data generated from rtnorm (also part of msm) I got warnings related to the NaNs generated in pnorm and qnorm, but no error as you reported. Both of these suggestions are in the posting guide (see signature above). So, to answer your problem, here's a quick example. library(MASS) ## for fitdistr library(msm) ## for dtnorm dtnorm0 - function(x, mean = 0, sd = 1, log = FALSE) { dtnorm(x, mean, sd, 0, Inf, log) } set.seed(1) ## to others may reproduce my results exactly x - rtnorm(100, lower = 0) fitdistr(x, dtnorm0, start = list(mean = 0, sd = 1)) Note, the help page ?fitdistr suggests additional parameters may be passed to the density function (i.e. dtnorm) or optim. However, this won't work here because lower is an argument for both functions. This is the reason for writing dtnorm0 which has neither a lower or an upper argument. HTH, --sundar __ 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] fitting truncated normal distribution
[EMAIL PROTECTED] wrote: Hello, I am a new user of R and found the function dtnorm() in the package msm. My problem now is, that it is not possible for me to get the mean and sd out of a sample when I want a left-truncated normal distribution starting at 0. fitdistr(x,dtnorm, start=list(mean=0, sd=1)) returns the error message Fehler in [-(`*tmp*`, x = lower x = upper, value = numeric(0)) : nichts zu ersetzen I don't know, where to enter the lower/upper value. Is there a possibility to program the dtnorm function by myself? Thank you very much in advance for your help, markus --- Versendet durch aonWebmail (webmail.aon.at) __ 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. Hi, Markus, You should always supply the package name where dtnorm is located. My guess is most don't know (as I didn't) it is part of the msm package. Also, you should supply a reproducible example so others may understand your particular problem. For example, when I ran your code on data generated from rtnorm (also part of msm) I got warnings related to the NaNs generated in pnorm and qnorm, but no error as you reported. Both of these suggestions are in the posting guide (see signature above). So, to answer your problem, here's a quick example. library(MASS) ## for fitdistr library(msm) ## for dtnorm dtnorm0 - function(x, mean = 0, sd = 1, log = FALSE) { dtnorm(x, mean, sd, 0, Inf, log) } set.seed(1) ## to others may reproduce my results exactly x - rtnorm(100, lower = 0) fitdistr(x, dtnorm0, start = list(mean = 0, sd = 1)) Note, the help page ?fitdistr suggests additional parameters may be passed to the density function (i.e. dtnorm) or optim. However, this won't work here because lower is an argument for both functions. This is the reason for writing dtnorm0 which has neither a lower or an upper argument. HTH, --sundar __ 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] fitting truncated normal distribution
Sorry, didn't notice that you *did* mention dtnorm is part of msm. Ignore that part of the advice... --sundar Sundar Dorai-Raj wrote: [EMAIL PROTECTED] wrote: Hello, I am a new user of R and found the function dtnorm() in the package msm. My problem now is, that it is not possible for me to get the mean and sd out of a sample when I want a left-truncated normal distribution starting at 0. fitdistr(x,dtnorm, start=list(mean=0, sd=1)) returns the error message Fehler in [-(`*tmp*`, x = lower x = upper, value = numeric(0)) : nichts zu ersetzen I don't know, where to enter the lower/upper value. Is there a possibility to program the dtnorm function by myself? Thank you very much in advance for your help, markus --- Versendet durch aonWebmail (webmail.aon.at) __ 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. Hi, Markus, You should always supply the package name where dtnorm is located. My guess is most don't know (as I didn't) it is part of the msm package. Also, you should supply a reproducible example so others may understand your particular problem. For example, when I ran your code on data generated from rtnorm (also part of msm) I got warnings related to the NaNs generated in pnorm and qnorm, but no error as you reported. Both of these suggestions are in the posting guide (see signature above). So, to answer your problem, here's a quick example. library(MASS) ## for fitdistr library(msm) ## for dtnorm dtnorm0 - function(x, mean = 0, sd = 1, log = FALSE) { dtnorm(x, mean, sd, 0, Inf, log) } set.seed(1) ## to others may reproduce my results exactly x - rtnorm(100, lower = 0) fitdistr(x, dtnorm0, start = list(mean = 0, sd = 1)) Note, the help page ?fitdistr suggests additional parameters may be passed to the density function (i.e. dtnorm) or optim. However, this won't work here because lower is an argument for both functions. This is the reason for writing dtnorm0 which has neither a lower or an upper argument. HTH, --sundar __ 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] Doubt about Student t distribution simulation
Hi, Jose/John, Here's an example to help Jose and highlights John's advice. Also includes set.seed which should be included in all simulations posted to R-help. set.seed(42) mu - 10 sigma - 5 n - 3 nsim - 1 m - matrix(rnorm(n * nsim, mu, sigma), nsim, n) t - apply(m, 1, function(x) (mean(x) - mu)/(sd(x)/sqrt(n))) library(lattice) qqmath(t, distribution = function(x) qt(x, n - 1), panel = function(x, ...) { panel.qqmath(x, col = darkblue, ...) panel.qqmathline(x, col = darkred, ...) }) With n = 3, expect a few outliers. --sundar John Fox wrote: Dear Jose, The problem is that you're using the population standard deviation (sigma) rather than the sample SD of each sample [i.e., t[i] = (mean(amo.i) - mu) / (sd(amo.i) / sqrt(n)) ], so your values should be normally distributed, as they appear to be. A couple of smaller points: (1) Even after this correction, you're sampling from a discrete population (albeit with replacement) and so the values won't be exactly t-distributed. You could draw the samples directly from N(mu, sigma) instead. (2) It would be preferable to make a quantile-comparison plot against the t-distribution, since you'd get a better picture of what's going on in the tails. I hope this helps, John John Fox Department of Sociology McMaster University Hamilton, Ontario Canada L8S 4M4 905-525-9140x23604 http://socserv.mcmaster.ca/jfox -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jose Claudio Faria Sent: Friday, August 04, 2006 3:09 PM To: R-help@stat.math.ethz.ch Subject: [R] Doubt about Student t distribution simulation Dear R list, I would like to illustrate the origin of the Student t distribution using R. So, if (sample.mean - pop.mean) / standard.error(sample.mean) has t distribution with (sample.size - 1) degree free, what is wrong with the simulation below? I think that the theoretical curve should agree with the relative frequencies of the t values calculated: #== begin options= # parameters mu= 10 sigma = 5 # size of sample n = 3 # repetitions nsim = 1 # histogram parameter nchist = 150 #== end options=== t = numeric() pop = rnorm(1, mean = mu, sd = sigma) for (i in 1:nsim) { amo.i = sample(pop, n, replace = TRUE) t[i] = (mean(amo.i) - mu) / (sigma / sqrt(n)) } win.graph(w = 5, h = 7) split.screen(c(2,1)) screen(1) hist(t, main = histogram, breaks = nchist, col = lightgray, xlab = '', ylab = Fi, font.lab = 2, font = 2) screen(2) hist(t, probability = T, main= 'f.d.p and histogram', breaks = nchist, col = 'lightgray', xlab= 't', ylab = 'f(t)', font.lab= 2, font = 2) x = t curve(dt(x, df = n-1), add = T, col = red, lwd = 2) Many thanks for any help, ___ Jose Claudio Faria Brasil/Bahia/Ilheus/UESC/DCET EstatÃstica Experimental/Prof. Adjunto mails: [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-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] deleting a directory
Hi, all, I'm looking a utility for removing a directory from within R. Currently, I'm using: foo - function(...) { mydir - tempdir() dir.create(mydir, showWarnings = FALSE, recursive = TRUE) on.exit(system(sprintf(rm -rf %s, mydir))) ## do some stuff in mydir invisible() } However, this is assumes rm is available. I know of ?dir.create, but there is no opposite. And ?file.remove appears to work only on files and not directories. Any advice? Or is my current approach the only solution? R.version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 3.1 year 2006 month 06 day01 svn rev38247 language R version.string Version 2.3.1 (2006-06-01) Thanks, --sundar __ 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] deleting a directory
Please ignore. I forgot ?unlink had a recursive argument. Thanks. --sundar Sundar Dorai-Raj wrote: Hi, all, I'm looking a utility for removing a directory from within R. Currently, I'm using: foo - function(...) { mydir - tempdir() dir.create(mydir, showWarnings = FALSE, recursive = TRUE) on.exit(system(sprintf(rm -rf %s, mydir))) ## do some stuff in mydir invisible() } However, this is assumes rm is available. I know of ?dir.create, but there is no opposite. And ?file.remove appears to work only on files and not directories. Any advice? Or is my current approach the only solution? R.version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 3.1 year 2006 month 06 day01 svn rev38247 language R version.string Version 2.3.1 (2006-06-01) Thanks, --sundar __ 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] Sweave error in example code
LL wrote: Hi.. I am running R version 2.3.1 on a Windows XP machine with the latest Miktex 2.5 installed. I get no errors from R when running the Sweave example, testfile - system.file(Sweave, Sweave-test-1.Rnw, package = utils) However, when I tex the resulting .tex file (after installing a4.sty) I get the error below. This is pdfeTeX, Version 3.141592-1.30.6-2.2 (MiKTeX 2.5 RC 1) entering extended mode (Sweave-test-1.tex LaTeX2e 2005/12/01 Babel v3.8g and hyphenation patterns for english, dumylang, nohyphenation, ge rman, ngerman, french, loaded. (C:\Program Files\MiKTeX 2.5\tex\latex\base\article.cls Document Class: article 2005/09/16 v1.4f Standard LaTeX document class (C:\Program Files\MiKTeX 2.5\tex\latex\base\size10.clo)) (C:\Program Files\MiKTeX 2.5\tex\latex\ltxmisc\a4wide.sty (C:\Program Files\MiKTeX 2.5\tex\latex\ntgclass\a4.sty)) ! Missing \endcsname inserted. to be read again \protect l.11 \begin {document} ? [[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. This works for me. However, when I ran this, MiKTeX prompted me to install the ntgclass package, which I did. Everything ran smoothly after that. I'm using R-2.3.1 with MiKTeX 2.4 in WinXP Pro. HTH, --sundar __ 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] scatter plot with axes drawn on the same scale
Try: plot(x, y, asp = 1) --sundar bogdan romocea wrote: Dear useRs, I'd like to produce some scatter plots where N units on the X axis are equal to N units on the Y axis (as measured with a ruler, on screen or paper). This approach x - sample(10:200,40) ; y - sample(20:100,40) windows(width=max(x),height=max(y)) plot(x,y) is better than plot(x,y) but doesn't solve the problem because of the other parameters (margins etc). Is there an easy, official way of sizing the axes to the same scale, one that would also work with multiple scatter plots being sent to the same pdf() - plus perhaps layout() or par(mfrow())? Thank you, b. __ 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] intersect of list elements
Georg Otto wrote: Hi, i have a list of several vectors, for example: vectorlist $vector.a.1 [1] a b c $vector.a.2 [1] a b d $vector.b.1 [1] e f g I can use intersect to find elements that appear in $vector.a.1 and $vector.a.2: intersect(vectorlist[[1]], vectorlist[[2]]) [1] a b I would like to use grep to get the vectors by their names matching an expression and to find the intersects between those vectors. For the first step: vectorlist[grep (vector.a, names(vectorlist))] $vector.a.1 [1] a b c $vector.a.2 [1] a b d Unfortunately, I can not pass the two vectors as argument to intersect: intersect(vectorlist[grep (vector.a, names(vectorlist))]) Error in unique(y[match(x, y, 0)]) : argument y is missing, with no default I am running R Version 2.3.1 (2006-06-01) Could somone help me to solve this? Cheers, Georg __ 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. Will this work for you? vectorlist - list(vector.a.1 = c(a, b, c), vector.a.2 = c(a, b, d), vector.b.1 = c(e, f, g)) intersect2 - function(...) { args - list(...) nargs - length(args) if(nargs = 1) { if(nargs == 1 is.list(args[[1]])) { do.call(intersect2, args[[1]]) } else { stop(cannot evaluate intersection fewer than 2 arguments) } } else if(nargs == 2) { intersect(args[[1]], args[[2]]) } else { intersect(args[[1]], intersect2(args[-1])) } } vector.a - vectorlist[grep (vector.a, names(vectorlist))] intersect2(vector.a) intersect2(vectorlist) HTH, --sundar __ 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] throwaway() function
John Wiedenhoeft wrote: Dear all, I apologize if this is a FAQ (seems a bit like one, but I didn't find anything). I'm looking for an easy way to cut one value out of a vector and shorten the vector accordingly. Something like: x - c(1, 1, 0, 6, 2) throwaway(x[3]) which will return x = 1 1 6 2, with length(x) = 4. I know one could do this by hand, but then one would have to create a second vector y in a loop which has to be 1 shorter then x and then assign x - y, as there is no anti-c() function which shortens a vector (at least to my knowledge). Is there some kind of a throwaway() function in R? Best regards, John __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Use indexing (explained in R-intro) x - x[-3] ## drops the third element x - x[-c(1, 3)] ## drops the first and third element HTH, --sundar __ 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] Sweave and multipage lattice
Dieter Menne wrote: Dear R-Listeners, as the Sweave faq says: http://www.ci.tuwien.ac.at/~leisch/Sweave/FAQ.html creating several figures from one figure chunk does not work, and for standard graphics, a workaround is given. Now I have a multipage trellis plot with an a-priori unknown number of pages, and I don't see an elegant way of dividing it up into multiple pdf-files. I noted there is a page event handler in the ... parameters, which would provide a handle to open/close the file. Any good idea would be appreciated. Dieter Hi, Dieter, I haven't seen a reply to this and I don't know Sweave. However, will the following example work? It does require you know the layout for one page. --sundar library(lattice) trellis.device(postscript, file = barley%02d.eps, width = 5, height = 3, onefile = FALSE, paper = special) ## from ?xyplot dotplot(variety ~ yield | site, data = barley, groups = year, key = simpleKey(levels(barley$year), space = right), xlab = Barley Yield (bushels/acre) , aspect=0.5, layout = c(1, 1), ylab=NULL) dev.off() files - list.files(pattern = glob2rx(barley*.eps)) for(file in files) cat(\\includegraphics{, file, }\n\n, sep=) __ 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] Wrap a loop inside a function
Doran, Harold wrote: I need to wrap a loop inside a function and am having a small bit of difficulty getting the results I need. Below is a replicable example. # define functions pcm - function(theta,d,score){ exp(rowSums(outer(theta,d[1:score],'-')))/ apply(exp(apply(outer(theta,d, '-'), 1, cumsum)), 2, sum) } foo - function(theta,items, score){ like.mat - matrix(numeric(length(items) * length(theta)), ncol = length(theta)) for(i in 1:length(items)) like.mat[i, ] - pcm(theta, items[[i]], score[[i]]) } # begin example theta - c(-1,-.5,0,.5,1) items - list(item1 = c(0,1,2), item2 = c(0,1), item3 = c(0,1,2,3,4), item4 = c(0,1)) score - c(2,1,3,1) (foo(theta, items, score)) # R output from function foo [1] 0.8807971 0.8175745 0.7310586 0.6224593 0.500 However, what I am expecting from the function foo is like.mat [,1] [,2] [,3] [,4] [,5] [1,] 0.118499655 0.17973411 0.25949646 0.34820743 0.4223188 [2,] 0.880797078 0.81757448 0.73105858 0.62245933 0.500 [3,] 0.005899109 0.01474683 0.03505661 0.07718843 0.1520072 [4,] 0.880797078 0.81757448 0.73105858 0.62245933 0.500 I cannot seem to track down why the function foo is only keeping the last row of the full matrix I need. Can anyone see where my error is? Thanks, Harold platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 3.0 year 2006 month 04 day24 svn rev37909 language R version.string Version 2.3.0 (2006-04-24) [[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. Hi, Harold, Your function foo is only returning the last call from for. Try: foo - function(theta,items, score){ like.mat - matrix(numeric(length(items) * length(theta)), ncol = length(theta)) for(i in 1:length(items)) like.mat[i, ] - pcm(theta, items[[i]], score[[i]]) ## return like.mat, not just the last line from for like.mat } HTH, --sundar __ 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] RODBC, missing values, and Excel
Hi, Gabor, Thanks for the code. When I tried this I get an error when trying to use a relative path name: read.excel - function(file, sheet, ...) { require(rcom) require(gdata) oxl - comCreateObject('Excel.Application') comSetProperty(oxl, Visible, TRUE) # this line optional owb - comGetProperty(oxl, Workbooks) ob - comInvoke(owb, Open, file) osheets - comGetProperty(ob, Worksheets) n - comGetProperty(osheets, Count) ithSheetName - function(i) comGetProperty(comGetProperty(osheets, Item, i), Name) sheetNames - sapply(1:n, ithSheetName) comInvoke(oxl, Quit) read.xls(file, match(sheet, sheetNames), ...) } read.excel(tmp.xls, Sheet2, na.strings = na) Error in 1:n : NA/NaN argument read.excel(D:/Users/sundard/frm/config/R/tmp.xls, +Sheet2, na.strings = na) x 1 0.11 2 0.11 3 NA 4 NA 5 NA 6 NA 7 0.11 Any reason I need an absolute path? Thanks again, --sundar Gabor Grothendieck wrote: In thinking about this some more I have a better idea. Use rcom (or RDCOMClient) to get a list of the sheet names and then use that to determine which sheet you need. Then use read.xls to get it like this assuming that the Excel file and path are C:\test.xls and that one of the sheets in that spreadsheet is xyz. In my version the na.strings had a space at the end so you may need to change the na.strings= setting: library(rcom) xls - C:\\test.xls oxl - comCreateObject('Excel.Application') comSetProperty(oxl, Visible, TRUE) # this line optional owb - comGetProperty(oxl, Workbooks) ob - comInvoke(owb, Open, xls) osheets - comGetProperty(ob, Worksheets) n - comGetProperty(osheets, Count) ithSheetName - function(i) comGetProperty(comGetProperty(osheets, Item, i), Name) sheetNames - sapply(1:n, ithSheetName) comInvoke(oxl, Quit) library(gdata) read.xls(xls, match(xyz, sheetNames), na.strings = na ) On 7/12/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Would it be good enough to just read all the sheets in? The perl program can do that and although the read.xls R function does not interface to that aspect of its functionality its not that difficult to access it yourself. Assume your excel file is in \test.xls . Just switch to that folder. paste together a command to run the perl program, run it, get a list of the file names it produced and read them in: library(gdata) setwd(/) cmd - paste(perl, system.file(perl/xls2csv.pl, package = gdata), test) system(cmd) ff - list.files(patt = test_Sheet.*.csv) sapply(ff, read.csv, na.strings = na , simplify = FALSE) On 7/12/06, Sundar Dorai-Raj [EMAIL PROTECTED] wrote: Hi, Gabor, Thanks for the reply. Perhaps Prof. Ripley will enlighten us as he is the RODBC maintainer. Unfortunately, gdata::read.xls will not work for me (at least I don't think it will) because I need to refer to each worksheet by name and not by number. For example, I need extract data from Sheet1 and not simply the first sheet. Thanks, --sundar Gabor Grothendieck wrote: I also got a strange result too (I renamed it sdr.read.xls to distinguish it from read.xls in gdata and noticed that a space got into my na's somehow so I used na for my na.strings: sdr.read.xls(/test.xls, Sheet2, na.strings = na ) x 1 NA 2 NA 3 na 4 na 5 na 6 na 7 NA I had more success using read.xls in the gdata package. Note that we need to install perl first if not already present: library(gdata) # for read.xls read.xls(/test.xls, 2, na.strings = na ) x 1 0.11 2 0.11 3 NA 4 NA 5 NA 6 NA 7 0.11 R.version.string # XP [1] Version 2.3.1 Patched (2006-06-04 r38279) packageDescription(gdata)$Version [1] 2.1.2 packageDescription(RODBC)$Version [1] 1.1-7 On 7/12/06, Sundar Dorai-Raj [EMAIL PROTECTED] wrote: Hi, all, I'm trying to use RODBC to read data from Excel. However, I'm having trouble converting missing values to NA and rather perplexed by the output. Below illustrates my problem: ## DATA - copy to Excel and save as tmp.xls ## tmp.xls!Sheet1 x 0.11 0.11 na na na 0.11 ## tmp.xls!Sheet2 x 0.11 0.11 na na na na 0.11 ## R Code read.xls - function(file, sheet = Sheet1, ...) { require(RODBC) channel - odbcConnectExcel(file) sheet - sprintf(select * from `%s$`, sheet) x - sqlQuery(channel, sheet, ...) odbcClose(channel) x } read.xls(./tmp.xls, Sheet1, na.strings = na) ## works as expected # x #1 0.11 #2 0.11 #3 NA #4 NA #5 NA #6 0.11 read.xls(./tmp.xls, Sheet2, na.strings = na) ## Huh? What happened? # x #1 NA #2 NA #3 NA #4 NA #5 NA #6 NA #7 NA sessionInfo() Version 2.3.1 (2006-06-01) i386-pc-mingw32 attached base packages: [1] methods stats graphics grDevices utils datasets [7] base other attached packages: RODBC 1.1-7 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] RODBC, missing values, and Excel
Hi, all, I'm trying to use RODBC to read data from Excel. However, I'm having trouble converting missing values to NA and rather perplexed by the output. Below illustrates my problem: ## DATA - copy to Excel and save as tmp.xls ## tmp.xls!Sheet1 x 0.11 0.11 na na na 0.11 ## tmp.xls!Sheet2 x 0.11 0.11 na na na na 0.11 ## R Code read.xls - function(file, sheet = Sheet1, ...) { require(RODBC) channel - odbcConnectExcel(file) sheet - sprintf(select * from `%s$`, sheet) x - sqlQuery(channel, sheet, ...) odbcClose(channel) x } read.xls(./tmp.xls, Sheet1, na.strings = na) ## works as expected # x #1 0.11 #2 0.11 #3 NA #4 NA #5 NA #6 0.11 read.xls(./tmp.xls, Sheet2, na.strings = na) ## Huh? What happened? # x #1 NA #2 NA #3 NA #4 NA #5 NA #6 NA #7 NA sessionInfo() Version 2.3.1 (2006-06-01) i386-pc-mingw32 attached base packages: [1] methods stats graphics grDevices utils datasets [7] base other attached packages: RODBC 1.1-7 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] RODBC, missing values, and Excel
Hi, Gabor, Thanks for the reply. Perhaps Prof. Ripley will enlighten us as he is the RODBC maintainer. Unfortunately, gdata::read.xls will not work for me (at least I don't think it will) because I need to refer to each worksheet by name and not by number. For example, I need extract data from Sheet1 and not simply the first sheet. Thanks, --sundar Gabor Grothendieck wrote: I also got a strange result too (I renamed it sdr.read.xls to distinguish it from read.xls in gdata and noticed that a space got into my na's somehow so I used na for my na.strings: sdr.read.xls(/test.xls, Sheet2, na.strings = na ) x 1 NA 2 NA 3 na 4 na 5 na 6 na 7 NA I had more success using read.xls in the gdata package. Note that we need to install perl first if not already present: library(gdata) # for read.xls read.xls(/test.xls, 2, na.strings = na ) x 1 0.11 2 0.11 3 NA 4 NA 5 NA 6 NA 7 0.11 R.version.string # XP [1] Version 2.3.1 Patched (2006-06-04 r38279) packageDescription(gdata)$Version [1] 2.1.2 packageDescription(RODBC)$Version [1] 1.1-7 On 7/12/06, Sundar Dorai-Raj [EMAIL PROTECTED] wrote: Hi, all, I'm trying to use RODBC to read data from Excel. However, I'm having trouble converting missing values to NA and rather perplexed by the output. Below illustrates my problem: ## DATA - copy to Excel and save as tmp.xls ## tmp.xls!Sheet1 x 0.11 0.11 na na na 0.11 ## tmp.xls!Sheet2 x 0.11 0.11 na na na na 0.11 ## R Code read.xls - function(file, sheet = Sheet1, ...) { require(RODBC) channel - odbcConnectExcel(file) sheet - sprintf(select * from `%s$`, sheet) x - sqlQuery(channel, sheet, ...) odbcClose(channel) x } read.xls(./tmp.xls, Sheet1, na.strings = na) ## works as expected # x #1 0.11 #2 0.11 #3 NA #4 NA #5 NA #6 0.11 read.xls(./tmp.xls, Sheet2, na.strings = na) ## Huh? What happened? # x #1 NA #2 NA #3 NA #4 NA #5 NA #6 NA #7 NA sessionInfo() Version 2.3.1 (2006-06-01) i386-pc-mingw32 attached base packages: [1] methods stats graphics grDevices utils datasets [7] base other attached packages: RODBC 1.1-7 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] use of NULL environment is deprecated?
Patrick Connolly wrote: ] version _ platform x86_64-unknown-linux-gnu arch x86_64 os linux-gnu system x86_64, 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) I see in the NEWS file the line: o Use of NULL as an environment is deprecated and gives a warning. Which duly happens. I get warnings like this: Warning message: use of NULL environment is deprecated My problem is that I don't know what is being referred to. A little birdie tells me that in later versions of R, those warnings will become errors so I need to work out where they're coming from before I can use later versions. My question is: How does one work out which is being referred to by such a message? The traceback() function is useful when failure occurs. Is there an analagous way of looking into warnings? TIA Hi, Patrick, This will happen when you load a package that was created for an earlier version of R. If this is your own package, recreate the package using R-2.3.1. If it's a package on CRAN, then update.packages() should also do the trick. HTH, --sundar __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Colinearity Function in R
Peter Lauren wrote: Is there a colinearty function implemented in R? I have tried help.search(colinearity) and help.search(collinearity) and have searched for colinearity and collinearity on http://www.rpad.org/Rpad/Rpad-refcard.pdf but with no success. Many thanks in advance, Peter Lauren. Forgot one: RSiteSearch(collinearity) which returns (among others that may not be so helpful) http://finzi.psych.upenn.edu/R/library/perturb/html/00Index.html HTH, --sundar __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] i suspect that there a memory leak in vmmin?
Vumani Dlamini wrote: Dear listers, Am currently using MCMC approaches to estimate some parameters of my model. One parameter has to be updated using a tuned gamma distribution. So at each iteration I estimate the mean and variance of the density of the gamma approximation using vmmin (i also supply the gradient argument). For moderate replications the procedure works, but if I increase them R crashes. If instead of the tuned gamma density i use the adaptive rejection sampling procedure by Gilks and Wild (downloaded from their website) the procedure returns the results for any number of replications, thus I suspected that there was a memory leak in vmmin. I am not an expert in C and am only a windows user. Have tried some of the debugging tools available to us windows users: gdb, mpatrol, duma without success. Am not sure whether this is a bug. Version 2.3.1 (2006-06-01) Windows XP Regards, Vumani Rgui.exe caused an Access Violation at location 100dec2f in module R.dll Reading from location 3ff7c27d. Registers: eax=63ac ebx=01e773a0 ecx=3ff7c27a edx=0002 esi=01e254b4 edi=0002 eip=100dec2f esp=00e0ecb0 ebp=00e0ed78 iopl=0 nv up ei pl nz na pe nc cs=001b ss=0023 ds=0023 es=0023 fs=003b gs= efl=0202 Call stack: 100DEC2F R.dll:100DEC2F SET_TAG 100E0527 R.dll:100E0527 Rf_allocVector 100E0D37 R.dll:100E0D37 R_alloc 100F2ACA R.dll:100F2ACA vmmin 023F5E96 gem.dll:023F5E96 weibullMH 10088C33 R.dll:10088C33 do_dotcall 100B8827 R.dll:100B8827 Rf_eval 100BA4D2 R.dll:100BA4D2 do_set 100B86CB R.dll:100B86CB Rf_eval 100BA5D5 R.dll:100BA5D5 do_begin 100B86CB R.dll:100B86CB Rf_eval 100BB8EB R.dll:100BB8EB Rf_applyClosure 100B85F8 R.dll:100B85F8 Rf_eval 100BA4D2 R.dll:100BA4D2 do_set 100B86CB R.dll:100B86CB Rf_eval 100DB51C R.dll:100DB51C Rf_ReplIteration 100DBAA6 R.dll:100DBAA6 run_Rmainloop 004013CF Rgui.exe:004013CF 00401316 Rgui.exe:00401316 00401518 Rgui.exe:00401518 00401236 Rgui.exe:00401236 00401288 Rgui.exe:00401288 7C816D4F kernel32.dll:7C816D4F RegisterWaitForInputIdle __ 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 It's not clear to my why you suspect vmmin (aka BFGS) rather than how you are using said function? Can you provide a re-producible example as the posting guide asks? Also, are you using optim in R? Or are you calling vmmin from C-code? Again, an example would clear up many of the questions you have asked. --sundar __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] numerical integration problem
przeszczepan wrote: Hi, I have got problems integrating the following function using integrate: lambdat-function(t){ tempT-T[k,][!is.na(T[k,])]#available values from k-th row of matrix T tempJ-J[k,][!is.na(J[k,])] hg-length(tempT[tempT=t tempJ==0])#counts observations satisfing the conditions ag-length(tempT[tempT=t tempJ==1]) lambdaXY[hg+1,ag+1]#takes values from a 10x10 matrix } I keep receiving this message: 1: longer object length is not a multiple of shorter object length in: tempT = t 2: longer object length is not a multiple of shorter object length in: tempT = t tempJ == 0 What I suspect is that the integrate function submits the whole vector of points at which the integral is to be evaluated at once. For my function to be integrated it would rather have to be evaluated at each point after another in a loop of some kind. You suspect correctly. Best to read ?integrate too. Can you think of a way to solve this problem without me having to write the integrating procedure from scratch (I have no idea about FORTRAN and this is what the integrate description refers to)? Just put a for-loop in your function to iterate over t. n - length(t) hg - ag - vector(numeric, n) for(i in seq(n)) { hg[i] - length(tempT[tempT = t[i] tempJ == 0]) ag[i] - length(tempT[tempT = t[i] tempJ == 1]) } I doubt this will work because integrate is expecting a vector of n=length(t) from lambdat. The last line of the function returns a nxn matrix. Please submit data to run the function plus your call to integrate in any subsequent postings. HTH, --sundar Thank you. Kind Regards, Lukasz Szczepanski Student __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to generate a figure using par( ) with some densityplot( )'s
Amir Safari wrote: Hi Dear R users, For a pair plotting, usaully we use par( ) function. Apparently it does not work anywhere. I want to have 3 plots in a single figure, like this: par(mfrow=c(3,1)) densityplot( a) densityplot(b) densityplot(c) But it does not work. How is it possible to have such a figure with densityplot( ) in a single figure? So many thanks for any help. Amir Safari Assuming you are talking about densityplot in lattice, then you are missing the point of lattice. You should try: library(lattice) set.seed(1) a - rnorm(100) b - rnorm(50) c - rnorm(75) densityplot(~a + b + c, outer = TRUE, layout = c(3, 1)) Set outer to FALSE to overlay the densities (this is the default behavior). You should remove the layout argument in that case, though. HTH, --sundar __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Finding a color code.
A Ezhil wrote: Hi, Is it possible to find corresponding color code in R for the following RGB (R185, G35 B80)? Thanks in advance. Best regards, Ezhil How about: x - c(185, 35, 80) class(x) - hexmode paste(#, paste(format(x), collapse = ), sep = ) [1] #b92350 I found this using help.search(hex) which led to ?format.hexmode. HTH, --sundar __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to generate a figure using par( ) with some densityplot( )'s
Deepayan Sarkar wrote: On 6/26/06, Sundar Dorai-Raj [EMAIL PROTECTED] wrote: Amir Safari wrote: Hi Dear R users, For a pair plotting, usaully we use par( ) function. Apparently it does not work anywhere. I want to have 3 plots in a single figure, like this: par(mfrow=c(3,1)) densityplot( a) densityplot(b) densityplot(c) But it does not work. How is it possible to have such a figure with densityplot( ) in a single figure? So many thanks for any help. Amir Safari Assuming you are talking about densityplot in lattice, then you are missing the point of lattice. You should try: library(lattice) set.seed(1) a - rnorm(100) b - rnorm(50) c - rnorm(75) densityplot(~a + b + c, outer = TRUE, layout = c(3, 1)) This only works if a, b and c are of the same length. The following should work though: densityplot(~data | which, data = make.groups(a, b, c)) -Deepayan Hi, Deepayan, My mistake. This is clear in ?densityplot. However, there is no warning if the condition is not met and, apparently, recycling rules are applied. Thanks, --sundar __ 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