Re: [R] changing number of axis
On Wed, Sep 16, 2009 at 2:02 PM, Dan Kortschak dan.kortsc...@adelaide.edu.au wrote: Hi, I trying to produce a bar chart describing hits to specific bins by chromosome for a large data set (I am asking here because experimentation with options is precluded due to this - generating the figure takes about an hour): barchart(hits~bin|chromosome, data=hits, horizontal=FALSE, origin=0, lab=c(3,10), layout=c(1,5,5), strip=strip.custom(style=3, bg=grey90, par.strip.text=list(cex=0.5)), as.table=TRUE); I have about 2500 bins for the largest factor and barchart is drawing tick labels for a substantial proportion of these (how many, I can't see since due to the density of the labels). Probably all 2500 of them. My question is how I can get a sane number of labels along the x axis (about 5-10 would be good). I suspect that 'scales' might be the way to go, but I can't see an obvious option to do this. Basically, barchart has to be convinced that the limits are numeric. There are various ways to do that; the simplest is to provide a numeric 'xlim', e.g., df - data.frame(y = runif(100), x = gl(100, 1)) barchart(y ~ x, df, origin = 0) barchart(y ~ x, df, origin = 0, xlim = c(0, 101)) However, you should also rethink the use of barchart for a 2500-level factor; at a minimum, consider something like xyplot(y ~ as.numeric(x), df, type = h) -Deepayan __ R-help@r-project.org 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] changing number of axis
Hi Deepayan, Thanks for that, I had a think (a few hour too late) and came to the same conclusion. I had wanted to have vertical bars for each of the data points, I have gone to a straight xyplot and this shows other intersting information - maybe I want to be able to do both point and bar plots (the bars show gaps in the bins nicely where the points don't). I'm thinking there is probably a better way to do it that what I was trying, a vertical line from y=0 to y=binvalue for each represented bin seem most sensible, but I'm not sure how to go about this. thanks Dan On Tue, 2009-09-29 at 22:59 -0700, Deepayan Sarkar wrote: On Wed, Sep 16, 2009 at 2:02 PM, Dan Kortschak dan.kortsc...@adelaide.edu.au wrote: Hi, I trying to produce a bar chart describing hits to specific bins by chromosome for a large data set (I am asking here because experimentation with options is precluded due to this - generating the figure takes about an hour): barchart(hits~bin|chromosome, data=hits, horizontal=FALSE, origin=0, lab=c(3,10), layout=c(1,5,5), strip=strip.custom(style=3, bg=grey90, par.strip.text=list(cex=0.5)), as.table=TRUE); I have about 2500 bins for the largest factor and barchart is drawing tick labels for a substantial proportion of these (how many, I can't see since due to the density of the labels). Probably all 2500 of them. My question is how I can get a sane number of labels along the x axis (about 5-10 would be good). I suspect that 'scales' might be the way to go, but I can't see an obvious option to do this. Basically, barchart has to be convinced that the limits are numeric. There are various ways to do that; the simplest is to provide a numeric 'xlim', e.g., df - data.frame(y = runif(100), x = gl(100, 1)) barchart(y ~ x, df, origin = 0) barchart(y ~ x, df, origin = 0, xlim = c(0, 101)) However, you should also rethink the use of barchart for a 2500-level factor; at a minimum, consider something like xyplot(y ~ as.numeric(x), df, type = h) -Deepayan __ R-help@r-project.org 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] Arial for pdf() on a Mac
On Tue, 29 Sep 2009, Steve Bellan wrote: Hi, I'd like to use Arial for the font in the PDF's and TIFF's I produce in R As ever, it is helpful to explain why you want to do something. First, because there may be better solutions to the larger problem, and secondly because the answer may involve the helper in a lot of work (as this one has), and you need to persaude them to be altruistic by establishing a good cause. on my Mac (running 10.5.5). I've found the following archived help file on how to do it in Linux (http://tolstoy.newcastle.edu.au/R/e4/help/08/08/19847.html) but That posting is about postscript(), and not about Linux per se. It was a brief reply to an inadequately researched question. What exact graphics device(s) are you talking about here? You seem to have read some information about pdf(), but that does not produce TIFFs, and tiff() has a Mac-specific backend. Indeed, TIFFs do not contain fonts, rather bitmap images of characters. For postscript this was somewhat moot: Arial and Helvetica are alleged to have the same font metrics (although each seems to have various implementations with different font metrics). See http://en.wikipedia.org/wiki/Helvetica which says Monotype's Arial, designed in 1982, while different from Helvetica in some few details, has identical character widths, and is indistinguishable by most non-specialists. and it can be simply a matter of getting the postscript/PDF viewer to use Arial rather than Helevetica character outlines. It is not helped by there being many versions of 'Arial' as well as of 'Helvetica'. don't understand how to do this on my system. Are *.afm files freely available No, font information on proprietary fonts is also proprietary. and do they come with the *.enc file that Type1Font() requires? The .enc files are for encodings, and whatever Arial you have is likely to be compatible with one of the supplied encodings. You only need to worry about which encoding if you are using non-ASCII text/symbols. if so where? Or do I convert some files I already have to *.afm? As the posting you quoted said, you convert some files you already have. I've searched around for useful info without much luck. And once I have the *.afm's an *.enc am I correct in assuming that I put them in the library/grDevices/afm directory and run the following in R: No, you give the full paths to where you put them (and .enc files do not go in the afm directory). Arial - Typ1Font(Arial, c(4-5 afm files here), encoding = enc file here) pdf(..., family=Arial) You also need to arrange to embed the fonts outlines, or for your PDF viewer to have access to them (and that's non-trivial, perhaps impossible). The basic issues here are 1) This is not a subject appropriate to R-help, and it has very little to do with R. What is to be done with the postscript/PDF produced is absolutely crucial: given the prevalence of font substitution in PDF viewers, it is very likely that Helvetica would be shown as Arial or v.v. 2) The differences between 'Arial' and 'Helvetica' are arcane. If 'Helvetica' really will not do, you need specialist typographical help. 3) 'Arial' is not a standard PDF font. If you have it on your system, then it is a system-specific question as to how to tell your chosen R graphics device and your graphics viewers about it. Since you are on a Mac, you have the option of using the quartz() family of devices, and as Arial *is* a Mac system font this is likely to be a far less painful route. But Mac-specific issues have an appropriate list, r-sig-mac, and you are far more likely to get help there. Thanks for your help, Steve Bellan MPH, Epidemiology PhD Candidate, Environmental Science, Policy Management University of California, Berkeley __ R-help@r-project.org 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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org 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] JRI - get S4 objects from R and assign them again
Hi, You should use this mailing list instead http://mailman.rz.uni-augsburg.de/mailman/listinfo/stats-rosuda-devel. ... where I just posted something that might help you. Romain On 09/28/2009 02:57 PM, ajoec...@gmx.de wrote: Hello, I am writing a Java frontend for a selfwritten R program using JRI. Because I am working with my own S4 classes almost all of my R functions return a S4 object. In the Java Program I now need to run a R function and its result should be assigned to a new R variable afterwards. I tried REngine.eval(), but the returned REXP was always null. I tried also the rni methods: long result = re.rniParse(readInDataAndPreprocess(removemarked,removeflagged,substract_background),1); System.out.println(Result: + result); long r=re.rniEval(result, 0); System.out.println(Result = +r+, building REXP); REXP x=new REXP(re, r); re.assign(resultReading, x); but the variable resultReading was not available in R afterwards. Has anyone of you an idea what I could do? Thanks in advance! Best, Anni -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/ztCu : RGG #158:161: examples of package IDPmisc |- http://tr.im/yw8E : New R package : sos `- http://tr.im/y8y0 : search the graph gallery from R __ R-help@r-project.org 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: How to display no box but only a y-axis on the left + Thicker lines
On Fri, Sep 18, 2009 at 6:06 AM, baptiste auguie baptiste.aug...@googlemail.com wrote: No box is easy, bwplot(y~x, data=data.frame(y=rnorm(10),x=sample(letters[1:3],10,repl=T)), par.settings=list(axis.line=list(col=NA))) but that seems to remove all axis lines and ticks as well. You may have to define a custom panel.axis() function. Yes. You can get back the tick marks with scaless$col: bwplot(y~x, data=data.frame(y=rnorm(10),x=sample(letters[1:3],10,repl=T)), par.settings=list(axis.line=list(col=NA)), scales = list(col = 1)) but lattice's default axis function doesn't draw the axis in the same way as base's axis(). -Deepayan An alternative is to use grid.remove() to remove the frame, bwplot(y~x, data=data.frame(y=rnorm(10),x=sample(letters[1:3],10,repl=T))) grid.remove(rect,grep=T,global=TRUE) HTH, baptiste 2009/9/18 lith minil...@gmail.com: 1.) How do I make lattice (e.g. barchart) to not draw a box but only a y-axis on the left hand side so that the plot looks like barplot with default settings? Does nobody have an idea? Or is the solution that obvious? __ R-help@r-project.org 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@r-project.org 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@r-project.org 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] changing number of axis
On Tue, Sep 29, 2009 at 11:09 PM, Dan Kortschak dan.kortsc...@adelaide.edu.au wrote: Hi Deepayan, Thanks for that, I had a think (a few hour too late) and came to the same conclusion. I had wanted to have vertical bars for each of the data points, I have gone to a straight xyplot and this shows other intersting information - maybe I want to be able to do both point and bar plots (the bars show gaps in the bins nicely where the points don't). Perhaps type = c(l, h) in xyplot. -Deepayan I'm thinking there is probably a better way to do it that what I was trying, a vertical line from y=0 to y=binvalue for each represented bin seem most sensible, but I'm not sure how to go about this. thanks Dan On Tue, 2009-09-29 at 22:59 -0700, Deepayan Sarkar wrote: On Wed, Sep 16, 2009 at 2:02 PM, Dan Kortschak dan.kortsc...@adelaide.edu.au wrote: Hi, I trying to produce a bar chart describing hits to specific bins by chromosome for a large data set (I am asking here because experimentation with options is precluded due to this - generating the figure takes about an hour): barchart(hits~bin|chromosome, data=hits, horizontal=FALSE, origin=0, lab=c(3,10), layout=c(1,5,5), strip=strip.custom(style=3, bg=grey90, par.strip.text=list(cex=0.5)), as.table=TRUE); I have about 2500 bins for the largest factor and barchart is drawing tick labels for a substantial proportion of these (how many, I can't see since due to the density of the labels). Probably all 2500 of them. My question is how I can get a sane number of labels along the x axis (about 5-10 would be good). I suspect that 'scales' might be the way to go, but I can't see an obvious option to do this. Basically, barchart has to be convinced that the limits are numeric. There are various ways to do that; the simplest is to provide a numeric 'xlim', e.g., df - data.frame(y = runif(100), x = gl(100, 1)) barchart(y ~ x, df, origin = 0) barchart(y ~ x, df, origin = 0, xlim = c(0, 101)) However, you should also rethink the use of barchart for a 2500-level factor; at a minimum, consider something like xyplot(y ~ as.numeric(x), df, type = h) -Deepayan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help with sub functions
On Tue, 29 Sep 2009, edche...@gmail.com wrote: I have chances to work with both linux based and win based R codes. And as you all know in linux, the file directories use / and win uses \\. Is there a function like sub or gsub that could substitute those slashes automatically? See ?chartr, and you can also use gsub(fixed = TRUE). But as both the R and rw FAQs tell you, your assertion about 'win' is incorrect for modern Windows: the Windows system functions accept either slash or backslash, as do all but a few badly-written Windows applications. A word of warning: the ASCII representation of \ is both a character in Windows DBCS encodings (used for CJK languages, it is rendered as the Yen symbol in most DBCS fonts) and a trail byte, and you need to be very careful with substitutions. We have had reports of both gsub and chartr mangling Chinese file names, although it is likely they were not in a Chinese locale and it was before many Unicode-related changes in R under Windows. Thanks! Edward Chen Email: tke...@msn.com Cell Phone: 510-371-4717 -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org 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 space between charts in lattice graphics
On Sat, Sep 19, 2009 at 9:42 AM, Larry White ljw1...@gmail.com wrote: Hi, I'm trying to create a lattice plot with three xyplots in one vertical column. I would like to reduce the vertical space between the charts. My code is below. There seems to be a between parameter for lattice.options, but I can't find any examples. Aside from the data setup, the code is below. Can anyone provide an example showing how to reduce the white space between the charts? Thanks. There are a bunch of *.padding settings that you can change to control spacing in lattice plots; e.g., see str(trellis.par.get(layout.heights)) But you are probably not using lattice as effectively as you might; consider this single call as an alternative: xyplot(total + bal + index ~ date, outer = TRUE, layout = c(1, 3), scales = list(y = free)) You'll need a bit more (a custom panel function) to get different color/pch in one panel. -Deepayan total_chart - xyplot(total ~ date, xlab=list(label=), ylab=list(label=Total Work) ) balance_chart - xyplot(bal ~ date, xlab=list(label=), ylab=list(label=Remaining Work) ) index_chart - xyplot(index ~ date, col=red, type=b, pch=15) print(total_chart, split=c(1,1,1,3), position=c(0, 0, 1, 1), newpage=FALSE, more=TRUE) print(balance_chart, split=c(1,2,1,3), position=c(0, 0, 1, 1), newpage=FALSE, more=TRUE) print(index_chart, split=c(1,3,1,3), position=c(0, 0, 1, 1), newpage=TRUE, more=FALSE) [[alternative HTML version deleted]] __ R-help@r-project.org 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@r-project.org 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] Probability of data values form DENSITY function
Lina, check ?density (and do so carefully). R uses a kernel estimate, by default Gaussian if I remember correctly. Values in a certain grid can be found from the code I sent earlier. I didn't check, but these are most likely just linearly interpolated by plot.density, and as the grid is sufficiently tight, it visually looks smooth. You could mimick this by linearly interpolating from the two closest neighbours for any new x values (or, as a rough approximation, choosing the density value of the nearest neighbour). I am not sure whether there are some specificities for time series in general or GARCH models in particular, that's not my area of expertise. Maybe there is some method for GARCH objects in the library you are using (you don't tell me which one). Try str(density(x)) from your original post to see whether you might have to adapt the proposed way to get these values. I copy the list in case someone can give more details on that. Two side remarks: * You should note that the density function in R takes a lot of parameters that might heavily influence the outcome, and even though R will propose some defaults that will work frequently, they might not be optimal or even appropriate for your particular situation, model, and data. * From your messages I fear that you have a limited understanding of the notion of density functions, at least for continuous distributions; they do NOT give the probability that a certain value is taken. Try plot(x-seq(-1,1,0.01), dnorm(x, sd=.25), type=l) to see that the density can easily exceed 1 and can hence not represent a probability. In fact, the theoretical probability that a specific value is actually taken from a continuous distribution is always equal to 0. I would strongly suggest to contact a local statistician to clarify these issues. HTH, Michael From: Lina Rusyte [mailto:liner...@yahoo.co.uk] Sent: Dienstag, 29. September 2009 18:03 To: Meyners,Michael,LAUSANNE,AppliedMathematics Subject: RE: [R] Probability of data values form DENSITY function Dear Mr. Michael Meyners, Assume, that I have simulated data from GARCH process: spec = garchSpec(model = list(omega = 0.01, alpha = 0.13, beta = 0.86, shape = 6), cond.dist = std) yt-garchSim(spec, n = 4000) The empirical distribution of this data (yt) is assumed to be not parametrized distribution). This data is my in-sample data. I have another set of the data (yt1), generated from the same process (but it is not the same as yt). I need to find the probabilities of these data (yt1) points in previously mentioned empiric distribution (of yt). Simply to say, having continuous EMPIRIC density function, I need for some points in x axis (values) to find out the corresponding values of y axis (their probability). R plots empiric density function, so I assume it approximates somehow the empirical density function. Thank a lot for the help in advance. Best regards, Lina --- On Tue, 29/9/09, Meyners,Michael, wrote: From: Meyners,Michael,LAUSANNE,AppliedMathematics Subject: RE: [R] Probability of data values form DENSITY function To: Lina Rusyte liner...@yahoo.co.uk Cc: R help r-help@r-project.org Date: Tuesday, 29 September, 2009, 4:59 PM Lina, check whether something like data.frame(density(rnorm(10))[1:2]) contains the information you want. Otherwise, try to be (much) more specific in what you want so that we do not need to guess (and of course provide minimal, self-contained, reproducible code). That has a higher chance to trigger some responses than posting the same message again. And if you even explain what you want to do with these values, you might get even better responses. HTH, Michael -Original Message- From: r-help-boun...@r-project.org http://de.mc256.mail.yahoo.com/mc/compose?to=r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org http://de.mc256.mail.yahoo.com/mc/compose?to=r-help-boun...@r-project.org ] On Behalf Of Lina Rusyte Sent: Dienstag, 29. September 2009 16:45 To: R help Cc: R help Subject: [R] Probability of data values form DENSITY function Hello,  Could someone help me please and to tell how to get the probability from empirical DENSITY (not parametric) for
Re: [R] Lattice: combine the same strip?
On Sat, Sep 19, 2009 at 3:36 PM, di jianing jianin...@gmail.com wrote: Hello R helpers, I am producing a figure with dual strips, i.e., x~y | S1 + S2, where S1 and S2 are two strips. For example, in figure 2.1 at http://lmdvr.r-forge.r-project.org/figures/figures.html. In this case, I would like to combine the the top strip, since all three pictures in the same row have the same level based on the first strip. In other words, instead of | -- S11 -- | -- S11 -- | -- S11 -- | | -- S21 -- | -- S22 -- | -- S23 -- | I would like my graph to look like | - S11 | | -- S21 -- | -- S22 -- | -- S23 -- | In there a way I can do it? No (or at least, way too complicated). The strip function gets called for each panel, and there is no provision to combine strips across panels. As Baptiste suggested, useOuterStrips() is probably an easier alternative. -Deepayan Thanks! JD [[alternative HTML version deleted]] __ R-help@r-project.org 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@r-project.org 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] fportfolio - help
Dear All, I have a .csv worksheet containing the following information - column A: dates (from 5/25/1999 to 5/26/2009, in chronological order) (in total there are 37 547 lines) - columns B to AH: numbers from approx -50 000 000 to 50 000 000, each representing a daily PL. Each column represents an asset - and I am trying to optimize a portfolio of such assets line 1 is a line of headers. I have dowloaded the fportfolio package but I can't manage to make anything out of it. I think that this is due to the class of my Data Set. It is said the Data must be of class timeSeries. Hence my question : how can I transform my .csv file in an appropriate *timeSeries *class Data Set, considering how my .csv file is built? Thank you very much for your kind help, Lara -- Lara Shocron lara.shoc...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org 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] preformatted and '#' in manual pages
On Tue, Sep 29, 2009 at 6:47 PM, Duncan Murdoch murd...@stats.uwo.ca wrote: On 9/29/2009 11:57 AM, Gábor Csárdi wrote: On Tue, Sep 29, 2009 at 5:36 PM, Duncan Murdoch murd...@stats.uwo.ca wrote: Gábor Csárdi wrote: Dear All, I have the following in a .Rd file: ... human readable (not binary) format. The format itself is like the following: \preformatted{ \# vertex1name vertex2name [optionalWeight] vertex3name [optionalWeight] } Here, the first vertex of an edge is preceded with a pound sign ... and it is fine with R 2.9.2, but fails on R-devel, when building the PDF version of the manual: ... * checking PDF version of manual ... WARNING LaTeX errors when creating PDF version. This typically indicates Rd problems. LaTeX errors found: ! You can't use `macro parameter character #' in vertical mode. argument ...ike the following: \begin {alltt} ## vertex1name vertex2name [... l.9051 listed one per line on subsequent lines.} * checking PDF version of manual without index ... ERROR To be precise, this is * using R version 2.10.0 Under development (unstable) (2009-09-27 r49847) Is there a way to escape the '#' for LaTeX? I believe the Latex macro you want is \sharp, which isnt an Rd macro, so you'd need something like \latex{\sharp}{#}. Duncan, this might solve the issue in Latex (I haven't tried yet), but in R (version 2.9.2) the manual page looks like ... is like the following: \latex{\sharp}{#} vertex1name vertex2name [optionalWeight] vertex3name [optionalWeight] Here, the first vertex of an edge is preceded with a pound sign ... which is obviously not what I want. I guess that's still in the \preformatted section, which doesn't act on Rd macros. Sorry about that, my advice assumed you were putting it into text. Did 2.9.x emit the \sharp in this situation, or did it do something else? We do some rewriting of special characters when writing verbatim text, and it looks as though our handling of # has changed. (I'm just heading out to a long meeting, or I'd check myself...) Duncan Murdoch Yes, that was 2.9.x. This part might be OK for R-devel (I don't know, I am using the windows build service to check with R-devel, but have no windows at hand to install the package). But, anyway, R-devel check fails if there is a '#' in the \preformatted section in all these situations: - plain # - escaped \# - \latex{\sharp}{#} Best, Gabor -- Gabor Csardi gabor.csa...@unil.ch UNIL DGM __ R-help@r-project.org 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] bwplot scales in alphabetical order
Dear List, I know this has been covered before, but I don't seem to be able to get it right. I am constructing a boxplot in lattice and can't get the scales in the correct alphebetical order. I have already read that this is due to the way factors are treated, and I have to redefine the levels of the factors. However, I have failed. As a simple example: library(lattice) id-rep(letters[1:9], each=20) x-rep(seq(1:10),each=18) y-rnorm(180,50,20) #Reverse alphebetical order bwplot(y~x|id, horizontal=FALSE) #alphebetical order reading right to left id-factor(id,levels = sort(id,decreasing = TRUE)) bwplot(y~x|id, horizontal=FALSE) It appears that bwplot plots scales from the bottom left to the top right. If so my factor levels would need to be levels=c(7,8,9,4,5,6,1,2,3). I tried that but can't seem to get the factor function to work. #Did not work! id-factor(id,levels=c(7,8,9,4,5,6,1,2,3),lables=letters[1:9]) Your help would be greatly appreciated. Tim Tim Clark Department of Zoology University of Hawaii __ R-help@r-project.org 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: How to display no box but only a y-axis on the left + Thicker lines
Yes. You can get back the tick marks with scaless$col: Thanks for the hint. May I kindly ask what would be the easiest way to draw a line on the left side? Thanks, Tom __ R-help@r-project.org 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] Condition to factor (easy to remember)
Dear List, creating factors in a given non-default orders is notoriously difficult to explain in a course. Students love the ifelse construct given below most, but I remember some comment from Martin Mächler (?) that ifelse should be banned from courses. Any better idea? Not necessarily short, easy to remember is important. Dieter data = c(1,7,10,50,70) levs = c(Pre,Post) # Typical C-Programmer style factor(levs[as.integer(data 10)+1], levels=levs) # Easiest to understand factor(ifelse(data =10, levs[1], levs[2]), levels=levs) -- View this message in context: http://www.nabble.com/Condition-to-factor-%28easy-to-remember%29-tp25676411p25676411.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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 there a R function that can do similar things like 'pdist' in Matlab?
That's not correlation. It's distance instead. See ?dist Regards, Yihui -- Yihui Xie xieyi...@gmail.com Phone: 515-294-6609 Web: http://yihui.name Department of Statistics, Iowa State University 3211 Snedecor Hall, Ames, IA On Tue, Sep 29, 2009 at 8:22 PM, RT Ye rty...@gmail.com wrote: Hi, I want to compute the pairwise correlation for about 10,000 genes. In Matlab there is a function called 'pdsit' that can do this very efficiently. I am wondering is there a similar function in R? Thanks, RT Ye. __ R-help@r-project.org 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@r-project.org 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: How to display no box but only a y-axis on the left + Thicker lines
2009/9/30 lith minil...@gmail.com: Yes. You can get back the tick marks with scaless$col: Thanks for the hint. May I kindly ask what would be the easiest way to draw a line on the left side? Try this, mpanel = function(...) { grid.segments(0,0,0,1) ; panel.bwplot(...) } bwplot(y~x, data=data.frame(y=rnorm(10),x=sample(letters[1:3],10,repl=T)), par.settings=list(axis.line=list(col=NA)), scales = list(col = 1), panel=mpanel) HTH, baptiste Thanks, Tom __ R-help@r-project.org 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@r-project.org 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] dichromat, regexp, and grid objects
Replying to myself here, Hadley pointed out this website on the ggplot2 mailing list, http://colororacle.cartography.ch/ And this seems like a more straight-forward solution to my query (albeit not using R). It sort of makes sense to momentarily alter the computer display rather than parse the code for colour and fill regular expressions... baptiste 2009/9/28 baptiste auguie baptiste.aug...@googlemail.com: Dear list, The dichromat package defines a dichromat function which Collapses red-green color distinctions to approximate the effect of the two common forms of red-green colour blindness, protanopia and deuteranopia. library(dichromat) library(grid) colorStrip - function (colors = 1:3, draw = TRUE) { x - seq(0, 1 - 1/length(colors), length = length(colors)) y - rep(0.5, length(colors)) my.grob - grid.rect(x = unit(x, npc), y = unit(y, npc), width = unit(1/length(colors), npc), height = unit(1, npc), just = left, hjust = NULL, vjust = NULL, default.units = npc, name = NULL, gp = gpar(fill = colors, col = colors, draw = draw, vp = NULL)) my.grob } colorStrip(1:3) colorStrip(dichromat(1:3)) Now what would be nice is a function that can edit the colours (col and fill parameters) of an existing grob. dichromatit - function(x){ .NotYetImplemented() } dichromatit(colorStrip()) It could allow high-level testing for visual perception of lattice and ggplot2 plots, p1 = xyplot(1~1) p2 = qplot(1,1, colour= I(red)) dichromatit(p1) p2 + dichromatit() One approach could be to use only integer codes for colours, and modify the current palette() (works also for base graphics). But this is quite a stringent request for lattice and ggplot2 which define many named colours in their various themes and scales. Therefore I'd like to think of an approach based on a recursive modification of a grob's gpar components. Does this seem doable with some regular expression magic [*]? All the best, baptiste [*]: http://xkcd.com/208/ __ R-help@r-project.org 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] Compress (gzip) a pdf device
I have not found an easy way to compress a file on filesystem. Especially I'd like to compress a pdf from pdf() function/device. Is it possible to compress It on the flight? I'd like to do something like: pdf(gzipconnection()) dev.off() If It is not possible, how can I create a gzip with the pdf? Thanks Daniele A. ORS Srl Via Agostino Morando 1/3 12060 Roddi (Cn) - Italy Tel. +39 0173 620211 Fax. +39 0173 620299 / +39 0173 433111 Web Site www.ors.it Qualsiasi utilizzo non autorizzato del presente messaggio e dei suoi allegati ? vietato e potrebbe costituire reato. Se lei avesse ricevuto erroneamente questo messaggio, Le saremmo grati se provvedesse alla distruzione dello stesso e degli eventuali allegati. Opinioni, conclusioni o altre informazioni riportate nella e-mail, che non siano relative alle attivit? e/o alla missione aziendale di O.R.S. Srl si intendono non attribuibili alla societ? stessa, n? la impegnano in alcun modo. [[alternative HTML version deleted]] __ R-help@r-project.org 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] Compress (gzip) a pdf device
2009/9/30 Daniele Amberti daniele.ambe...@ors.it I have not found an easy way to compress a file on filesystem. Especially I'd like to compress a pdf from pdf() function/device. Is it possible to compress It on the flight? I'd like to do something like: pdf(gzipconnection()) dev.off() I guess this boils down to a question I asked some time ago concerning getting the filename of a pdf() device, as I wanted to create a compressed pdf from the uncompressed pdf created by R (not zipping the pdf). It does not seem to be possible, at least I did not get any response which I could use to implement my idea (create my dev.off(), which calls dev.off() and afterwards compresses the pdf by using the file name). If you find a solution, please let me know. Cheers, Rainer If It is not possible, how can I create a gzip with the pdf? Thanks Daniele A. ORS Srl Via Agostino Morando 1/3 12060 Roddi (Cn) - Italy Tel. +39 0173 620211 Fax. +39 0173 620299 / +39 0173 433111 Web Site www.ors.it Qualsiasi utilizzo non autorizzato del presente messaggio e dei suoi allegati ? vietato e potrebbe costituire reato. Se lei avesse ricevuto erroneamente questo messaggio, Le saremmo grati se provvedesse alla distruzione dello stesso e degli eventuali allegati. Opinioni, conclusioni o altre informazioni riportate nella e-mail, che non siano relative alle attivit? e/o alla missione aziendale di O.R.S. Srl si intendono non attribuibili alla societ? stessa, n? la impegnano in alcun modo. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Natural Sciences Building Office Suite 2039 Stellenbosch University Main Campus, Merriman Avenue Stellenbosch South Africa Cell: +27 - (0)83 9479 042 Fax:+27 - (0)86 516 2782 Fax:+49 - (0)721 151 334 888 email: rai...@krugs.de Skype: RMkrug Google: r.m.k...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org 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] fitting logistic model with constant harvesting
Hi I am fitting simulated data to a logistic model usin SSlogis as follow: nls( cove ~ SSlogis(year, Asym, xmid, scal), data = dat, trace = TRUE, model = TRUE, ... ) This works niocely, but now I have a situation where I have constant harvesting, i.e. where p is the population size, N the carrying capacity, k the growth rate and a the constant harvest. My question is, how can I fit this logistic growth with constant harvesting to my data? Thanks, Raine -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Natural Sciences Building Office Suite 2039 Stellenbosch University Main Campus, Merriman Avenue Stellenbosch South Africa Cell: +27 - (0)83 9479 042 Fax:+27 - (0)86 516 2782 Fax:+49 - (0)721 151 334 888 email: rai...@krugs.de Skype: RMkrug Google: r.m.k...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org 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] Odp: Regression line w/ residuals - tuning the plot
Hi As you did not provide any piece of code I done some myself x-1:20 y-5*x+3+rnorm(20) plot(x,y) fit-lm(y~x) par(mfrow=c(2,1)) plot(x,y) abline(fit) plot(x, resid(fit)) I do not see any problem with this. If you want to set up margins use par(mar=) par(mar=c(0,4,4,1)) plot(x,y, axes=F) axis(2) box() abline(fit) par(mar=c(5,4,0,1)) plot(x, resid(fit)) Regards Petr r-help-boun...@r-project.org napsal dne 28.09.2009 17:19:27: Hello everybody, I am sure this is a beginners' problem which is being asked recurrently every few months, but nevertheless I wasn't able to find the answer searching through the r-help list. So here is my problem: I would like to plot a set of points (y vs. x), a (linear) regression line through them, and on the second graph underneath the first one I would want to plot residuals vs. x. I came up with two solutions, unfortunately neither of them is fully satisfactory. First I tried with what I later learned is called traditional graphics (file norris.R). Here, the white space margins around the plots are too wide, meaning that the data in the plot are crammed. Probably I would be quite happy if I could somehow define a rectangular plotting area with its height being ~150% of its width, but I cannot prevent R from offering me a square plotting area. Next I tried a lattice package (file norris.lattice.R). Here, the margins are smaller, but the lower plot does not fit exactly under the upper one (the x-axes should match). Most likely I am not using the correct terminology (if I would have known it, I could have looked in the help pages myself, thank you :), but I hope that the attached files make more sense of what I am trying to do. Thanks in advance. All the best, Primoz -- Primož Peterlin, Inštitut za biofiziko, Med. fakulteta, Univerza v Ljubljani Lipičeva 2, SI-1000 Ljubljana, Slovenija. primoz.peter...@mf.uni-lj.si Tel +386-1-5437612, fax +386-1-4315127, http://biofiz.mf.uni-lj.si/~peterlin/ F8021D69 OpenPGP fingerprint: CB 6F F1 EE D9 67 E0 2F 0B 59 AF 0D 79 56 19 0F __ R-help@r-project.org 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@r-project.org 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] Odp: how to draw a slope (using abline) with a specific starting point?
Hi it is not clear what you want? If you want a line which does not stretch entire plot use segments. AFAIK abline does not have any argument restricting its length. Regards Petr r-help-boun...@r-project.org napsal dne 29.09.2009 20:04:05: plot(y~x, type='p', col=3, xlim=c(50,1000), ylim=c(0,80), xlab='', ylab='', data=example) abline(a=11, b=0.04, col = 2) -- Thanks, A.B. [[alternative HTML version deleted]] __ R-help@r-project.org 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@r-project.org 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] dichromat, regexp, and grid objects
baptiste auguie baptiste.auguie at googlemail.com writes: Replying to myself here, Hadley pointed out this website on the ggplot2 mailing list, http://colororacle.cartography.ch/ And this seems like a more straight-forward solution to my query (albeit not using R). It sort of makes sense to momentarily alter the computer display rather than parse the code for colour and fill regular expressions... 2009/9/28 baptiste auguie baptiste.auguie at googlemail.com: Dear list, The dichromat package defines a dichromat function which Collapses red-green color distinctions to approximate the effect of the two common forms of red-green colour blindness, protanopia and deuteranopia. All the best, baptiste Just to point out a fact or two with respect to the information on the indicated web page and a statement above. While roughly 8% of males are classified as color-deficient by standard tests, as indicated at the site to which the link points, only about 2% are actually dichromats, i.e., protanopes and deuteranopes, referred to above as common forms, and to which the dichromat package is directly relevant. Dichromatic vision is reduced to 2 dimensions from the normal 3. Most of the other 6% (i.e., the most common forms) are what are termed anomalous trichromats and to whom the renditions of the dichromat package are not actually appropriate, as the color spaces of such observers are not a subspace of that of a normal observer. Such individuals really see the world a bit differently, as they may very well call something as red that a normal observer would call green or vice versa depending what kind of anomalous trichromat one is. So, strictly speaking, the dichromat package is of great value in avoiding color choices that about 1% of the population would have trouble discriminating. Ken -- Ken Knoblauch Inserm U846 Stem-cell and Brain Research Institute Department of Integrative Neurosciences 18 avenue du Doyen Lépine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr/members/kenneth-knoblauch.html __ R-help@r-project.org 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] R: How can I avoid a for-loop through sapply or lapply ?
Thank you very much. It works fine. Maura -Messaggio originale- Da: Steve Lianoglou [mailto:mailinglist.honey...@gmail.com] Inviato: mar 29/09/2009 18.08 A: mau...@alice.it Cc: r-h...@stat.math.ethz.ch Oggetto: Re: [R] How can I avoid a for-loop through sapply or lapply ? Hi, On Sep 29, 2009, at 12:03 PM, mau...@alice.it wrote: Through converting a miRNAs file from FASTA to character format I get a vector which looks like the following: nml [1] hsa-let-7a MIMAT062 Homo sapiens let-7a [2] hsa-let-7b MIMAT063 Homo sapiens let-7b [3] hsa-let-7c MIMAT064 Homo sapiens let-7c [4] hsa-let-7d MIMAT065 Homo sapiens let-7d [5] hsa-let-7e MIMAT066 Homo sapiens let-7e [6] hsa-let-7f MIMAT067 Homo sapiens let-7f [7] hsa-miR-15a MIMAT068 Homo sapiens miR-15a [8] hsa-miR-16 MIMAT069 Homo sapiens miR-16 [9] hsa-miR-17 MIMAT070 Homo sapiens miR-17 [10] hsa-miR-18a MIMAT072 Homo sapiens miR-18a ... [888] hsa-miR-675* MIMAT0006790 Homo sapiens miR-675* [889] hsa-miR-888* MIMAT0004917 Homo sapiens miR-888* [890] hsa-miR-541* MIMAT0004919 Homo sapiens miR-541* My goal is to separate into a vector only the first string preceding the 1st space starting from the left. With reference to the records above listed I would obtain: [1] hsa-let-7a [2] hsa-let-7b [3] hsa-let-7c [4] hsa-let-7d [5] hsa-let-7e [6] hsa-let-7f f [7] hsa-miR-15a [8] hsa-miR-16 [9] hsa-miR-17 [10] hsa-miR-18a ... [888] hsa-miR-675* [889] hsa-miR-888* [890] hsa-miR-541* pieces - strsplit(nml, ) sapply(pieces, '[', 1) Or, the same as a 1 liner: sapply(strsplit(nml, ), '[', 1) Hope that helps, -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact tutti i telefonini TIM! [[alternative HTML version deleted]] __ R-help@r-project.org 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] PCA or CA
On Tue, 2009-09-29 at 17:02 +, Paul Dennis wrote: Dear all I have a data set for which PCA based between group analysis (BGA) gives significant results but CA-BGA does not. I am having difficulty finding a reliable method for deciding which ordination technique is most appropriate. I have been told to do a 1 table CA and if the 1st axis is2 units go for CA if not then PCA. Another approach is that described in the Canoco manual - perform DCA and then look at the length of the axes. I used decorana in vegan and it gives axis lengths. I assume that these are measured in SD units. Anyway the manual say if the axis length is 3 go for PCA,4 use CA and if intermediate use either. Are either of these approaches good/valid/recommended or is there a better method? Thanks Paul Hi Paul I think that Ca is Correspondence Analysis and PCA is Principal Component Analysis, right? In this case, if all variables is numeric do you must use PCA, if all variables is factor do you must use CA. If you have a mixed variables do you have a problem, in most case I convert numeric variables to factor (with loss of information) and make CA -- Bernardo Rangel Tura, M.D,MPH,Ph.D National Institute of Cardiology Brazil __ R-help@r-project.org 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] programming to calculate variance
Dear R-user Suppose I have the following data y=c(2,1,5,8,11,3,1,7,50,21,33,7,60) x=data.frame(y) for(i in 4:nrow(x)) x[i,] =var(x[i-3:i-1,]) I'm trying to get a new variable with the variance of the 3 previous values (just an example) and with NA in the three first positions. I know that my for() is wrong but I'm not able to find my error. Any idea? Thanks, Marlene. [[alternative HTML version deleted]] __ R-help@r-project.org 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] Odp: programming to calculate variance
Hi Try function rollapply from zoo.It can compute rolling results of functions. Make your y a zoo object and use rollapply(object, 3, var) Regards Petr r-help-boun...@r-project.org napsal dne 30.09.2009 12:37:36: Dear R-user Suppose I have the following data y=c(2,1,5,8,11,3,1,7,50,21,33,7,60) x=data.frame(y) for(i in 4:nrow(x)) x[i,] =var(x[i-3:i-1,]) I'm trying to get a new variable with the variance of the 3 previous values (just an example) and with NA in the three first positions. I know that my for() is wrong but I'm not able to find my error. Any idea? Thanks, Marlene. [[alternative HTML version deleted]] __ R-help@r-project.org 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@r-project.org 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] Rserve with java commands and examples
I am currently working in Rserve. I have trouble understanding the eval commands and when to use it? How to write java script for R commands? Is there any tutorial or documentation. Thanks in advance for your help. -- View this message in context: http://www.nabble.com/Rserve-with-java-commands-and-examples-tp25675209p25675209.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How do I do simple string concatenation in R?
Dear R gurus How do I do simple string concatenation in R? For example: A = klm B = jjj How can I assign a value to C such that C == klmjjj is True? Thank you Arie [[alternative HTML version deleted]] __ R-help@r-project.org 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
Estoy haciendo un GLMM usando como variable aleatoria y una variable cualitativa con dos categorias. Cuando intento ajustar el modelo me devuelve el mensaje In mer_finalize(ans) : false convergence (8) a que es debido esto? y como puedo solucionarlo? Muchas gracias _ Descubre todas las formas en que puedes estar en contacto con amigos y familiares. [[alternative HTML version deleted]] __ R-help@r-project.org 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] programming to calculate variance
I think it should be var(y[i-3:i-1,]) instead of var(x[i-3:i-1,]) otherwise the values of the vector are overwritten Best wishes, Matthias marlene marchena schrieb: Dear R-user Suppose I have the following data y=c(2,1,5,8,11,3,1,7,50,21,33,7,60) x=data.frame(y) for(i in 4:nrow(x)) x[i,] =var(x[i-3:i-1,]) I'm trying to get a new variable with the variance of the 3 previous values (just an example) and with NA in the three first positions. I know that my for() is wrong but I'm not able to find my error. Any idea? Thanks, Marlene. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dr. rer. nat. Matthias Gondan Institut für Psychologie Universität Regensburg D-93050 Regensburg Tel. 0941-943-3856 Fax 0941-943-3233 Email: matthias.gon...@psychologie.uni-regensburg.de http://www.psychologie.uni-r.de/Greenlee/team/gondan/gondan.html __ R-help@r-project.org 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] Change directory to implement same programes
HI, R-Users, I have one problem: I have written the the programs which process all file in one directory: for example: setwd(C:/Documents and Settings/lma/My Documents/Vappu-saved/Log) as the start. .. But I have many folders like Vappu-saved and there are a lot of files in each directory. What I want is using the same program what I write for the above directory to autimatically change directory address to implement the above programs what I wrote. How do I realize it? Thanks a lot. Regards, Lingyi _ Windows Live: Keep your life in sync. Check it out! http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t1_allup_explore_012009 [[alternative HTML version deleted]] __ R-help@r-project.org 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 do I do simple string concatenation in R?
Tobias Verbeke wrote: Hi Ari, How do I do simple string concatenation in R? For example: A = klm B = jjj How can I assign a value to C such that C == klmjjj is True? paste(A, B, collapse = ) Oops. paste(A, B, sep = ) Best, Tobias __ R-help@r-project.org 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 do I do simple string concatenation in R?
?paste -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Dr. Arie Ben David Sent: Mittwoch, 30. September 2009 10:22 To: r-help@r-project.org Subject: [R] How do I do simple string concatenation in R? Dear R gurus How do I do simple string concatenation in R? For example: A = klm B = jjj How can I assign a value to C such that C == klmjjj is True? Thank you Arie [[alternative HTML version deleted]] __ R-help@r-project.org 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@r-project.org 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 do I do simple string concatenation in R?
Hi Ari, How do I do simple string concatenation in R? For example: A = klm B = jjj How can I assign a value to C such that C == klmjjj is True? paste(A, B, collapse = ) See ?paste HTH, Tobias __ R-help@r-project.org 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] Evaluating expresssions as parameter values
On Tue, Sep 22, 2009 at 12:03 PM, Erich Neuwirth erich.neuwi...@univie.ac.at wrote: I need to play games with an expression similar to the following one: print(xyplot(DepVar ~ Group|Covar, groups=Othergroup, data=mydf, pch = 18 ,main=Testcase,auto.key = TRUE)) The problem is that the formula argument (the first argument) an the groups argument are passed over from another program as strings. The formula argument does not pose problems, I can do as.formula(DepVar ~ Group|Covar) bit I could not find an equivalent technique for the groups parameter. 'groups' can be a formula too, e.g., xyplot(Sepal.Length ~ Petal.Length, iris, groups = ~Species) -Deepayan __ R-help@r-project.org 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 do I do simple string concatenation in R?
see ?paste A -klm B - jjj C-paste(A,B,sep='') if(C==klmjjj) print(C) [1] klmjjj cheers Bob Dr. Arie Ben David hol_aben...@bezeqint.net Sent by: r-help-boun...@r-project.org 30/09/2009 09:22 To r-help@r-project.org cc Subject [R] How do I do simple string concatenation in R? Dear R gurus How do I do simple string concatenation in R? For example: A = klm B = jjj How can I assign a value to C such that C == klmjjj is True? Thank you Arie [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org 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] Change directory to implement same programes
How do I source a bunch of files in different directories in R? From: metal_lical...@live.com To: r-help@r-project.org Date: Wed, 30 Sep 2009 13:45:34 +0300 Subject: [R] Change directory to implement same programes HI, R-Users, I have one problem: I have written the the programs which process all file in one directory: for example: setwd(C:/Documents and Settings/lma/My Documents/Vappu-saved/Log) as the start. .. But I have many folders like Vappu-saved and there are a lot of files in each directory. What I want is using the same program what I write for the above directory to autimatically change directory address to implement the above programs what I wrote. How do I realize it? Thanks a lot. Regards, Lingyi _ Windows Live: Keep your life in sync. Check it out! http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t1_allup_explore_012009 [[alternative HTML version deleted]] _ Show them the way! Add maps and directions to your party invites. http://www.microsoft.com/windows/windowslive/products/events.aspx [[alternative HTML version deleted]] __ R-help@r-project.org 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] programming to calculate variance
Hi Petr, Thanks for your suggestion. It woks, but now I have other problem the positions of the values changed. I need the NA values in the three first positions. y=c(2,1,5,8,11,3,1,7,50,21,33,7,60) x=as.zoo(y) x 1 2 3 4 5 6 7 8 9 10 11 12 13 2 1 5 8 11 3 1 7 50 21 33 7 60 varx=rollapply(x,3,var) 2 345 6 7 89 10 11 12 4.33 12.33 9.00 16.33 28.00 9.33 714.33 481.00 212.33 169.33 702.33 2009/9/30 Petr PIKAL petr.pi...@precheza.cz Hi Try function rollapply from zoo.It can compute rolling results of functions. Make your y a zoo object and use rollapply(object, 3, var) Regards Petr r-help-boun...@r-project.org napsal dne 30.09.2009 12:37:36: Dear R-user Suppose I have the following data y=c(2,1,5,8,11,3,1,7,50,21,33,7,60) x=data.frame(y) for(i in 4:nrow(x)) x[i,] =var(x[i-3:i-1,]) I'm trying to get a new variable with the variance of the 3 previous values (just an example) and with NA in the three first positions. I know that my for() is wrong but I'm not able to find my error. Any idea? Thanks, Marlene. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org 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] Change directory to implement same programes
Perhaps Sys.glob can help you. See ?Sys.glob On Wed, Sep 30, 2009 at 8:19 AM, Tammy Ma metal_lical...@live.com wrote: How do I source a bunch of files in different directories in R? From: metal_lical...@live.com To: r-help@r-project.org Date: Wed, 30 Sep 2009 13:45:34 +0300 Subject: [R] Change directory to implement same programes HI, R-Users, I have one problem: I have written the the programs which process all file in one directory: for example: setwd(C:/Documents and Settings/lma/My Documents/Vappu-saved/Log) as the start. .. But I have many folders like Vappu-saved and there are a lot of files in each directory. What I want is using the same program what I write for the above directory to autimatically change directory address to implement the above programs what I wrote. How do I realize it? Thanks a lot. Regards, Lingyi _ Windows Live™: Keep your life in sync. Check it out! http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t1_allup_explore_012009 [[alternative HTML version deleted]] _ Show them the way! Add maps and directions to your party invites. http://www.microsoft.com/windows/windowslive/products/events.aspx [[alternative HTML version deleted]] __ R-help@r-project.org 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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org 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] multiple lattice, xyplot levelplot on same page - solved
Felix, Thanks for your suggestions below and all the behind-the-scenes email help. For those who come after me on this issue. Option (1) worked best for my purpose as it retained the levelplot() legend, and meant the y-axis were exactly aligned. The trick was the following advice: If you are using c(), you need to give arguments like scales only to the first object in c(); most such settings for the second object will be ignored. The 'correct' (i.e. gives me what I want ;-) ) code is below. Two points to note: 1) I used subscripts = TRUE in the original use of xyplot(), removing the necessity for p1 - update(p1, subscripts = TRUE) (see email below) 2) Using c() in this way did rotate the y-labels to 90degrees, so I had to specify scales = list(y = list(rot=0)) to ensure the y-labels were plotted as they would be with levelplot() defaults. Many thanks and regards, Ky #--- #Working code, xyplot levelplot on same page library(lattice) library(latticeExtra) #xyplot x1 - 0:10 x2 - x1^2 p1 - xyplot(x2 ~ x1, subscripts = TRUE, panel = function(x,y,...){ panel.xyplot(x, y, type=l, lwd=2)}) #levelplot y.df - data.frame(y1 = rep(x1, times = 3), y2 = rep(c('E1', 'E2', 'E3'), each = length(x1)), y3 = c(x1, x1+2, x1-1)) p2 - levelplot(y3 ~ y1*y2, data = y.df, scales = list(y = list(rot = 0)), colorkey =list(space='bottom')) update(c(p2, p1, x.same = TRUE), layout = c(1, 2), ylab = list(c(p2, p1), c(1/4, 3/4))) -Original Message- From: foolish.andr...@gmail.com [mailto:foolish.andr...@gmail.com] On Behalf Of Felix Andrews Sent: Sunday, 27 September 2009 9:00 PM To: Ky Mathews Cc: r-help@r-project.org Subject: Re: [R] multiple lattice, xyplot levelplot on same page Ky, The error you report is a problem with the c() method for trellis plots: it allows for a different panel function in each panel, but only one prepanel function. Because of this, the prepanel.default.levelplot function is not getting what it expects to recompute the panel dimensions. It may be possible to extend the function to handle this, but for now you have a few options: (1) Set subscripts = TRUE in the xyplot: p1 - update(p1, subscripts = TRUE) update(c(p2, p1, x.same = TRUE), layout = c(1, 2)) (2) Put the xyplot first, but then re-order the panels by indexing: update(c(p1, p2, x.same = TRUE), layout = c(1, 2))[2:1] (3) Take out the x.same=TRUE argument, if you can set the x scales to be the same beforehand. In your example, the xyplot and levelplot had the same x axis limits anyway, but presumably that is not the case in your real problem. update(c(p2, p1), layout = c(1, 2)) (4) Use a completely different mechanism: draw the two plots in the desired position (after setting the x axes to be identical beforehand, if desired). See ?plot.trellis This latter mechanism was designed in to trellis from the beginning, whereas the c() method is basically a hack. It also has the advantage of retaining complete control over each plot independently. By the way, I can't understand what you are trying to do with the par.settings$layout.width argument. It doesn't seem to have any effect. Ditto for the 'y = c(1/4, 3/4))' argument. Also, I seem to have lost control of par settings such as las = 1 This is a base graphics (?par) parameter, which does not apply to grid or lattice graphics. The equivalent of las in lattice is the scales$rot argument. See ?xyplot Hope that helps -Felix 2009/9/26 Ky Mathews k.math...@usyd.edu.au: Dear R-users, I'd like to place an xyplot() at the top of a page and a levelplot() at the bottom of the same page, and have the x-axes be the same. I've come close to finding a solution through Rarchive, and can produce an upside-down version of what I'd like (levelplot() on the top - see code below). However, the following error occurs when I try and plot the xyplot() at the top: Error in prepanel.default.function(x = 0:10, y = c(0, 1, 4, 9, 16, 25, : element 1 is empty; the part of the args list of 'length' being evaluated was: (subscripts) Any pointers in the right direction would be much appreciated. #OS: Windows XP 2002 SP3; R: 2.9.2; lattice 0.17-25; latticeExtra 0.6-1 Thanks and regards, Ky ### #Rcode for xyplot and lattice plot on the same page. library(lattice) library(latticeExtra) #xyplot x1 - 0:10 x2 - x1^2 p1 - xyplot(x2 ~ x1 , par.settings = list(layout.width = list(panel=1, ylab = 2 , axis.left =1.0, left.padding=1 , ylab.axis.padding=1, axis.panel=1))) #levelplot y.df - data.frame(y1 = rep(x1, times = 3) ,
[R] How to change e-mail address
Hi! Thanks in advance. I know this is not the right place to send this message. But I have tried to do so by sending e-mail to the addresses r-help-requ...@r-project.org and r-announce-requ...@stat.math.ethz.ch. But no success. I am getting messages such as Your message to R-help awaits moderator approval. I need your assistance on above. I am an user of r-help. My e-mail address has been changed due to the new name of our Department. My previous e-mail address (When I have subscribed to r-help by sending an e-mail): debabrata.mi...@commerce.nsw.gov.au My current e-mail address: debabrata.mi...@services.nsw.gov.au Regards, Deb [[alternative HTML version deleted]] __ R-help@r-project.org 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] programming to calculate variance
marlene marchena marchenamarl...@gmail.com napsal dne 30.09.2009 13:28:16: Hi Petr, Thanks for your suggestion. It woks, but now I have other problem the positions of the values changed. I need the NA values in the three first positions. y=c(2,1,5,8,11,3,1,7,50,21,33,7,60) x=as.zoo(y) x 1 2 3 4 5 6 7 8 9 10 11 12 13 2 1 5 8 11 3 1 7 50 21 33 7 60 varx=rollapply(x,3,var) 2 345 6 7 89 10 11 12 4.33 12.33 9.00 16.33 28.00 9.33 714.33 481.00 212.33 169.33 702.33 win-3 varx=rollapply(x,win,var) varx[1:win]-NA Regards Petr 2009/9/30 Petr PIKAL petr.pi...@precheza.cz Hi Try function rollapply from zoo.It can compute rolling results of functions. Make your y a zoo object and use rollapply(object, 3, var) Regards Petr r-help-boun...@r-project.org napsal dne 30.09.2009 12:37:36: Dear R-user Suppose I have the following data y=c(2,1,5,8,11,3,1,7,50,21,33,7,60) x=data.frame(y) for(i in 4:nrow(x)) x[i,] =var(x[i-3:i-1,]) I'm trying to get a new variable with the variance of the 3 previous values (just an example) and with NA in the three first positions. I know that my for() is wrong but I'm not able to find my error. Any idea? Thanks, Marlene. [[alternative HTML version deleted]] __ R-help@r-project.org 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@r-project.org 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] AsciiDoc and R
I would like to learn AsciiDoc. Is there any good examples how to use AsciiDoc with R? I know that there is packages called ascii to do this, but it would be nice to see some examples how AsciiDoc works with R. Is there an AsciiDoc distribution for Max OS X? -Johannes __ R-help@r-project.org 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] programming to calculate variance
Hi Marlene, x=data.frame(y,vr=NA) for(i in 4:nrow(x)) x[i,vr] =var(y[(i-3):(i-1)]) will do the trick, solving both problems with overwriting subsequent x-values and obeying the precedence of R operators. For the latter, see ?Syntax and compare i-5 i-3:i-1 (i-3):(i-1) hth. marlene marchena schrieb: Dear R-user Suppose I have the following data y=c(2,1,5,8,11,3,1,7,50,21,33,7,60) x=data.frame(y) for(i in 4:nrow(x)) x[i,] =var(x[i-3:i-1,]) I'm trying to get a new variable with the variance of the 3 previous values (just an example) and with NA in the three first positions. I know that my for() is wrong but I'm not able to find my error. Any idea? Thanks, Marlene. [[alternative HTML version deleted]] __ R-help@r-project.org 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. -- Eik Vettorazzi Institut für Medizinische Biometrie und Epidemiologie Universitätsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790 -- Pflichtangaben gemäß Gesetz über elektronische Handelsregister und Genossenschaftsregister sowie das Unternehmensregister (EHUG): Universitätsklinikum Hamburg-Eppendorf Körperschaft des öffentlichen Rechts Gerichtsstand: Hamburg Vorstandsmitglieder: Prof. Dr. Jörg F. Debatin (Vorsitzender) Dr. Alexander Kirstein Ricarda Klein Prof. Dr. Dr. Uwe Koch-Gromus __ R-help@r-project.org 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] AsciiDoc and R
Hello, There is a webpage showing examples of asciidoc and R here : http://eusebe.github.com/ascii/ The package works with Sweave() function : Sweave(yourfile.Rnw, driver = RweaveAsciidoc) where youfile.Rnw is a text file with asciidoc markup and embedded R code. About asciidoc markup, the documentation is very complete: http://www.methods.co.nz/asciidoc/userguide.html For Mac OS X installation, I really have no idea, but perhaps this page may help you : http://www.lco.cl/Members/geychaner/Install%20instructions.html#asciidoc Best, David 2009/9/30 johannes rara johannesr...@gmail.com I would like to learn AsciiDoc. Is there any good examples how to use AsciiDoc with R? I know that there is packages called ascii to do this, but it would be nice to see some examples how AsciiDoc works with R. Is there an AsciiDoc distribution for Max OS X? -Johannes __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org 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] programming to calculate variance
Thanks a lot, finally It works! I was wondering why my for() did not work. Now I now the difference between i-3 and (i-3) Thanks again for all your help. Marlene. x y vr 1 2 NA 2 1 NA 3 5 NA 4 8 4.33 5 11 12.33 6 3 9.00 7 1 16.33 8 7 28.00 9 50 9.33 10 21 714.33 11 33 481.00 12 7 212.33 13 60 169.33 2009/9/30 Eik Vettorazzi e.vettora...@uke.uni-hamburg.de Hi Marlene, x=data.frame(y,vr=NA) for(i in 4:nrow(x)) x[i,vr] =var(y[(i-3):(i-1)]) will do the trick, solving both problems with overwriting subsequent x-values and obeying the precedence of R operators. For the latter, see ?Syntax and compare i-5 i-3:i-1 (i-3):(i-1) hth. marlene marchena schrieb: Dear R-user Suppose I have the following data y=c(2,1,5,8,11,3,1,7,50,21,33,7,60) x=data.frame(y) for(i in 4:nrow(x)) x[i,] =var(x[i-3:i-1,]) I'm trying to get a new variable with the variance of the 3 previous values (just an example) and with NA in the three first positions. I know that my for() is wrong but I'm not able to find my error. Any idea? Thanks, Marlene. [[alternative HTML version deleted]] __ R-help@r-project.org 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. -- Eik Vettorazzi Institut für Medizinische Biometrie und Epidemiologie Universitätsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790 -- Pflichtangaben gemäß Gesetz über elektronische Handelsregister und Genossenschaftsregister sowie das Unternehmensregister (EHUG): Universitätsklinikum Hamburg-Eppendorf Körperschaft des öffentlichen Rechts Gerichtsstand: Hamburg Vorstandsmitglieder: Prof. Dr. Jörg F. Debatin (Vorsitzender) Dr. Alexander Kirstein Ricarda Klein Prof. Dr. Dr. Uwe Koch-Gromus [[alternative HTML version deleted]] __ R-help@r-project.org 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] Condition to factor (easy to remember)
On Sep 30, 2009, at 3:43 AM, Dieter Menne wrote: Dear List, creating factors in a given non-default orders is notoriously difficult to explain in a course. Students love the ifelse construct given below most, but I remember some comment from Martin Mächler (?) that ifelse should be banned from courses. Any better idea? Not necessarily short, easy to remember is important. Dieter data = c(1,7,10,50,70) levs = c(Pre,Post) # Typical C-Programmer style factor(levs[as.integer(data 10)+1], levels=levs) I agree with your observation that many people express a preference for the ifelse version. I had the same sort of comment on some of my Excel code (not in a statistical application) a couple of days ago. In your code the as.integer function is superfluous and you could argue that it might even be easier to understand for the Boolean- challenged masses if you substituted as.logical(). It would be also superfluous, but it might convey a message that the programmer _knew+ that the + operation is capable of doing the necessary coercion. # Easiest to understand factor(ifelse(data =10, levs[1], levs[2]), levels=levs) -- -- Boole Rules David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org 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 for visualizing/analyzing accelerometry data?
On 9/29/2009 10:39 PM, Jen Maresh wrote: Hello All - Any recommendations or suggestions for neat ways to visualize data taken from a 3-axis accelerometer? My study species is aquatic, so I would be interested in movement in the 3 dimensions in addition to being able to incorporate the time series as well. Is there a package in R that might be useful for this? As David mentioned, rgl can draw 3D figures, but the problem of visualizing a 3D path in an informative way is not easy. The new cylinder3d function in rgl might give paths that are easier to decode visually than line segments would be; it also offers the possibility of encoding orientation in the shape of the cylinder. I'd be interested in hearing how this goes. Duncan Murdoch __ R-help@r-project.org 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] Condition to factor (easy to remember)
David Winsemius wrote: # Typical C-Programmer style factor(levs[as.integer(data 10)+1], levels=levs) In your code the as.integer function is superfluous Oops... done too much c# lately, getting invalid cast challenged. Dieter -- View this message in context: http://www.nabble.com/Condition-to-factor-%28easy-to-remember%29-tp25676411p25680111.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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 compile R with command completion?
On Tue, Sep 29, 2009 at 10:39 PM, Martin Morgan mtmor...@fhcrc.org wrote: Peng Yu wrote: On Tue, Sep 29, 2009 at 3:47 PM, Tobias Verbeke tobias.verb...@gmail.com wrote: Peng Yu wrote: I want to compile R with command completion. But I don't find such an option in configure. Can somebody let me know how to enable command completion in an R session? AFAIK this is not an option you set when compiling. Did you try to type a letter (say 'l') and press the TAB key ? If you are not satisfied, you might want to use other R editors or development environments (such as StatET for Eclipse or ESS) which implement command completion in their idiosyncratic ways. I have an older version of R where I can do command completion (after typing TAB, it will list variables that are starting with the already typed letter. I compiled a newer version R with the default compile options, which does not do command completion. Since the old version can do completion, I believe that there must be a way to configure the new version also do so. Can somebody share your insights with me? Thank you! On linux this facility is provided by the readline system library; this should be configured to be true by default and when available; look at the end of the configure output, and check that you have the readline headers installed. I get the following configure output that is related to readline. Why 'rl_completion_matches' doesn't exist? What should I do with it? checking readline/history.h usability... yes checking readline/history.h presence... yes checking for readline/history.h... yes checking readline/readline.h usability... yes checking readline/readline.h presence... yes checking for readline/readline.h... yes checking for rl_callback_read_char in -lreadline... no checking for main in -lncurses... yes checking for rl_callback_read_char in -lreadline... yes checking for history_truncate_file... yes checking whether rl_completion_matches exists and is declared... no checking readline/history.h usability... yes checking readline/history.h presence... yes checking for readline/history.h... yes checking readline/readline.h usability... yes checking readline/readline.h presence... yes checking for readline/readline.h... yes checking for rl_callback_read_char in -lreadline... no checking for main in -lncurses... yes checking for rl_callback_read_char in -lreadline... yes checking for history_truncate_file... yes checking whether rl_completion_matches exists and is declared... no __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to automatically set plot limits and plot scale?
Hi all, I have two related questions about plot limits and plot sizes. R can automatically fit plot limits to your data if you plot the data in the first plot command. But if you add to the plot later (e.g. by drawing lines, as I must do), the original limits are not recalculated, even if you plot outside what is displayed. Is there a way to get R to automatically change the limits to fit everthing in? I can live with not being able to solve that problem because I don't need to make so many plots that I can't manually set the limits. My next problem is more challenging to solve manually. I would like my plots, when I send them to postscript, to all have the same scale (number of units per cm on page should be the same). So if the plot limits are set to encompass more, the graph should be output as bigger. It doesn't seem completely straightforward to do this manually by setting the postscript width and height, because that doesn't take into account that there are margins, etcetera. Is there a way to solve this? Thanks very much for any help! Ben -- View this message in context: http://www.nabble.com/how-to-automatically-set-plot-limits-and-plot-scale--tp25680059p25680059.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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 change e-mail address
On Sep 30, 2009, at 1:09 AM, Debabrata Midya wrote: Hi! Thanks in advance. I know this is not the right place to send this message. But I have tried to do so by sending e-mail to the addresses r-help-requ...@r-project.org and r-announce-requ...@stat.math.ethz.ch. But no success. I am getting messages such as Your message to R-help awaits moderator approval. I need your assistance on above. I am an user of r-help. My e-mail address has been changed due to the new name of our Department. My previous e-mail address (When I have subscribed to r-help by sending an e-mail): debabrata.mi...@commerce.nsw.gov.au My current e-mail address: debabrata.mi...@services.nsw.gov.au You could have done this yourself if you had read the directions on the page where you originally subscribed: https://stat.ethz.ch/mailman/listinfo/r-help Look for: To unsubscribe from R-help, get a password reminder, or change your subscription options enter your subscription email address: Log in using you old address and change your subscription information. -- David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org 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] bwplot scales in alphabetical order
Tim, Add the argument as.table=TRUE to your call: bwplot(y~x|id, horizontal=FALSE, as.table=TRUE) Peter Ehlers Tim Clark wrote: Dear List, I know this has been covered before, but I don't seem to be able to get it right. I am constructing a boxplot in lattice and can't get the scales in the correct alphebetical order. I have already read that this is due to the way factors are treated, and I have to redefine the levels of the factors. However, I have failed. As a simple example: library(lattice) id-rep(letters[1:9], each=20) x-rep(seq(1:10),each=18) y-rnorm(180,50,20) #Reverse alphebetical order bwplot(y~x|id, horizontal=FALSE) #alphebetical order reading right to left id-factor(id,levels = sort(id,decreasing = TRUE)) bwplot(y~x|id, horizontal=FALSE) It appears that bwplot plots scales from the bottom left to the top right. If so my factor levels would need to be levels=c(7,8,9,4,5,6,1,2,3). I tried that but can't seem to get the factor function to work. #Did not work! id-factor(id,levels=c(7,8,9,4,5,6,1,2,3),lables=letters[1:9]) Your help would be greatly appreciated. Tim Tim Clark Department of Zoology University of Hawaii __ R-help@r-project.org 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@r-project.org 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] AsciiDoc and R
On Sep 30, 2009, at 7:57 AM, johannes rara wrote: I would like to learn AsciiDoc. Is there any good examples how to use AsciiDoc with R? I know that there is packages called ascii to do this, but it would be nice to see some examples how AsciiDoc works with R. Is there an AsciiDoc distribution for Max OS X? http://lmgtfy.com/?q=asciidoc+mac+os+x (Google even gives you informative links if you misspell it (as I did) as ascidocs the first time.) -- David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org 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] Overview of error and warning messages for teaching + examples
Dear all, The background: as I didn't find a manual specifically directed towards debugging R code on a novice and intermediate level, I decided to write a student manual myself. I have some basic examples of errors (the classical interpunction and writing mistakes), but have the feeling that I miss quite some of the frequently occuring mistakes and messages. Therefore I'm looking around to find a list of these, and if possible, some examples of wrong R code. I have been googling around a bit, but I couldn't find an overview of the most common error and warning messages in R. Off course this mailing list is an extensive source of all kind or errors and examples, but I was wondering if there is a somewhat more structured overview. All help appreciated. Kind regards Joris Meys __ R-help@r-project.org 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] Read header csv file
Hi R community, First of all, I want to thank everybody to share their time solving R questions, You are great. Ok, for my questions, I've been looking for a solutions by myself, in forums but I'm just a little bit desesperate so I hope somebody can help me. I have built a code to read files from a directory. These files are named by a year (2004.csv, 2005.csv,...). When the code reads first file (2004.csv), inside this file, there is information about precipitation of every months and I calculate different variables like R square adjusted, p value or formula fit to the data from linear regression. The code do more things but for my question, to explain what I need, that part of the code is enough. I want to export to the text file, year and month apart of some other variables, something like this: Year: 2004 Month: January R1: 0.98 Pvalue: 0.03 ... Year: 2004 Month: February R1:0.78 Pvalue:0.12 ... I've seen that I can use order sink() and cat(), so I would put those orders in my code, like this: nfiles- length(dir(directory where my files are)) #Count file number for(year in 1:nfiles)#Read first file { filename-dir()[[year]]#take first file and read filename, so if year is 1, then filename will be 2004, is year is 2, filename will be 2005,... clima-read.csv2(filename, nrows=7) #open 2004.csv So, if want to export year to my text file I would do for(year in 1:nfiles)#Read first file { sink(directore where my text file is) filename-dir()[[year]]#take first file and read filename, so if year is 1, then filename will be 2004, is year is 2, filename will be 2005,... cat( Year: ,filename) sink() clima-read.csv2(filename, nrows=7) #open 2004.csv And in my text file would read Year: 2004 Now, I want to the same to months. (I have built a for loop to read months inside for loop to read years). When I import a csv file I get something like this JanurayFebruary 13.0 4.1 21.4 3.7 3 0.2 1.5 4 6.7 4.1 . . . I can use commands like clima$Januray or clima[[1]] but I just get precipitation values. However, I am not able to get the header of the column. If I would able to do that I could do the same as for years and export those headers to my text file. Does anyone know how I could do that? or does anyone know another way to do what I need? Would anyone use sink() and cat() commands to create a summary text like the one I need to do?. Probably my for loop is not the best, I am still a beginner with R, and probably there are some better forms to express in R what I need but I am working alone so there is nobody in person to help me so I apologize for my simple questions. Thanks in advance. Lucas _ [[alternative HTML version deleted]] __ R-help@r-project.org 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 compile R with command completion?
Peng Yu wrote: On Tue, Sep 29, 2009 at 10:39 PM, Martin Morgan mtmor...@fhcrc.org wrote: Peng Yu wrote: On Tue, Sep 29, 2009 at 3:47 PM, Tobias Verbeke tobias.verb...@gmail.com wrote: Peng Yu wrote: I want to compile R with command completion. But I don't find such an option in configure. Can somebody let me know how to enable command completion in an R session? AFAIK this is not an option you set when compiling. Did you try to type a letter (say 'l') and press the TAB key ? If you are not satisfied, you might want to use other R editors or development environments (such as StatET for Eclipse or ESS) which implement command completion in their idiosyncratic ways. I have an older version of R where I can do command completion (after typing TAB, it will list variables that are starting with the already typed letter. I compiled a newer version R with the default compile options, which does not do command completion. Since the old version can do completion, I believe that there must be a way to configure the new version also do so. Can somebody share your insights with me? Thank you! On linux this facility is provided by the readline system library; this should be configured to be true by default and when available; look at the end of the configure output, and check that you have the readline headers installed. I get the following configure output that is related to readline. Why 'rl_completion_matches' doesn't exist? What should I do with it? checking readline/history.h usability... yes checking readline/history.h presence... yes checking for readline/history.h... yes checking readline/readline.h usability... yes checking readline/readline.h presence... yes checking for readline/readline.h... yes checking for rl_callback_read_char in -lreadline... no checking for main in -lncurses... yes checking for rl_callback_read_char in -lreadline... yes checking for history_truncate_file... yes checking whether rl_completion_matches exists and is declared... no I don't know. Ask on the R-devel mailing list. Include the output of R's sessionInfo(), your operating system version, and the version of readline (e.g., from /usr/include/readline/readline.h) Martin checking readline/history.h usability... yes checking readline/history.h presence... yes checking for readline/history.h... yes checking readline/readline.h usability... yes checking readline/readline.h presence... yes checking for readline/readline.h... yes checking for rl_callback_read_char in -lreadline... no checking for main in -lncurses... yes checking for rl_callback_read_char in -lreadline... yes checking for history_truncate_file... yes checking whether rl_completion_matches exists and is declared... no __ R-help@r-project.org 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. -- Martin Morgan Computational Biology / Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: Arnold Building M1 B861 Phone: (206) 667-2793 __ R-help@r-project.org 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] Optim(...) estimate of stDev far too low
R-help, I'm just trying to find the ML (maximum likelihood) estimates of the mean and standard deviation of a set of observations: xx=c(2.5,3.5,4,6,6.5,7.5) fn-function(params,x=xx) { media-params[1] st -params[2] pdf=-sum(dnorm(log(xx),log(media),st,TRUE)) return(pdf) } optim(c(mu,stdev),fn,method=L-BFGS-B,lower=c(0.001, 0.001) ,upper = rep(Inf, 2), hessian=TRUE, control=list(trace=1)) iter0 value 3.011784 final value 2.802694 converged $par [1] 4.6597779 0.3860387 $value [1] 2.802694 $counts function gradient 17 17 $convergence [1] 0 $message [1] CONVERGENCE: REL_REDUCTION_OF_F = FACTR*EPSMCH WHich gives an estimate of stDev = 0.38 while the empirical stDev = 1.94 Is there anything wrong above in the code? Thanks in advance __ R-help@r-project.org 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] rcs fits in design package
Hi all, I have a vector of proportions (post_op_prw) such that summary(amb$post_op_prw) Min. 1st Qu. MedianMean 3rd Qu.Max.NA's 0. 0. 0. 0.3985 0.9134 0.9962 1. summary(cut2(amb$post_op_prw,0.0001)) [0.,0.0001) [0.0001,0.9962]NA's 19041672 1 I want to use post_op_prw as a predictor variable in an OLS model. I decided to fit it using a restricted cubic spline. But, I'm seeing behavior I don't understand. See below: rcspline.eval(amb$post_op_prw,nk = 3, knots.only = T) [1] 0.000 0.6147927 0.9092937 0.9667178 Warning message: In rcspline.eval(amb$post_op_prw, nk = 3, knots.only = T) : could not obtain 3 knots with default algorithm. Used alternate algorithm to obtain 4 knots rcspline.eval(amb$post_op_prw,nk = 4, knots.only = T) [1] 0.000 0.8476793 0.9783558 rcspline.eval(amb$post_op_prw,nk = 5, knots.only = T) [1] 0.000 0.9012711 0.9783558 Why are the 4 and 5 knot spline requests returning a spline with 3 knots? I get the best model results using rcs(amb$post_op_prw,3). I'm kind of new to using splines. Does the fact that observations are clustered at the ends make the spline fit questionable? Thanks, Rachel Hayes [[alternative HTML version deleted]] __ R-help@r-project.org 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] R/PL : cannot build PL/R
Dear all, i am trying to get PL / R running on Mac OS X. PostgreSQL is already running and connects just smoothly to R via DBI / RPostgreSQL . Despite finding a couple of posts of people with the same problem (i.e. error message) i could not get it done for me. I use Mac OS 10.5.7 and PostgreSQL 8.3.7 as well as R 2.9.2 I put the untared plr to my /Library/Frameworks/R.framework/Resources/ If i just add the path mentioned above to the Makefile and run USE_PGXS=1 make : i get the following error message: make: pg_config: Command not found make: *** No targets. Stop. If simply run make inside the plr directory i get the following: Makefile:41: ../../src/Makefile.global: No such file or directory Makefile:42: /contrib/contrib-global.mk: No such file or directory make: *** No rule to make target `/contrib/contrib-global.mk'. Stop. If I change R_HOME in the makefile to Users/myname (which is supposed to be my R home and initial working directory) I get the following error message: *** Cannot build PL/R because libR is not a shared library. *** You might have to rebuild your R installation. Refer to *** the documentation for details. This is a message i found already on several posts. Some answers suggest to recompile R with the shared lib option enabled. Anyway, some posts suggests that it is possible without recompiling. Simon Urbanek for example said on a markmail.org post, it was possible without recompiling. I´d really like to know how... Thx in advance for any suggestions ! Best regards matt __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to calculate KMO?
Hi All, How do i calculate KMO for a dataset? *Dataset:-* m1 m2 m3 m4 m5 m6 m7 m8 1 2 20 20 2 1 4 14 12 2 9 16 3 5 2 5 5 15 3 18 18 18 13 17 9 2 4 4 7 7 2 12 2 11 11 11 5 7 8 5 19 5 2 20 18 6 7 4 7 4 7 9 3 3 7 5 5 5 12 5 13 13 12 8 6 6 4 3 5 17 17 16 9 12 12 4 2 4 4 14 14 10 5 14 6 19 6 2 20 20 11 13 13 13 20 10 10 10 9 12 3 3 3 11 6 15 15 12 13 2 2 2 7 5 5 6 16 14 11 11 10 4 10 10 10 10 15 1 1 1 8 4 16 16 17 16 23 23 3 4 3 3 3 3 17 4 4 6 9 8 17 8 18 18 8 8 5 9 7 7 7 9 19 6 7 8 3 8 4 4 7 20 8 11 9 3 2 2 2 3 ** *SPSS results for the above dataset:* Kaiser-Meyer-Olkin Measure of Sampling Adequacy.(KMO) 0.350911931549742 *Got a R-function:-* ( http://www.opensubscriber.com/message/r-h...@stat.math.ethz.ch/2776549.html) kmo.test - function(df){ ### ## Calculate the Kaiser-Meyer-Olkin Measure of Sampling Adequacy. ## Input should be a data frame or matrix, output is the KMO statistic. ## Formula derived from Hutcheson et al, 1999, ## The multivariate social scientist, page 224, ISBN 0761952012 ## see http://www2.chass.ncsu.edu/garson/pa765/hutcheson.htmhttp://www2.chass.ncsu.edu/garson/pa765/hutcheson.htm%3E ### cor.sq = cor(df)^2 cor.sumsq = (sum(cor.sq)-dim(cor.sq)[1])/2 library(corpcor) pcor.sq = cor2pcor(cor(df))^2 pcor.sumsq = (sum(pcor.sq)-dim(pcor.sq)[1])/2 kmo = sus.cor.ss/(sus.cor.ss+sus.pcor.ss) return(kmo) } What is this object *sus.cor.ss*?I get errors sus.cor.ss Error: object sus.cor.ss not found Thanks in advance Moumita [[alternative HTML version deleted]] __ R-help@r-project.org 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] k-modes (Huang) in package klaR?
Dear R-Users and Developers, I want to calculate something like k-means clustering, but with ordinal data (Braun-Blanquet) to combine this classification technique with a NMDS-Ordination. I found an algorithm especially developed for categorical data: k-modes (Huang 1998). Is there a function implemented in R which can calculate with this algorithm. I found a hint on a poster-abstract from Gero Szepannek, Uwe Ligges and Claus Weihs. There it is stated that the algorithm is implemented in their package klaR. But I cannot find anything about k-modes in the klaR-Tutorial. Could you please help me. Thanks Kim -- GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT! __ R-help@r-project.org 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] Change directory to implement same programes
Hi, You can use list.files() of Sys.glob to get a listing of all the files in a certain directory, e.g. to get all .R files and source them: for(f in Sys.glob(C:/Documents and Settings/lma/*.R)) source(f) cheers, Paul Tammy Ma wrote: How do I source a bunch of files in different directories in R? From: metal_lical...@live.com To: r-help@r-project.org Date: Wed, 30 Sep 2009 13:45:34 +0300 Subject: [R] Change directory to implement same programes HI, R-Users, I have one problem: I have written the the programs which process all file in one directory: for example: setwd(C:/Documents and Settings/lma/My Documents/Vappu-saved/Log) as the start. .. But I have many folders like Vappu-saved and there are a lot of files in each directory. What I want is using the same program what I write for the above directory to autimatically change directory address to implement the above programs what I wrote. How do I realize it? Thanks a lot. Regards, Lingyi _ Windows Live™: Keep your life in sync. Check it out! http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t1_allup_explore_012009 [[alternative HTML version deleted]] _ Show them the way! Add maps and directions to your party invites. http://www.microsoft.com/windows/windowslive/products/events.aspx [[alternative HTML version deleted]] __ R-help@r-project.org 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. -- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://intamap.geo.uu.nl/~paul __ R-help@r-project.org 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/PL : cannot build PL/R
Wrong mailing list. Suggest reposting on R-SIG-Mac but only after re- reading the Posting Guide. On Sep 30, 2009, at 10:03 AM, Bunny, lautloscrew.com wrote: Dear all, i am trying to get PL / R running on Mac OS X. PostgreSQL is already running and connects just smoothly to R via DBI / RPostgreSQL . David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org 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] Condition to factor (easy to remember)
1. A common way of doing this is cut: cut(data, c(-Inf, 10, Inf), lab = levs, right = TRUE) [1] Pre Pre Pre Post Post Levels: Pre Post We don't actually need right=TRUE as its the default but if you omit it then it can be hard to remember whether the right end of intervals are included or excluded in the subdivision so I would recommend including it as a matter of course. Slightly less safe but if you knew the values were integral then another approach that would allow dropping the right= argument would be to use 10.5 as the breakpoint in which case the setting of right= does not matter anyways. 2. Similar to cut is findInterval so the subscripting of your first solution could be done via findInterval: levs[ findInterval(data, c(-Inf, 10), right = TRUE) ] [1] Pre Pre Pre Post Post The same comment regarding 10.5 applies. I've omitted the factor(...) part to focus on the difference and in the remaining examples have done that too. 3. Either of these could replace the ifelse. Both work by vectorizing an ordinary if but sapply is a more common way to do it so is likely preferable from the viewpoint of clarity. # 3a sapply(data, function(x) if (x = 10) levs[1] else levs[2]) [1] Pre Pre Pre Post Post # 3b Vectorize(function(x) if (x = 10) levs[1] else levs[2])(data) [1] Pre Pre Pre Post Post 4. The subscripting in your first solution could be done like this which is a bit longer but is arguably easier to understand: levs[ 1 * (data =10) + 2 * (data 10) ] [1] Pre Pre Pre Post Post On Wed, Sep 30, 2009 at 3:43 AM, Dieter Menne dieter.me...@menne-biomed.de wrote: Dear List, creating factors in a given non-default orders is notoriously difficult to explain in a course. Students love the ifelse construct given below most, but I remember some comment from Martin Mächler (?) that ifelse should be banned from courses. Any better idea? Not necessarily short, easy to remember is important. Dieter data = c(1,7,10,50,70) levs = c(Pre,Post) # Typical C-Programmer style factor(levs[as.integer(data 10)+1], levels=levs) # Easiest to understand factor(ifelse(data =10, levs[1], levs[2]), levels=levs) -- View this message in context: http://www.nabble.com/Condition-to-factor-%28easy-to-remember%29-tp25676411p25676411.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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@r-project.org 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] k-modes (Huang) in package klaR?
Kim Vanselow wrote: Dear R-Users and Developers, I want to calculate something like k-means clustering, but with ordinal data (Braun-Blanquet) to combine this classification technique with a NMDS-Ordination. I found an algorithm especially developed for categorical data: k-modes (Huang 1998). Is there a function implemented in R which can calculate with this algorithm. I found a hint on a poster-abstract from Gero Szepannek, Uwe Ligges and Claus Weihs. There it is stated that the algorithm is implemented in their package klaR. But I cannot find anything about k-modes in the klaR-Tutorial. Could you please help me. Dear Kim, well, maybe you start writing a message to the authors of that poster-abstract at first who might be able to help? Since I am one of those: Where can I find this abstract or poster (at least in order to remind Gero who does no longer work at the university to finally implement the feature, if it is not yet there)? Best wishes, Uwe Ligges Thanks Kim __ R-help@r-project.org 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] Optim(...) estimate of stDev far too low
Luis, I don't think that you want log() in fn. Try it with pdf=-sum(dnorm(x, media, st, TRUE)) (and note the x, rather than xx). -Peter Ehlers Luis Ridao Cruz wrote: R-help, I'm just trying to find the ML (maximum likelihood) estimates of the mean and standard deviation of a set of observations: xx=c(2.5,3.5,4,6,6.5,7.5) fn-function(params,x=xx) { media-params[1] st -params[2] pdf=-sum(dnorm(log(xx),log(media),st,TRUE)) return(pdf) } optim(c(mu,stdev),fn,method=L-BFGS-B,lower=c(0.001, 0.001) ,upper = rep(Inf, 2), hessian=TRUE, control=list(trace=1)) iter0 value 3.011784 final value 2.802694 converged $par [1] 4.6597779 0.3860387 $value [1] 2.802694 $counts function gradient 17 17 $convergence [1] 0 $message [1] CONVERGENCE: REL_REDUCTION_OF_F = FACTR*EPSMCH WHich gives an estimate of stDev = 0.38 while the empirical stDev = 1.94 Is there anything wrong above in the code? Thanks in advance __ R-help@r-project.org 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@r-project.org 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] Re cursive regression
Hi there, I'm in desperate need to figure out how to solve this issue. I need to estimate a recursive model for a time series data of asset returns. The dependent variable is the asset return and then I have a set of k variables, a lagged value of the dependent variable (plus an intercept) as regressors. My sample period (monthly observations) starts on Jan 1972. What I need to do is the following: 1)use a moving window regression (window of 60 observations, i.e. 5 years) 2)estimate all the possible model (Jan 1972 Dec 1977) using a subset of the k variables (intercept and lagged values always present) and choose the best model according to thee AIC criterion 3)once the best model is chosen, make one-step ahead prediction with that model 4)go back to step 2 shifting the sample period one month ahead (i.e. Feb 1972, Jan 1978) and then repeat step 2 and 3 5)keep going until the end of the sample (May 2009) Hope it helps -- View this message in context: http://www.nabble.com/Recursive-regression-tp25682804p25682804.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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] Managing random number generating, while using Condor parallel computing
Hello all, Recently I started playing with running R scripts on the Condor system in my institute. (For more on this, have a look at: Running Long R Jobs with Condor DAG by Xianhong Xie link: http://cran.r-project.org/doc/Rnews/Rnews_2005-2.pdf ) Might someone advice me about the following question: How should I handle the RNG (random number generation) in the running of parallel instances of R on different machines. For example, Let's say I wish to run 10 times a script that generates 100 normal variables and return their mean. The script itself is easy to write. What I am not sure about is what should I do with the seed. Should I let the program choose one for itself ? Should I set a seed according to some function of the current process ? Is there an outside source I should get the numbers from? Thanks, Tal -- My contact information: Tal Galili E-mail: tal.gal...@gmail.com Phone number: 972-52-7275845 FaceBook: Tal Galili My Blogs: http://www.talgalili.com (Web and general, Hebrew) http://www.biostatistics.co.il (Statistics, Hebrew) http://www.r-statistics.com/ (Statistics,R, English) [[alternative HTML version deleted]] __ R-help@r-project.org 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] k-modes (Huang) in package klaR?
Uwe Ligges wrote: Kim Vanselow wrote: Dear R-Users and Developers, I want to calculate something like k-means clustering, but with ordinal data (Braun-Blanquet) to combine this classification technique with a NMDS-Ordination. I found an algorithm especially developed for categorical data: k-modes (Huang 1998). Is there a function implemented in R which can calculate with this algorithm. I found a hint on a poster-abstract from Gero Szepannek, Uwe Ligges and Claus Weihs. There it is stated that the algorithm is implemented in their package klaR. But I cannot find anything about k-modes in the klaR-Tutorial. Could you please help me. Dear Kim, well, maybe you start writing a message to the authors of that poster-abstract at first who might be able to help? Since I am one of those: Where can I find this abstract or poster (at least in order to remind Gero who does no longer work at the university to finally implement the feature, if it is not yet there)? Some news on this: Gero never presented it in his talk at the useR!2008 and we all forgot that he announced it in his abstract. He is working for a bank these days and is going to send his code within a few days. Will take a look if it is easy to add the existing code to klaR then. Best wishes, Uwe Ligges Best wishes, Uwe Ligges Thanks Kim __ R-help@r-project.org 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] AsciiDoc and R
Hi, On Sep 30, 2009, at 7:57 AM, johannes rara wrote: I would like to learn AsciiDoc. Is there any good examples how to use AsciiDoc with R? I know that there is packages called ascii to do this, but it would be nice to see some examples how AsciiDoc works with R. Is there an AsciiDoc distribution for Max OS X? Perhaps this might help, too: http://learnr.wordpress.com/2009/09/29/wordpress-blogging-with-r-in-3-steps/ -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Read header csv file
Lucas, Although I can't answer all your questions, I can give some suggestions. I will assume you know how many years of data you have. Suppose it is 2004 through 2009. In each input file, the columns must have names, so I will assume there is a column named Month. I am not sure if you want all of your output in one file, or if you want one output file for each year. I am going to assume you want a separate output file for each year. I am going to assume that when you do the calculations for each month within each year, the results include two variables named r1 and pvalue (as in your example). Here is some example R code: ## make sure that R is working in the directory that contains the files ## this can be done from a menu in the R window, if you are using R in Windows or Macintosh, ## or by using the setwd() command setwd( directory where my files are ) years - 2004:2009 for (yr in years) { infile - paste(yr,'.csv',sep='') outfile - paste(yr,'.txt',sep='') clima - read.csv2(infile,nrows=7) ## open the output file for the current year sink(outfile) for (mn in unique(clima$Month)) { ## do calculations for the current month cat('Year: ', yr, ' Month:', mn, ' R1:', r1,' Pvalue:', pvalue,'\n') ## end of loop through months (in the current year) } ## close the output file. sink() ## end of loop through years } If you want all the output, including all the years, in a single file, then put the sink() commands outside the loop. Like this: years - 2004:2009 ## open the output file for writing sink(MyOutput.txt) for (yr in years) { infile - paste(yr,'.csv',sep='') clima - read.csv(infile,nrows=7) for (mn in unique(clima$Month)) { ## do calculations for the current month ## some results are in variables named r1 and pvalue cat('Year: ', yr, ' Month:', mn, ' R1:', r1,' Pvalue:', pvalue,'\n') ## end of loop through months (in the current year) } ## end of loop through years } ## close the output file. sink() A few comments: The sink() command must be given a file name, not a directory name. You had sink(directore where my text file is) You can try it first without the sink() commands, and see the results on your computer screen. This is a good way to make sure they are correct. Since you already know your file names, 2004.csv, 2005.csv, and so on, it is not necessary to use the dir() command to get them. And actually, better to use list.files(), not dir(). If you do use the list.files() or dir() command, try not to use it repeatedly inside a loop. It should be sufficient to it once outside the loop, for example: myfiles - list.files(directory where my files are) nfiles - length(myfiles) for (year in 1:nfiles) { filename - myfiles[[year]] ## and I'm pretty sure it should be myfiles[year], not [[year]] } Also, the way you did it assumes that the dir() command lists the files in the correct order, and it also assumes that there are no other files in the directory. If you want to run R in a different directory than the data files are in, you can change a few things. datadir - directory my files are in infiles - list.files( datadir, full.names=TRUE) nfiles - length(infiles) for ( i in 1:nfiles ) { clima - read.csv2(infiles[1], nrow=7) sink( paste('outfile',i,'.txt',sep='') ## loop over months ## do calculations ## do the cat() commands sink() } At 1:10 PM + 9/30/09, Lucas Sevilla García wrote: Hi R community, First of all, I want to thank everybody to share their time solving R questions, You are great. Ok, for my questions, I've been looking for a solutions by myself, in forums but I'm just a little bit desesperate so I hope somebody can help me. I have built a code to read files from a directory. These files are named by a year (2004.csv, 2005.csv,...). When the code reads first file (2004.csv), inside this file, there is information about precipitation of every months and I calculate different variables like R square adjusted, p value or formula fit to the data from linear regression. The code do more things but for my question, to explain what I need, that part of the code is enough. I want to export to the text file, year and month apart of some other variables, something like this: Year: 2004 Month: January R1: 0.98 Pvalue: 0.03 ... Year: 2004 Month: February R1:0.78 Pvalue:0.12 ... I've seen that I can use order sink() and cat(), so I would put those orders in my code, like this: nfiles- length(dir(directory where my files are)) #Count file number for(year in 1:nfiles)#Read first file { filename-dir()[[year]] #take first file and read filename, so if year is 1, then filename will be 2004, is year is 2, filename will be 2005,... clima-read.csv2(filename, nrows=7) #open 2004.csv So, if want to export year to my text file I would do for(year in
[R] Openning multiple (writing) connections to a single file - possible ?
Hello members of the R-help group. I am trying to run multiple occurences of R (through the distributed computing of Condor), and have all of them write their output into one source. It is similar (I believe), to running R several time on the same machine, and running on each instance of R the same script. In that script there is a line saying write some text into a file, and I wish it to be the same file. So at the end of the running I will have a single results file. Here is the code I tried to run (which didn't work) : con - file(output.txt, open = w) cat(write me, file=con, append = T) close(con) Any suggestions? Is it possible ? (or should I just write the output to many files, and at the end combine them to one big file) Thanks, Tal -- My contact information: Tal Galili E-mail: tal.gal...@gmail.com Phone number: 972-52-7275845 FaceBook: Tal Galili My Blogs: http://www.talgalili.com (Web and general, Hebrew) http://www.biostatistics.co.il (Statistics, Hebrew) http://www.r-statistics.com/ (Statistics,R, English) [[alternative HTML version deleted]] __ R-help@r-project.org 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] Overview of error and warning messages for teaching + examples
Hi Joris. This is a wonderlful idea. I never came across such a document, but assembaling it sounds very good. What do you think about organizing the work of collecting (by R members and maybe your students) the error massages and code into some wiki page? (maybe on the R wiki) It could be a great work to give to students (go around the mailing list, search for i got this error massage, and write what the code-problem-solution was). Best, Tal -- My contact information: Tal Galili E-mail: tal.gal...@gmail.com Phone number: 972-52-7275845 FaceBook: Tal Galili My Blogs: http://www.talgalili.com (Web and general, Hebrew) http://www.biostatistics.co.il (Statistics, Hebrew) http://www.r-statistics.com/ (Statistics,R, English) On Wed, Sep 30, 2009 at 2:50 PM, joris meys jorism...@gmail.com wrote: Dear all, The background: as I didn't find a manual specifically directed towards debugging R code on a novice and intermediate level, I decided to write a student manual myself. I have some basic examples of errors (the classical interpunction and writing mistakes), but have the feeling that I miss quite some of the frequently occuring mistakes and messages. Therefore I'm looking around to find a list of these, and if possible, some examples of wrong R code. I have been googling around a bit, but I couldn't find an overview of the most common error and warning messages in R. Off course this mailing list is an extensive source of all kind or errors and examples, but I was wondering if there is a somewhat more structured overview. All help appreciated. Kind regards Joris Meys __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org 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] Managing random number generating, while using Condor parallel computing
On Wed, Sep 30, 2009 at 05:02:15PM +0200, Tal Galili wrote: Might someone advice me about the following question: How should I handle the RNG (random number generation) in the running of parallel instances of R on different machines. http://lmgtfy.com/?q=site%3Ar-project.org+parallel+RNG -- Three out of two people have difficulties with fractions. __ R-help@r-project.org 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] Overview of error and warning messages for teaching + examples
Hi Tal, The Wiki is a great idea! Alas I'm not that familiar with setting up Wikis. Any idea how to practically approach this? I'm currently a bit in a hurry, as I have to give the introduction next monday. I'll have a first, basic introduction ready by the end of the week, but I'll continue to develop a more complete document later on. Naturally, this will be available for the internet community too. I'll keep you updated. On Wed, Sep 30, 2009 at 5:44 PM, Tal Galili tal.gal...@gmail.com wrote: Hi Joris. This is a wonderlful idea. I never came across such a document, but assembaling it sounds very good. What do you think about organizing the work of collecting (by R members and maybe your students) the error massages and code into some wiki page? (maybe on the R wiki) It could be a great work to give to students (go around the mailing list, search for i got this error massage, and write what the code-problem-solution was). Best, Tal -- My contact information: Tal Galili E-mail: tal.gal...@gmail.com Phone number: 972-52-7275845 FaceBook: Tal Galili My Blogs: http://www.talgalili.com (Web and general, Hebrew) http://www.biostatistics.co.il (Statistics, Hebrew) http://www.r-statistics.com/ (Statistics,R, English) On Wed, Sep 30, 2009 at 2:50 PM, joris meys jorism...@gmail.com wrote: Dear all, The background: as I didn't find a manual specifically directed towards debugging R code on a novice and intermediate level, I decided to write a student manual myself. I have some basic examples of errors (the classical interpunction and writing mistakes), but have the feeling that I miss quite some of the frequently occuring mistakes and messages. Therefore I'm looking around to find a list of these, and if possible, some examples of wrong R code. I have been googling around a bit, but I couldn't find an overview of the most common error and warning messages in R. Off course this mailing list is an extensive source of all kind or errors and examples, but I was wondering if there is a somewhat more structured overview. All help appreciated. Kind regards Joris Meys __ R-help@r-project.org 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@r-project.org 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] Managing random number generating, while using Condor parallel computing
Thanks/Sorry Dirk. After some more searches I found: http://cran.r-project.org/web/packages/rsprng/index.html With a nice explenation about it here: http://wiki.r-project.org/rwiki/doku.php?id=packages:cran:rsprng Thanks/Sorry again, Tal -- My contact information: Tal Galili E-mail: tal.gal...@gmail.com Phone number: 972-52-7275845 FaceBook: Tal Galili My Blogs: http://www.talgalili.com (Web and general, Hebrew) http://www.biostatistics.co.il (Statistics, Hebrew) http://www.r-statistics.com/ (Statistics,R, English) On Wed, Sep 30, 2009 at 5:56 PM, Dirk Eddelbuettel e...@debian.org wrote: On Wed, Sep 30, 2009 at 05:02:15PM +0200, Tal Galili wrote: Might someone advice me about the following question: How should I handle the RNG (random number generation) in the running of parallel instances of R on different machines. http://lmgtfy.com/?q=site%3Ar-project.org+parallel+RNG -- Three out of two people have difficulties with fractions. [[alternative HTML version deleted]] __ R-help@r-project.org 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] Scaling data
Hello all I am manipulating some data and wish to expand/unmerge (i.e. do the opposite of aggregate) rows in a data matrix based on the values in a particular column and a seperator, e.g. Col1Col2 n1;n2 6 ...separating by ; becomes Col1Col2 num16 num26 Any ideas? Also can I do this based on values in two columns? EG: Col1Col2Col3 n1;n2 ID1;ID2 6 ...becomes Col1Col2Col3 n1 ID1 6 n2 ID2 6 ? -- AstraZeneca UK Limited is a company incorporated in Engl...{{dropped:21}} __ R-help@r-project.org 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] Macro variable substitution
There was a rather in depth article on doing macros in R in the R newsletter a couple of years ago. There is also the defmacro function in the gtools package based on that article that can make the job easier for many cases. See fortune(236) before taking the assign route. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of David Young Sent: Tuesday, September 29, 2009 9:58 AM To: r-help@r-project.org Subject: [R] Macro variable substitution Hello All, I'm a new R user and have a question about what in SAS would be called macro variable substitution. Below is some R code that doesn't work, but I think it will illustrate what I'd like to do. readfunc-function(x) { x - read.table(paste(x,.csv,sep=), header=TRUE,sep=,) } readfunc(TEF) What I'd like to do is have the letters TEF become the name of the new R data and also be used in conjunction with .csv to read the file TEF.csv. So working R code looks like this: TEF - read.table(TEF.csv, header=TRUE,sep=,) but I'd like to type the changing letter sequence just once. Any suggestions would be appreciated. -- Best regards, David Young Marketing and Statistical Consultant Madrid, Spain +34 913 540 381 http://www.linkedin.com/in/europedavidyoung __ R-help@r-project.org 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@r-project.org 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] extract clusters from a hclusrt object without cutree
Hello, I am generating an hclust() object and want to extract a subset of clusters WITHOUT using cutree(). I see this somehow involves using the $merge matrix to associate $labels into their appropriate clusters where clusters are split below a given $height threshold. Can anyone suggest a way/code to do this? I see cutree uses embedded fortran code, so it's not obvious how cutree does it thanks Tony __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] error in function AMER
Dear all, I am trying to reproduce the example in the vignette Using lme4 to fit Generalized Additive Mixed Models with my dataset. But... exemplo - read.table(exemplo.dat,header=T) mod - amer(pasvig ~ -1 + harvf + tp(dias,by=harvf) + (1 | pac), data=exemplo) Erro em if (from == to) rep.int(from, length.out) else as.vector(c(from, : valor ausente onde TRUE/FALSE necessário A subset of the dataset is below. No clue about what is wrong. Thanks a lot! Marilia pasvig dias harvf pac 124 0 HRJB 1 125 473 HRJB 1 125 888 HRJB 1 136 1272 HRJB 1 161 1614 HRJB 1 133 0 HRV 2 151 716 HRV 2 127 850 HRV 2 141 1137 HRV 2 135 1382 HRV 2 168 0 HRV 3 140 169 HRV 3 140 555 HRV 3 137 1259 HRV 3 147 1524 HRV 3 150 1842 HRV 3 133 1982 HRV 3 160 0 HRV 4 159 417 HRV 4 137 790 HRV 4 173 1146 HRV 4 149 1761 HRV 4 165 2135 HRV 4 142 2415 HRV 4 137 0 HRV 5 144 420 HRV 5 145 842 HRV 5 127 0 HRJB 6 124 365 HRJB 6 122 762 HRJB 6 138 1134 HRJB 6 124 1561 HRJB 6 133 0 HRV 7 116 502 HRV 7 142 1474 HRV 7 170 0 HRV 8 151 400 HRV 8 132 577 HRV 8 114 1169 HRV 8 146 1547 HRV 8 110 1904 HRV 8 156 0 HRV 9 132 1370 HRV 9 154 1784 HRV 9 148 2318 HRV 9 148 0 HRV 10 110 520 HRV 10 123 924 HRV 10 130 1640 HRV 10 142 2075 HRV 10 158 0 HRV 11 166 274 HRV 11 159 1059 HRV 11 150 0 HRV 12 140 333 HRV 12 121 704 HRV 12 138 1225 HRV 12 110 1406 HRV 12 151 0 HRV 13 179 318 HRV 13 167 913 HRV 13 181 1261 HRV 13 131 0 HRJB 14 123 630 HRJB 14 136 1038 HRJB 14 138 1463 HRJB 14 133 1757 HRJB 14 119 2158 HRJB 14 144 0 HRV 15 150 418 HRV 15 145 659 HRV 15 141 1099 HRV 15 133 1336 HRV 15 150 1757 HRV 15 140 0 HRV 16 127 432 HRV 16 118 NA HRV 16 151 0 HRV 17 140 720 HRV 17 150 1455 HRV 17 156 0 HRV 18 144 402 HRV 18 152 807 HRV 18 139 1163 HRV 18 127 1575 HRV 18 126 0 HRV 19 141 997 HRV 19 143 1505 HRV 19 153 1843 HRV 19 123 2023 HRV 19 135 0 HRV 20 128 357 HRV 20 135 880 HRV 20 151 1561 HRV 20 153 1952 HRV 20 131 2364 HRV 20 122 0 HRJB 21 141 462 HRJB 21 136 1224 HRJB 21 132 1757 HRJB 21 __ R-help@r-project.org 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] Scaling data
Try this: as.data.frame(sapply(sapply(DF, as.character, simplify = FALSE), strsplit, ;)) On Wed, Sep 30, 2009 at 1:18 PM, Dry, Jonathan R jonathan@astrazeneca.com wrote: Hello all I am manipulating some data and wish to expand/unmerge (i.e. do the opposite of aggregate) rows in a data matrix based on the values in a particular column and a seperator, e.g. Col1 Col2 n1;n2 6 ...separating by ; becomes Col1 Col2 num1 6 num2 6 Any ideas? Also can I do this based on values in two columns? EG: Col1 Col2 Col3 n1;n2 ID1;ID2 6 ...becomes Col1 Col2 Col3 n1 ID1 6 n2 ID2 6 ? -- AstraZeneca UK Limited is a company incorporated in Engl...{{dropped:21}} __ R-help@r-project.org 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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org 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] bwplot scales in alphabetical order
Peter, Thanks, that did it! Tim Tim Clark Department of Zoology University of Hawaii --- On Wed, 9/30/09, Peter Ehlers ehl...@ucalgary.ca wrote: From: Peter Ehlers ehl...@ucalgary.ca Subject: Re: [R] bwplot scales in alphabetical order To: Tim Clark mudiver1...@yahoo.com Cc: r-help@r-project.org Date: Wednesday, September 30, 2009, 2:43 AM Tim, Add the argument as.table=TRUE to your call: bwplot(y~x|id, horizontal=FALSE, as.table=TRUE) Peter Ehlers Tim Clark wrote: Dear List, I know this has been covered before, but I don't seem to be able to get it right. I am constructing a boxplot in lattice and can't get the scales in the correct alphebetical order. I have already read that this is due to the way factors are treated, and I have to redefine the levels of the factors. However, I have failed. As a simple example: library(lattice) id-rep(letters[1:9], each=20) x-rep(seq(1:10),each=18) y-rnorm(180,50,20) #Reverse alphebetical order bwplot(y~x|id, horizontal=FALSE) #alphebetical order reading right to left id-factor(id,levels = sort(id,decreasing = TRUE)) bwplot(y~x|id, horizontal=FALSE) It appears that bwplot plots scales from the bottom left to the top right. If so my factor levels would need to be levels=c(7,8,9,4,5,6,1,2,3). I tried that but can't seem to get the factor function to work. #Did not work! id-factor(id,levels=c(7,8,9,4,5,6,1,2,3),lables=letters[1:9]) Your help would be greatly appreciated. Tim Tim Clark Department of Zoology University of Hawaii __ R-help@r-project.org 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@r-project.org 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 visualize gini coefficient in each node in RF?
You can try to hunt for it in the findbestsplit Fortran subroutine. It uses some thing that's equivalent (but easier to compute), not exactly identical. Breiman uses whatever computational shortcuts he could find in his code. Best, Andy From: Chrysanthi A. [mailto:chrys...@gmail.com] Sent: Tuesday, September 29, 2009 4:55 PM To: Liaw, Andy Cc: r-help@r-project.org Subject: Re: [R] how to visualize gini coefficient in each node in RF? Thanks for the reply! However, what is the code that is used in order to calculate it.. Is it included in the randomForest R function.. Because I am trying to find the code corresponding to the estimation of the gini coefficient but I am a bit confused. Could you please help me, by indicating me that? thanks a lot, chrysanthi 2009/9/29 Liaw, Andy andy_l...@merck.com No. The forest object is too large as is. I didn't think it's worth the extra memory to store them. They were never kept even in the Fortran/C code. Andy From: Chrysanthi A. Sent: Monday, September 28, 2009 5:20 PM To: r-help@r-project.org Subject: [R] how to visualize gini coefficient in each node in RF? Dear all, I am working with randomForest package and I am interested in examining the Gini importance measures that are used as a general indicator of feature relevance. Is there a possibility of getting the Gini measure that is being estimated in each tree by the output of the getTree() function? Thanks a lot, Chrysanthi [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Notice: This e-mail message, together with any attachments, contains information of Merck Co., Inc. (One Merck Drive, Whitehouse Station, New Jersey, USA 08889), and/or its affiliates (which may be known outside the United States as Merck Frosst, Merck Sharp Dohme or MSD and in Japan, as Banyu - direct contact information for affiliates is available at http://www.merck.com/contact/contacts.html) that may be confidential, proprietary copyrighted and/or legally privileged. It is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please notify us immediately by reply e-mail and then delete it from your system. Notice: This e-mail message, together with any attachme...{{dropped:15}} __ R-help@r-project.org 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] start a script directly under windows
hi, I try to configure my system so when I click on an .R script, the script is executed in the R GUI. I tried to open .R files with different .exe files that I found in the bin-folder of the R folder (R.exe, Rcmd.exe, Rgui.exe ...). But I always get the message; ARGUMENT 'c:\...\...' ___ignored___ (where c:\...\.. is the path to the .R file) how can I change this behavior? Sorry I am not so familiar with windows OS (I use windows xp). thanks for any help! __ R-help@r-project.org 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] change axis labels in persp
I need to change one of the axis produced by persp by giving it labels for the tickmarks. The dimension has months (a factor) so the default decimals don't look good. The graph will finally become a pdf or emf file to be embedded in a document, so persp3d will not work, I think. Thank you all. Stephen [[alternative HTML version deleted]] __ R-help@r-project.org 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] Rounding error in seq(...)
Hi, Today I was flabbergasted to see something that looks like a rounding error in the very basic seq function in R. a = seq(0.1,0.9,by=0.1) a [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 a[1] == 0.1 [1] TRUE a[2] == 0.2 [1] TRUE a[3] == 0.3 [1] FALSE It turns out that the alternative a = (1:9)/10 works just fine. Are there any good guides out there on how to deal with issues like this? I am normally aware of rounding errors, but it really surprised me to see that an elementary function like seq would behave in this way. Thanks, Michael Knudsen -- Michael Knudsen micknud...@gmail.com http://sites.google.com/site/micknudsen/ __ R-help@r-project.org 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] Rounding error in seq(...)
On 9/30/2009 2:40 PM, Michael Knudsen wrote: Hi, Today I was flabbergasted to see something that looks like a rounding error in the very basic seq function in R. a = seq(0.1,0.9,by=0.1) a [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 a[1] == 0.1 [1] TRUE a[2] == 0.2 [1] TRUE a[3] == 0.3 [1] FALSE It turns out that the alternative a = (1:9)/10 works just fine. Are there any good guides out there on how to deal with issues like this? I am normally aware of rounding errors, but it really surprised me to see that an elementary function like seq would behave in this way. Why? You asked for an increment of 1 in the second case (which is exactly represented in R), then divided by 10, so you'll get the same as 0.3 gives you. In the seq() case you asked for an increment of a number close to but not equal to 1/10 (because 1/10 is not exactly representable in R), so you got something different. Duncan Murdoch __ R-help@r-project.org 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] Rounding error in seq(...)
On Wed, Sep 30, 2009 at 8:44 PM, Duncan Murdoch murd...@stats.uwo.ca wrote: Why? You asked for an increment of 1 in the second case (which is exactly represented in R), then divided by 10, so you'll get the same as 0.3 gives you. In the seq() case you asked for an increment of a number close to but not equal to 1/10 (because 1/10 is not exactly representable in R), so you got something different. Well, the problem is that I don't know how seq is implemented. I just assumed that it wouldn't behave like this. -- Michael Knudsen micknud...@gmail.com http://sites.google.com/site/micknudsen/ __ R-help@r-project.org 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] Rounding error in seq(...)
Inline Below. Bert Gunter Nonclinical Biostatistics 467-7374 http://devo.gene.com/groups/devo/depts/ncb/home.shtml -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Michael Knudsen Sent: Wednesday, September 30, 2009 11:50 AM To: Duncan Murdoch Cc: r help Subject: Re: [R] Rounding error in seq(...) On Wed, Sep 30, 2009 at 8:44 PM, Duncan Murdoch murd...@stats.uwo.ca wrote: Why? You asked for an increment of 1 in the second case (which is exactly represented in R), then divided by 10, so you'll get the same as 0.3 gives you. In the seq() case you asked for an increment of a number close to but not equal to 1/10 (because 1/10 is not exactly representable in R), so you got something different. Well, the problem is that I don't know how seq is implemented. I just assumed that it wouldn't behave like this. -- This represents common misconceptions about the nature of floating point computations/finite precision arithmetic. See 7.31 in the R FAQ. You may wish to Google/Wikipedia on floating point computation or something similar for more info. -- Bert __ R-help@r-project.org 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] Rounding error in seq(...)
On 9/30/2009 2:50 PM, Michael Knudsen wrote: On Wed, Sep 30, 2009 at 8:44 PM, Duncan Murdoch murd...@stats.uwo.ca wrote: Why? You asked for an increment of 1 in the second case (which is exactly represented in R), then divided by 10, so you'll get the same as 0.3 gives you. In the seq() case you asked for an increment of a number close to but not equal to 1/10 (because 1/10 is not exactly representable in R), so you got something different. Well, the problem is that I don't know how seq is implemented. I just assumed that it wouldn't behave like this. It doesn't really matter how it is implemented: if you ask to start at 0.1 and increment by 0.1, you should expect the result to be the same as 0.1 0.1+0.1 0.1+0.1+0.1 etc. and I think it is. The problem is that 0.1+0.1+0.1 is not the same as 0.3, due to rounding. Neither 0.1 nor 0.3 can be represented exactly in the standard IEEE floating point formats that R uses. Duncan Murdoch __ R-help@r-project.org 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] Rounding error in seq(...)
hum, can you explain that a little more detailed? Perhaps I miss the background knowledge - but it seems just absurd to me. 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there? why is x - 0.1 + 0.1 +0.1 not equal to y - 0.3 ? Am 30.09.2009 um 21:04 schrieb Duncan Murdoch: On 9/30/2009 2:50 PM, Michael Knudsen wrote: On Wed, Sep 30, 2009 at 8:44 PM, Duncan Murdoch murd...@stats.uwo.ca wrote: Why? You asked for an increment of 1 in the second case (which is exactly represented in R), then divided by 10, so you'll get the same as 0.3 gives you. In the seq() case you asked for an increment of a number close to but not equal to 1/10 (because 1/10 is not exactly representable in R), so you got something different. Well, the problem is that I don't know how seq is implemented. I just assumed that it wouldn't behave like this. It doesn't really matter how it is implemented: if you ask to start at 0.1 and increment by 0.1, you should expect the result to be the same as 0.1 0.1+0.1 0.1+0.1+0.1 etc. and I think it is. The problem is that 0.1+0.1+0.1 is not the same as 0.3, due to rounding. Neither 0.1 nor 0.3 can be represented exactly in the standard IEEE floating point formats that R uses. Duncan Murdoch __ R-help@r-project.org 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@r-project.org 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] Rounding error in seq(...)
On Wed, Sep 30, 2009 at 8:40 PM, Michael Knudsen micknud...@gmail.com wrote: a = seq(0.1,0.9,by=0.1) a [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 a[1] == 0.1 [1] TRUE a[2] == 0.2 [1] TRUE a[3] == 0.3 [1] FALSE A friend of mine just pointed out a possible solution: a=seq(0.1,0.9,by=0.1) a = seq(0.1,0.9,by=0.1) a[3]==0.3 [1] FALSE all.equal(a[3],0.3) [1] TRUE The all.equal function checks if two objects are nearly equal. -- Michael Knudsen micknud...@gmail.com http://sites.google.com/site/micknudsen/ __ R-help@r-project.org 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] Rounding error in seq(...)
On 9/30/2009 3:17 PM, Martin Batholdy wrote: hum, can you explain that a little more detailed? Perhaps I miss the background knowledge - but it seems just absurd to me. 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there? R uses a binary floating point storage format, which is the standard thing to do in most languages. Numbers which are fractions like 1/2, 1/4 and 57/128 are all representable exactly, because the denominator is a power of 2. Whole numbers are also representable exactly. However, numbers like 1/10 are not. So R stores something slightly different from 1/10 when you say x - 0.1. If you compare it to 1/10, then it comes out equal, because you're comparing to the same slightly incorrect value. However, by the time you add up 3 of them, the rounding error accumulates, and you get a different answer than you'd get from 3/10, which is the same as 0.3. Duncan Murdoch why is x - 0.1 + 0.1 +0.1 not equal to y - 0.3 ? Am 30.09.2009 um 21:04 schrieb Duncan Murdoch: On 9/30/2009 2:50 PM, Michael Knudsen wrote: On Wed, Sep 30, 2009 at 8:44 PM, Duncan Murdoch murd...@stats.uwo.ca wrote: Why? You asked for an increment of 1 in the second case (which is exactly represented in R), then divided by 10, so you'll get the same as 0.3 gives you. In the seq() case you asked for an increment of a number close to but not equal to 1/10 (because 1/10 is not exactly representable in R), so you got something different. Well, the problem is that I don't know how seq is implemented. I just assumed that it wouldn't behave like this. It doesn't really matter how it is implemented: if you ask to start at 0.1 and increment by 0.1, you should expect the result to be the same as 0.1 0.1+0.1 0.1+0.1+0.1 etc. and I think it is. The problem is that 0.1+0.1+0.1 is not the same as 0.3, due to rounding. Neither 0.1 nor 0.3 can be represented exactly in the standard IEEE floating point formats that R uses. Duncan Murdoch __ R-help@r-project.org 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@r-project.org 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] Rounding error in seq(...)
On 1/10/2009, at 8:17 AM, Martin Batholdy wrote: hum, can you explain that a little more detailed? Perhaps I miss the background knowledge - but it seems just absurd to me. 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there? why is x - 0.1 + 0.1 +0.1 not equal to y - 0.3 ? You have told the answer already, several times. ***FLOATING POINT ARITHMETIC If you still don't understand, read up on it. Start by looking at the FAQ. cheers, Rolf Turner ## Attention:\ This e-mail message is privileged and confid...{{dropped:9}} __ R-help@r-project.org 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] Rounding error in seq(...)
Martin Batholdy wrote: hum, can you explain that a little more detailed? Perhaps I miss the background knowledge - but it seems just absurd to me. 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there? why is x - 0.1 + 0.1 +0.1 not equal to y - 0.3 Remember that this is in BINARY arithmetic. It's really not any stranger than the fact that 1/3 + 1/3 != 2/3 in finite accuracy decimal arithmetic (0.3 + 0.3 = 0.6 != 0.7). -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ R-help@r-project.org 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] Condition to factor (easy to remember)
An extremely verbose, but (in my view) easy to understand approach is: data.f - data; data.f[which(data = 10)] - levs[1]; data.f[which(data 10)] - levs[2]; data.f - factor(data.f) -Ista On Wed, Sep 30, 2009 at 8:31 AM, Dieter Menne dieter.me...@menne-biomed.de wrote: David Winsemius wrote: # Typical C-Programmer style factor(levs[as.integer(data 10)+1], levels=levs) In your code the as.integer function is superfluous Oops... done too much c# lately, getting invalid cast challenged. Dieter -- View this message in context: http://www.nabble.com/Condition-to-factor-%28easy-to-remember%29-tp25676411p25680111.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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. -- Ista Zahn Graduate student University of Rochester http://yourpsyche.org __ R-help@r-project.org 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] Rounding error in seq(...)
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Martin Batholdy Sent: Wednesday, September 30, 2009 12:18 PM To: Duncan Murdoch Cc: r help Subject: Re: [R] Rounding error in seq(...) hum, can you explain that a little more detailed? Perhaps I miss the background knowledge - but it seems just absurd to me. 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there? why is x - 0.1 + 0.1 +0.1 not equal to y - 0.3 Let's do this in base 10, since it is more familiar. Suppose we decide, for efficiency reasons to store all numbers to 2 significant decimal digits. Then 1/3 gets stored as 0.33 and stored(1/3)+stored(1/3)+stored(1/3) is stored(0.99), not 1.0. (Here stored() is the function that maps a number to the 2 decimal digit number closest to it.) For efficiency reasons standard computer representation of number with fractional part involves 52 significant binary digits. 1/10 in base 10 is like 1/3 in base 2: it cannot be represented exactly with 52 significant binary digits. Hence we cannot expect that as.double(1/10)+ 8 reps +as.double(1/10) will be exactly 1.0. (Here, as.double is not the R function but the mathematical function that maps a number to the double precision number closest to it.) Bill Dunlap TIBCO Software Inc - Spotfire Division wdunlap tibco.com ? Am 30.09.2009 um 21:04 schrieb Duncan Murdoch: On 9/30/2009 2:50 PM, Michael Knudsen wrote: On Wed, Sep 30, 2009 at 8:44 PM, Duncan Murdoch murd...@stats.uwo.ca wrote: Why? You asked for an increment of 1 in the second case (which is exactly represented in R), then divided by 10, so you'll get the same as 0.3 gives you. In the seq() case you asked for an increment of a number close to but not equal to 1/10 (because 1/10 is not exactly representable in R), so you got something different. Well, the problem is that I don't know how seq is implemented. I just assumed that it wouldn't behave like this. It doesn't really matter how it is implemented: if you ask to start at 0.1 and increment by 0.1, you should expect the result to be the same as 0.1 0.1+0.1 0.1+0.1+0.1 etc. and I think it is. The problem is that 0.1+0.1+0.1 is not the same as 0.3, due to rounding. Neither 0.1 nor 0.3 can be represented exactly in the standard IEEE floating point formats that R uses. Duncan Murdoch __ R-help@r-project.org 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@r-project.org 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@r-project.org 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.