[R] Cran package directory 404 error since 30th December
I have been getting a object not found error trying to access the CRAN package directory since the 30th December. I have tried several mirrors with the same error. A search here only shows a single question on this from anyone else (on the 30th December) which wasn't answered. I am surprised that there hasn't been more comment on this. Is there an announcement somewhere about this that I have missed, that say CRAN packages is down for maintenance or some other planned down time. Many thanks, Graham [[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] bmp() shifts the image (Windows XP)
Thanks Duncan for your help. Bill On 1/1/12, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 12-01-01 9:05 AM, William Simpson wrote: When using bmp() under Windows XP, I find that the saved image is a shifted version of the correct image. Try this: The image() function isn't designed to be able to do pixel-level addressing, so it's not too surprising that some rounding error somewhere leads to this. You could look through the Windows graphics device code to fix it. However, if you really need pixel level addressing, you should be using raster objects. I don't know if someone has written code to output a .bmp file, but it's a very simple format, so it shouldn't be too hard, especially if you only need a limited range of pixel formats (e.g. grayscale). Duncan Murdoch n-5 fn-01.bmp x-matrix(runif(n*n),nrow=n) image(x,col=gray(0:255/255),axes=F,frame.plot=F) bmp(filename = fn,width = n, height = n, units = px) par(mar=c(0,0,0,0),pty=s) image(x,col=gray(0:255/255),axes=F,frame.plot=F) dev.off() The image 01.bmp is like this: 22 23 24 25 w 32 33 34 35 w 42 43 44 45 w 52 53 54 55 w w w w w w w Where 22 represents x[2,2], etc; w represents a white pixel. For my application, the image has to be .bmp format. The same shifting behaviour is seen for large values of n. It is not just due to the small n value. For my application, this shifting is important and has to be eliminated. Please help. On an unrelated note, I found out that the bmp() code is smart enough to write my image as 8-bit using a palette instead of 24-bit with 0:255 grey levels if the image being saved does not use all 256 grey levels. I would love to hear it if somebody knows a good way to make bmp() stupid and always save as 24-bit. My kludge, using 256x256 pixel images, is to tack on an extra row with grey levels 0:255. Then when displaying, I have to crop the image to get rid of that bogus row. Thanks very much for any help! Bill __ 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] Cran package directory 404 error since 30th December
On 02/01/2012 08:17, Graham Smith wrote: I have been getting a object not found error trying to access the CRAN package directory since the 30th December. I have tried several mirrors with the same error. A search here only shows a single question on this from anyone else (on the 30th December) which wasn't answered. I am surprised that there hasn't been more comment on this. Is there an announcement somewhere about this that I have missed, that say CRAN packages is down for maintenance or some other planned down time. You missed the thread on R-devel. The short answer is that this needs someone in Vienna to fix (people do have vacations and take weekends off), and that the web/packages directory is pure sugar: the packages are still there, the check results are there ... just the summary pages are missing and they are accessible via one (at least) of the mirrors. The person whose message here was unanswered bombarded many people, including CRAN and me personally, so did get several replies. Many thanks, Graham [[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. That means you: no HTML mail -- 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.
[R] Percentage scale on y-axis
Seasonal Greetings! I am trying to plot a simple survival curve using; plot(survfit(Surv(d01,cens) ,conf.type=none ),xlab=Time,ylab=Survival) I would be interested in a percentage scale on the y-axis. How do I achieve sucha scale? Thank you 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] clear plot linear mixed model
Hi, first a happy new year ;) I would like to plot the regression lines of a model like lme - lme(conc ~ name/time - 1, random=conc~time|nr,method=ML,data=measurements) Ideally a seperate plot for each regression line (respectively name) and seperate colors for the measurements (nr). How would you do that? thx Christof __ 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 on Android
Ken Hutchison schrieb: If stranded on a desert island and getting R fully functional on Droid would save you, I'd advise looking for food; else be prepared to name your phone Wilson. Ken Hutchison I propose to add that to fortunes :-D Andreas Borg -- Andreas Borg Abteilung Medizinische Informatik Universitätsmedizin der Johannes Gutenberg-Universität Mainz Institut für Med. Biometrie, Epidemiologie und Informatik (IMBEI) Obere Zahlbacher Straße 69, 55131 Mainz Tel: +49 (0) 6131 17-5062 E-Mail: andreas.b...@uni-mainz.de __ 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] clear plot linear mixed model
Christof Kluß ckluss at email.uni-kiel.de writes: I would like to plot the regression lines of a model like lme - lme(conc ~ name/time - 1, random=conc~time|nr,method=ML,data=measurements) Ideally a seperate plot for each regression line (respectively name) and seperate colors for the measurements (nr). How would you do that? thx Christof see plot.augPred in the nlme package -- 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.
Re: [R] R report generator (for Word)?
On 01/01/12 15:50, Michael wrote: Happy New Year all! I am looking for a good solution for keeping record of my experiments - could you please help me? My work is about analysing data... My current work-flow: 1. Everyday my bosses give me some small steps/tasks for analysing data - which are parts of one bigger/whole project. 2. Everyday I send tens of emails to bosses/colleagues to report my findings in each step. 3. Bosses/colleagues often respond to my findings in real-time and suggest new experiments/steps and ask what-if questions. 4. I often have to manually copy and paste the results from R console and put them into an Excel and decorate a bit and send out. 5. Every one week and 2 weeks, we need to present to more senior bosses with more nice-looking presentations which is a summary of our findings in those 1-2 weeks. It's this time that is most chaotic because my colleagues and I have to dig into all the hundreds of emails in the past 1-2 weeks and copy and paste and organize those data again and make a nice overall summary for presentation... 6. As I am a hard-working guy, I myself often run my own random/ad-hoc experiments using out-of-work time and whenever I have interesting findings, I will send to immediate bosses and colleagues to seek their comments. 7. All these experiments are in fact variations of different versions/ideas of one big/whole project. Lets say in one big project bosses/colleagues and I have come up with a few big ideas, then we have a few sub-projects: MyProjectIdea1 MyProjectIdea2 ... MyProjectIdeaN And each idea has a few variations, mostly are for answering what-if questions by varying the parameters here and there ... For example: MyProjectIdea1_Variation1_WhatIfParam1ChangedTo1.2? ... ... etc. 8. Most experiments run tens of minutes to many hours... and some of them have to run on Linux, and some others can be run on Windows. Fortunately we have universal paths accessible on both Windows and Linux, so those won't be problem... 9. Because of the time-consuming nature of these experiments, I also save the images as rData whenever I can. However, it's necessary to keep track of the context where these data were generated. Otherwise even the records of these images won't help recall the scenario we have run... --- Keeping track of these changes and all kinds of what-ifs now becomes increasingly a problem for me. Some times in order to respond to a query, although I have done it before already, but because I didn't keep record and save the result, or even though I have saved the memory image yet I am not completely sure about the cleanness of the results/data,I have to redo it and wait for another few hours. Is there a way that I can manage these whole processes better and be more productive? I have been digging and thinking about this for while and I guess Sweave is the right way to go? I would agree that Sweave is a good way to organise these kind of analysis that you do repetitively. I would also recomend you look at some of the caching methods available (CacheSweave http://cran.r-project.org/web/packages/cacheSweave/index.html ) will allow you to skip chunks of the analysis that haven't changed since the last run. The problem for Sweave is that it's hard to make Latex generated pdf appealing to business managers... so if I keep records in Sweave/Latex for my own record/benefit (that's already a big benefit)... I still need to somehow manually copy/paste the data from Sweave/Latex/pdf into Word/Excel/Powerpoint in order to make a nice presentation... I know there are some Open Office and Word version of Sweave... the problem is that I couldn't find many demonstrations on these topics and my question is: are they good and can they fulfill what we needed? For Open Office have a look at the odfWeave package ( http://cran.r-project.org/web/packages/odfWeave/index.html ) that functions in a similar way to Sweave but starts with and produces an odt Open Doc text file. I have used it in the past but not recently, although I vaguely remember seeing a post recently that the current version doesn't compile on Windows, so that may curtail it's effectiveness. regards, 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] Cran package directory 404 error since 30th December
Thanks Brian, The short answer is that this needs someone in Vienna to fix (people do have vacations and take weekends off), and that the web/packages directory is pure sugar: the packages are still there, the check results are there ... just the summary pages are missing and they are accessible via one (at least) of the mirrors. The person whose message here was unanswered bombarded many people, including CRAN and me personally, so did get several replies. I'm not subscribed to R-devel, and usually just sit and wait for these things to sort themselves out. Generally, even during holiday periods this sort of thing get sorted amazingly quickly, but I was puzzled by the lack of comment. suggesting it may be some DNS look up error at my end. It came to light when browsing he task views and then wanting to read the manual for a particular package, but getting a 404 when I clicked the link. I was obviously un lucky with the mirrors I tried. Any thanks again. Graham [[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] R report generator (for Word)?
The html route is one I have used quite a lot, but rather than R2HTML I far prefer hwriter. I have spent some time on enhancing hwriter and you can find my hwriterPlus on R-forge. It has fairly extensive examples and a vignette in the inst directory. I am still working on some improvements to the package. David Scott From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] on behalf of Joshua Wiley [jwiley.ps...@gmail.com] Sent: Monday, January 02, 2012 9:31 AM To: Michael Cc: r-help Subject: Re: [R] R report generator (for Word)? Hi Michael, I like Sweave and LaTeX, but I can appreciate the difficulty using it with collaborators. What about something similar using HTML? Certainly integrates to any webpages nicely. There are two packages I think do this nicely, one is the R2HTML package (on CRAN). Another one that is not on CRAN yet, but I think has a lot of potential is the knitr package. You can find it on github. I am not personally familiar with any good ways to integrate R with MS Office products. Cheers, Josh On Sun, Jan 1, 2012 at 7:50 AM, Michael comtech@gmail.com wrote: Happy New Year all! I am looking for a good solution for keeping record of my experiments - could you please help me? My work is about analysing data... My current work-flow: 1. Everyday my bosses give me some small steps/tasks for analysing data - which are parts of one bigger/whole project. 2. Everyday I send tens of emails to bosses/colleagues to report my findings in each step. 3. Bosses/colleagues often respond to my findings in real-time and suggest new experiments/steps and ask what-if questions. 4. I often have to manually copy and paste the results from R console and put them into an Excel and decorate a bit and send out. 5. Every one week and 2 weeks, we need to present to more senior bosses with more nice-looking presentations which is a summary of our findings in those 1-2 weeks. It's this time that is most chaotic because my colleagues and I have to dig into all the hundreds of emails in the past 1-2 weeks and copy and paste and organize those data again and make a nice overall summary for presentation... 6. As I am a hard-working guy, I myself often run my own random/ad-hoc experiments using out-of-work time and whenever I have interesting findings, I will send to immediate bosses and colleagues to seek their comments. 7. All these experiments are in fact variations of different versions/ideas of one big/whole project. Lets say in one big project bosses/colleagues and I have come up with a few big ideas, then we have a few sub-projects: MyProjectIdea1 MyProjectIdea2 ... MyProjectIdeaN And each idea has a few variations, mostly are for answering what-if questions by varying the parameters here and there ... For example: MyProjectIdea1_Variation1_WhatIfParam1ChangedTo1.2? ... ... etc. 8. Most experiments run tens of minutes to many hours... and some of them have to run on Linux, and some others can be run on Windows. Fortunately we have universal paths accessible on both Windows and Linux, so those won't be problem... 9. Because of the time-consuming nature of these experiments, I also save the images as rData whenever I can. However, it's necessary to keep track of the context where these data were generated. Otherwise even the records of these images won't help recall the scenario we have run... --- Keeping track of these changes and all kinds of what-ifs now becomes increasingly a problem for me. Some times in order to respond to a query, although I have done it before already, but because I didn't keep record and save the result, or even though I have saved the memory image yet I am not completely sure about the cleanness of the results/data,I have to redo it and wait for another few hours. Is there a way that I can manage these whole processes better and be more productive? I have been digging and thinking about this for while and I guess Sweave is the right way to go? The problem for Sweave is that it's hard to make Latex generated pdf appealing to business managers... so if I keep records in Sweave/Latex for my own record/benefit (that's already a big benefit)... I still need to somehow manually copy/paste the data from Sweave/Latex/pdf into Word/Excel/Powerpoint in order to make a nice presentation... I know there are some Open Office and Word version of Sweave... the problem is that I couldn't find many demonstrations on these topics and my question is: are they good and can they fulfill what we needed? Your thoughts are greatly appreciated! Thanks a lot! [[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
[R] .Rprofile and help startup
Today I wanted to get R help to start up in text mode under Windows XP. I had my own notes on how to do that. The method described there didn't work. I checked on R-help. No helpful messages on the subject. Therefore I post here in the hope that it helps someone else (or myself, when I forget and search Rhelp again in future). The short story is that R seems to have changed recently (and maybe updates to Windows XP affected file naming). - as before, .Rprofile is placed in home directory, which is shown by doing: Sys.getenv(R_USER) - newer versions of Windows XP don't like to use filenames (eg .Rprofile) with a dot as first character! Have to rename file via startRuncmd - Need to put following line in .Rprofile: options(help_type=text) Old instructions to put options(chmhelp =FALSE) in .Rprofile do NOT work. Cheers, Bill __ 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] bmp() shifts the image (Windows XP)
Duncan, I checked out as.raster as you suggested. However, I can't find info on how to display and save a raster object. What a raster object is eludes me. These were fruitless ?as.raster ?grDevices library(help=grDevices) ?windows ?savePlot x-as.raster(matrix(runif(n*n),nrow=n)) How to display x? plot(x) and image(x) don't work. How to save the bitmap image x? Not sure if I need to scale x to be in range 0-255 before doing as.raster(). I see that x contains elements like #676767. col2rgb(#676767) [,1] red103 green 103 blue 103 That doesn't help me display and save bitmap images. I see there is a package called raster but I'd rather avoid it, given my very simple needs. Maybe package pixmap will work, then convert the saved images to .bmp (e.g. using Irfanview in batch mode). Thanks very much for any help! Bill On 1/1/12, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 12-01-01 9:05 AM, William Simpson wrote: When using bmp() under Windows XP, I find that the saved image is a shifted version of the correct image. Try this: The image() function isn't designed to be able to do pixel-level addressing, so it's not too surprising that some rounding error somewhere leads to this. You could look through the Windows graphics device code to fix it. However, if you really need pixel level addressing, you should be using raster objects. I don't know if someone has written code to output a .bmp file, but it's a very simple format, so it shouldn't be too hard, especially if you only need a limited range of pixel formats (e.g. grayscale). Duncan Murdoch n-5 fn-01.bmp x-matrix(runif(n*n),nrow=n) image(x,col=gray(0:255/255),axes=F,frame.plot=F) bmp(filename = fn,width = n, height = n, units = px) par(mar=c(0,0,0,0),pty=s) image(x,col=gray(0:255/255),axes=F,frame.plot=F) dev.off() The image 01.bmp is like this: 22 23 24 25 w 32 33 34 35 w 42 43 44 45 w 52 53 54 55 w w w w w w w Where 22 represents x[2,2], etc; w represents a white pixel. For my application, the image has to be .bmp format. The same shifting behaviour is seen for large values of n. It is not just due to the small n value. For my application, this shifting is important and has to be eliminated. Please help. On an unrelated note, I found out that the bmp() code is smart enough to write my image as 8-bit using a palette instead of 24-bit with 0:255 grey levels if the image being saved does not use all 256 grey levels. I would love to hear it if somebody knows a good way to make bmp() stupid and always save as 24-bit. My kludge, using 256x256 pixel images, is to tack on an extra row with grey levels 0:255. Then when displaying, I have to crop the image to get rid of that bogus row. Thanks very much for any help! Bill __ 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] calibration curve for glmnet object
Hi, I created a logistic regression model using the glmnet package. This model is of class glmnet or lognet. I wanted to plot a calibration curve for this model using the calibrate() function from rms package, but the objects used are different, rms requires a fit from lrm(). Is there another function for getting the calibration plot for this glmnet object, or can anyone drop some hints as to how to get it done? Thanks for your help, Dave. [[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] Rycas help
Dear friends, can I use Ryacas to solve the two equations X = a/(a+b) Y = (a+b)^2*(a+b+1)/(a*b) subject to a0 and b0 ? I'm on windows using latest R Best wishes Troels Ring Nephrology Aalborg, Denmark Jeg bruger BullGuard til at holde min computer ren. Prøv BullGuard gratis: www.bullguard.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] R report generator (for Word)?
Dear Michael, Our current work flow is to use Sweave and LaTeX. If Word output is needed we convert the LaTeX files to html using htlatex (installed with MikTex). Those html files can be opened with ms word. Best regards, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie Kwaliteitszorg / team Biometrics Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens Joshua Wiley Verzonden: zondag 1 januari 2012 21:32 Aan: Michael CC: r-help Onderwerp: Re: [R] R report generator (for Word)? Hi Michael, I like Sweave and LaTeX, but I can appreciate the difficulty using it with collaborators. What about something similar using HTML? Certainly integrates to any webpages nicely. There are two packages I think do this nicely, one is the R2HTML package (on CRAN). Another one that is not on CRAN yet, but I think has a lot of potential is the knitr package. You can find it on github. I am not personally familiar with any good ways to integrate R with MS Office products. Cheers, Josh On Sun, Jan 1, 2012 at 7:50 AM, Michael comtech@gmail.com wrote: Happy New Year all! I am looking for a good solution for keeping record of my experiments - could you please help me? My work is about analysing data... My current work-flow: 1. Everyday my bosses give me some small steps/tasks for analysing data - which are parts of one bigger/whole project. 2. Everyday I send tens of emails to bosses/colleagues to report my findings in each step. 3. Bosses/colleagues often respond to my findings in real-time and suggest new experiments/steps and ask what-if questions. 4. I often have to manually copy and paste the results from R console and put them into an Excel and decorate a bit and send out. 5. Every one week and 2 weeks, we need to present to more senior bosses with more nice-looking presentations which is a summary of our findings in those 1-2 weeks. It's this time that is most chaotic because my colleagues and I have to dig into all the hundreds of emails in the past 1-2 weeks and copy and paste and organize those data again and make a nice overall summary for presentation... 6. As I am a hard-working guy, I myself often run my own random/ad-hoc experiments using out-of-work time and whenever I have interesting findings, I will send to immediate bosses and colleagues to seek their comments. 7. All these experiments are in fact variations of different versions/ideas of one big/whole project. Lets say in one big project bosses/colleagues and I have come up with a few big ideas, then we have a few sub-projects: MyProjectIdea1 MyProjectIdea2 ... MyProjectIdeaN And each idea has a few variations, mostly are for answering what-if questions by varying the parameters here and there ... For example: MyProjectIdea1_Variation1_WhatIfParam1ChangedTo1.2? ... ... etc. 8. Most experiments run tens of minutes to many hours... and some of them have to run on Linux, and some others can be run on Windows. Fortunately we have universal paths accessible on both Windows and Linux, so those won't be problem... 9. Because of the time-consuming nature of these experiments, I also save the images as rData whenever I can. However, it's necessary to keep track of the context where these data were generated. Otherwise even the records of these images won't help recall the scenario we have run... --- Keeping track of these changes and all kinds of what-ifs now becomes increasingly a problem for me. Some times in order to respond to a query, although I have done it before already, but because I didn't keep record and save the result, or even though I have saved the memory image yet I am not completely sure about the cleanness of the results/data,I have to redo it and wait for another few hours. Is there a way that I can manage these whole processes better and be more productive? I have been digging and thinking about this for while and I guess Sweave is the right way to go? The problem for Sweave is that it's hard to make Latex generated pdf appealing to business managers... so if I keep records in Sweave/Latex for my own record/benefit (that's already a big benefit)... I still need to somehow manually copy/paste the data from Sweave/Latex/pdf
[R] summary per group
Hello, I know that it'll be quite easy to do what I want but somehow I am lost as I am new to R. I want to get summary results arranged by groups. In detail I'd like get the number (levels) of Species per Family like for this dataset: SPEC - factor(c(a,a,b,b,c,c,c,d,e,e,e,e)) FAM - factor(c(A,A,A,A,B,B,B,C,C,C,C,C)) df - data.frame(SPEC,FAM) I tried tapply(SPEC, FAM, nlevels).. but it is not the result I am looking for... What is the easiest way to do that? Do I have to rearrange the dataset? Best regards and Happy New Year! 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] R report generator (for Word)?
A little bit more information about SWord: It is similar to SWeave in the sense that one writes text and R code in one document, and the toolchain then replaces the R code by the results produced by running the R code. In SWeave, this produces a new file which then can processed by TeX. In SWord, the R output is integrated into the Word document, but the original R code is kept also. Therefore, in SWord, if two people are cooperating, the R person can produce a report in Word (using Sword) and send the document including the R results to the second person who does not need to have R. The second person then can edit the text in the Word document and send it back to the first person and changes to the R code (or the data) can be made in the Word file. In the SWeave workflow, the results are only contained in the TeX file. Any changes in the text made in the TeX file then have to be backported to the SWeave source file (.Rnw). http://rcom.univie.ac.at has more information on SWord. __ 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] summary per group
Hi Hello, I know that it'll be quite easy to do what I want but somehow I am lost as I am new to R. I want to get summary results arranged by groups. In detail I'd like get the number (levels) of Species per Family like for this dataset: SPEC - factor(c(a,a,b,b,c,c,c,d,e,e,e,e)) FAM - factor(c(A,A,A,A,B,B,B,C,C,C,C,C)) df - data.frame(SPEC,FAM) I tried tapply(SPEC, FAM, nlevels).. but it is not the result I am looking for... What is the easiest way to do that? Do I have to rearrange the dataset? To do what? Do you want number of unique entries within each level of FAM? If yes sapply(tapply(SPEC, FAM, unique), length) can do this. Regards Petr Best regards and Happy New Year! 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. __ 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] summary per group
Hi, On Mon, Jan 2, 2012 at 8:08 AM, Johannes Radinger jradin...@gmx.at wrote: Hello, I know that it'll be quite easy to do what I want but somehow I am lost as I am new to R. I want to get summary results arranged by groups. In detail I'd like get the number (levels) of Species per Family like for this dataset: SPEC - factor(c(a,a,b,b,c,c,c,d,e,e,e,e)) FAM - factor(c(A,A,A,A,B,B,B,C,C,C,C,C)) df - data.frame(SPEC,FAM) I tried tapply(SPEC, FAM, nlevels).. but it is not the result I am looking for... What is the easiest way to do that? Do I have to rearrange the dataset? nlevels() gives the number of levels defined, not the number of levels that have members, so for your example will always be 5. with(df, aggregate(SPEC, by=list(FAM), nlevels)) Group.1 x 1 A 5 2 B 5 3 C 5 You could drop the unused levels before checking: with(df, aggregate(SPEC, by=list(FAM), function(x)nlevels(factor(x Group.1 x 1 A 2 2 B 1 3 C 2 Or actually get a list of which ones are used: with(df, table(FAM, SPEC)) SPEC FAM a b c d e A 2 2 0 0 0 B 0 0 3 0 0 C 0 0 0 1 4 Sarah -- Sarah Goslee http://www.functionaldiversity.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] Base function for flipping matrices
But if not, it seems to me that it should be added as an array method to ?rev with an argument specifying which indices to rev() over. Yes, agreed. Sometimes arrays seem like something bolted onto R that is missing a lot of functionality. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ 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] bmp() shifts the image (Windows XP)
I have figured out what I wanted to do using pixmap. Pixmap writes .pgm files which I will batch convert to .bmp using Irfanview. Thanks for your help. Cheers, Bill On 1/2/12, William Simpson william.a.simp...@gmail.com wrote: Duncan, I checked out as.raster as you suggested. However, I can't find info on how to display and save a raster object. What a raster object is eludes me. These were fruitless ?as.raster ?grDevices library(help=grDevices) ?windows ?savePlot x-as.raster(matrix(runif(n*n),nrow=n)) How to display x? plot(x) and image(x) don't work. How to save the bitmap image x? Not sure if I need to scale x to be in range 0-255 before doing as.raster(). I see that x contains elements like #676767. col2rgb(#676767) [,1] red103 green 103 blue 103 That doesn't help me display and save bitmap images. I see there is a package called raster but I'd rather avoid it, given my very simple needs. Maybe package pixmap will work, then convert the saved images to .bmp (e.g. using Irfanview in batch mode). Thanks very much for any help! Bill On 1/1/12, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 12-01-01 9:05 AM, William Simpson wrote: When using bmp() under Windows XP, I find that the saved image is a shifted version of the correct image. Try this: The image() function isn't designed to be able to do pixel-level addressing, so it's not too surprising that some rounding error somewhere leads to this. You could look through the Windows graphics device code to fix it. However, if you really need pixel level addressing, you should be using raster objects. I don't know if someone has written code to output a .bmp file, but it's a very simple format, so it shouldn't be too hard, especially if you only need a limited range of pixel formats (e.g. grayscale). Duncan Murdoch n-5 fn-01.bmp x-matrix(runif(n*n),nrow=n) image(x,col=gray(0:255/255),axes=F,frame.plot=F) bmp(filename = fn,width = n, height = n, units = px) par(mar=c(0,0,0,0),pty=s) image(x,col=gray(0:255/255),axes=F,frame.plot=F) dev.off() The image 01.bmp is like this: 22 23 24 25 w 32 33 34 35 w 42 43 44 45 w 52 53 54 55 w w w w w w w Where 22 represents x[2,2], etc; w represents a white pixel. For my application, the image has to be .bmp format. The same shifting behaviour is seen for large values of n. It is not just due to the small n value. For my application, this shifting is important and has to be eliminated. Please help. On an unrelated note, I found out that the bmp() code is smart enough to write my image as 8-bit using a palette instead of 24-bit with 0:255 grey levels if the image being saved does not use all 256 grey levels. I would love to hear it if somebody knows a good way to make bmp() stupid and always save as 24-bit. My kludge, using 256x256 pixel images, is to tack on an extra row with grey levels 0:255. Then when displaying, I have to crop the image to get rid of that bogus row. Thanks very much for any help! Bill __ 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] bmp() shifts the image (Windows XP)
Hi, On Jan 2, 2012, at 7:00 AM, William Simpson wrote: Duncan, I checked out as.raster as you suggested. However, I can't find info on how to display and save a raster object. What a raster object is eludes me. These were fruitless ?as.raster ?grDevices library(help=grDevices) ?windows ?savePlot x-as.raster(matrix(runif(n*n),nrow=n)) How to display x? plot(x) and image(x) don't work. How to save the bitmap image x? Not sure if I need to scale x to be in range 0-255 before doing as.raster(). I see that x contains elements like #676767. col2rgb(#676767) [,1] red103 green 103 blue 103 That doesn't help me display and save bitmap images. I see there is a package called raster but I'd rather avoid it, given my very simple needs. Maybe package pixmap will work, then convert the saved images to .bmp (e.g. using Irfanview in batch mode). I agree that it can be very confusing to navigate the many tricks of working with images in R. I don't know if this helps in your particular case, but for display purposes, the newish rasterImage() is the way to go. Raster graphics in R got a big boost with the addition of native raster support - see http://journal.r-project.org/archive/2011-1/RJournal_2011-1_Murrell.pdf Here's a very simple example... n - 50 x - seq(from = -5, to = 20, length = n) y - seq(from = 38, to = 45, length = n) z - matrix(runif(n*n, min = 0, max = 1), nrow = n, ncol = n) plot(x,y, typ = n) rasterImage(z, x[1], y[1], x[n], y[n]) For pixel-to-pixel output, you might check out the savemat() function in the package 'squash'. Cheers, Ben Thanks very much for any help! Bill On 1/1/12, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 12-01-01 9:05 AM, William Simpson wrote: When using bmp() under Windows XP, I find that the saved image is a shifted version of the correct image. Try this: The image() function isn't designed to be able to do pixel-level addressing, so it's not too surprising that some rounding error somewhere leads to this. You could look through the Windows graphics device code to fix it. However, if you really need pixel level addressing, you should be using raster objects. I don't know if someone has written code to output a .bmp file, but it's a very simple format, so it shouldn't be too hard, especially if you only need a limited range of pixel formats (e.g. grayscale). Duncan Murdoch n-5 fn-01.bmp x-matrix(runif(n*n),nrow=n) image(x,col=gray(0:255/255),axes=F,frame.plot=F) bmp(filename = fn,width = n, height = n, units = px) par(mar=c(0,0,0,0),pty=s) image(x,col=gray(0:255/255),axes=F,frame.plot=F) dev.off() The image 01.bmp is like this: 22 23 24 25 w 32 33 34 35 w 42 43 44 45 w 52 53 54 55 w w w w w w w Where 22 represents x[2,2], etc; w represents a white pixel. For my application, the image has to be .bmp format. The same shifting behaviour is seen for large values of n. It is not just due to the small n value. For my application, this shifting is important and has to be eliminated. Please help. On an unrelated note, I found out that the bmp() code is smart enough to write my image as 8-bit using a palette instead of 24-bit with 0:255 grey levels if the image being saved does not use all 256 grey levels. I would love to hear it if somebody knows a good way to make bmp() stupid and always save as 24-bit. My kludge, using 256x256 pixel images, is to tack on an extra row with grey levels 0:255. Then when displaying, I have to crop the image to get rid of that bogus row. Thanks very much for any help! Bill __ 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. Ben Tupper Bigelow Laboratory for Ocean Sciences 180 McKown Point Rd. P.O. Box 475 West Boothbay Harbor, Maine 04575-0475 http://www.bigelow.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] Percentage scale on y-axis
On Jan 2, 2012, at 4:31 AM, Öhagen Patrik wrote: Seasonal Greetings! I am trying to plot a simple survival curve using; plot (survfit (Surv(d01,cens) ,conf.type=none ),xlab=Time,ylab=Survival) That does not look like a valid survival formula to me but maybe I'm insufficiently experienced. I would be interested in a percentage scale on the y-axis. How do I achieve sucha scale? Have you tried using xaxt=n and then following up with axis(2, at=seq(0,1,by=.2), labels=paste(100*seq(0,1,by=.2), %) ) in the usual manner (I think plot.coxph.survfit uses ordinary base graphics.) -- David Winsemius, MD 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] Percentage scale on y-axis
On Jan 2, 2012, at 10:10 AM, David Winsemius wrote: On Jan 2, 2012, at 4:31 AM, Öhagen Patrik wrote: Seasonal Greetings! I am trying to plot a simple survival curve using; plot (survfit (Surv(d01,cens) ,conf.type=none ),xlab=Time,ylab=Survival) That does not look like a valid survival formula to me but maybe I'm insufficiently experienced. I would be interested in a percentage scale on the y-axis. How do I achieve sucha scale? Have you tried using xaxt=n I hope it was obvious I meant to type ..., yaxt=n, and then following up with axis(2, at=seq(0,1,by=.2), labels=paste(100*seq(0,1,by=.2), %) ) in the usual manner (I think plot.coxph.survfit uses ordinary base graphics.) -- David Winsemius, MD 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. David Winsemius, MD 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] sm.density.compare - a lot of curves
Dear all, Let say I have a sets of numbers: rno1 = rnorm(1000) rno2 = rnorm(1000) If I write request as follow: sm.density.compare (rno, rno3, xfit=min(rno), max(rno2)) why I receive a lot of curves in my plot, while I have only two data sets? regards Przemek -- View this message in context: http://r.789695.n4.nabble.com/sm-density-compare-a-lot-of-curves-tp4253039p4253039.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] Break Points
Respected Sir I fitted that model... lnrpe= a+bt and conducted sup F test since autocorelation is present in the data and AIC as you mentioned might not Is it OK... Since I am not well versed with time series econometrics can you please tell me if the work is now correct or not -- Please have a look at our new mission and contribute into it (cut and paste the link below in the address bar of your internet browser) http://thesocialscienceinformer.blogspot.com/ Thanking you Ayanendu Sanyal PhD Scholar Institute for Social and Economic Change (ISEC) P.O- Nagarbhavi Bangalore-72 State- Karnataka Country- India PIN- 560072 www.isec.ac.in/phd.html http://ayanendusanyal.blogspot.com/ lnrpe 1.6113515 1.619601724 1.599889264 1.645954835 1.723777317 1.830606002 2.034751407 2.112377045 2.095050993 2.046822835 2.276628064 2.543864584 2.619425807 2.717786454 2.874537082 2.923223972 3.136825311 3.206377996 3.352655132 3.49032806 3.508602739 3.621768106 3.803617305 4.141727497 4.27471221 4.34523451 4.242555261 4.262046942 4.378894917 4.419018243 4.391496862 4.489015146 4.588180885 4.846861554 5.069645376 5.257766481 5.292695491 5.307844982 5.277006289 5.323613873 5.377629069 5.429256311 5.443411354 5.47242567 5.727392687 6.147054773 R version 2.14.1 (2011-12-22) Copyright (C) 2011 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i386-pc-mingw32/i386 (32-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. source(C:\\Documents and Settings\\ayaendu\\My Documents\\struc.R) Loading required package: MASS Loading required package: nnet Loading required package: survival Loading required package: splines Loading required package: zoo Attaching package: ‘zoo’ The following object(s) are masked from ‘package:base’: as.Date, as.Date.numeric Loading required package: sandwich Warning message: Overlapping confidence intervals ayan - read.table(ayan.txt, header=T) ## Fetching files saved in My documents ayan = ts(ayan, start=1, frequency=1) ## Setting the data into time series data trend = time (ayan) ## defining the explanatory variable reg = lm(ayan~trend) ## regression lnrpe= a+bt summary (reg) ## regression results summary Call: lm(formula = ayan ~ trend) Residuals: Min 1Q Median 3Q Max -0.35086 -0.11196 -0.01008 0.09193 0.38507 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 1.345373 0.049774 27.03 2e-16 *** trend 0.101771 0.001844 55.19 2e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 0.166 on 44 degrees of freedom Multiple R-squared: 0.9858, Adjusted R-squared: 0.9854 F-statistic: 3046 on 1 and 44 DF, p-value: 2.2e-16 library (car) ## loading package to do dwtest library (strucchange) ## loading package to do structural break library (lmtest) ## loading package to do dwtest dwtest (reg) ## for testing serial auto correrelation Durbin-Watson test data: reg DW = 0.4157, p-value = 1.405e-12 alternative hypothesis: true autocorrelation is greater than 0 bp.ayan - breakpoints(ayan ~ trend) ## searching for break points summary (bp.ayan) ## checking the breakpoints and minimum AIC level Optimal (m+1)-segment partition: Call: breakpoints.formula(formula = ayan ~ trend) Breakpoints at observation number: m = 1 23 m = 2 2333 m = 3 112333 m = 4 112333 40 m = 5 1120 26 34 40 m = 6 8 14 20 26 34 40 Corresponding to breakdates: m = 1 23 m = 2 2333 m = 3 112333 m = 4 112333 40 m = 5 1120 26 34 40 m = 6 8 14 20 26 34 40 Fit: m 0 1 2 3 4 5 RSS 1.2131579 0.7466773 0.5243361 0.3570253 0.2712234 0.2589809 BIC -25.2008012 -36.0409283 -40.8160181 -47.0090984 -48.1669059 -38.8056613 m 6 RSS 0.2698858 BIC -25.4224766 ci.ayan - confint(bp.ayan)## confidence interval for the test breakdates (ci.ayan) 2.5 % breakpoints 97.5 % 110 11 15 222 23 24 332 33 34 425 40 41 Warning message: Overlapping confidence intervals ci.ayan ## displays the confidence interval Confidence intervals for breakpoints
[R] Very strange function() behaviour.
Sorry if there's an easy answer to this problem, but here goes.. * INTRODUCTION CONTEXT* I'm creating a function where the number of entries in the lm(y~...) varies. i.e. depending on the function input I want lm(y~x1+x2+x3), sometimes I'll want lm(y~x1) only, et cetera. I've completed this with paste(..,sep=) and as.formula(). *The problem* Many of these possible entries [i.e. the x1, x2, x3] need their own lapply for the lm() to work, as they're all lists or matrices with many dimensions [I'm iterating along the dim of each X, which is why I need separate lapply() for each]. Except, I can't do as.formula(..) with lapply(), therefore I'm stuffed! This is the problem area: #-- rl-list() for(Q in 1:ncol(y)){ rl[[colnames(y)[Q]]]- lapply(1:length(x1),function(N){lm(y[,Q]~x1[[N]])} } #- This is the correct code for a case of 1 independent variable. But if the preceding code wants to put in x2 or x3 (which it can do fine), how do I get more lapplys to automatically layer on top of the above code, responsive to the number of x? [[Note I can't layer loops on top of it... as I'm shoving the lm() into a list(), lapply() puts the lm() in the correct dimensions of the list() but for() loops do not.]] ##P.S. just consider y to be: y-matrix(rnorm(100),ncol=50,nrow=100) ##x1, x2, x3, etc are either 1 or 2 dimensional lists... Just know that there needs to be some lapply()- or loop-esque thingy that deals with each one, otherwise it won't work. Thank you everyone. - Isaac Research Assistant Quantitative Finance Faculty, UTS -- View this message in context: http://r.789695.n4.nabble.com/Very-strange-function-behaviour-tp4252877p4252877.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] Create variable with AND IF statement
Hello, I'm using SPSS at work but really would like to switch to R. Right now I'm trying to learn R in reproducing calculations I did with SPSS but am stuck with something that is quite simple and comprehensible in SPSS-Syntax: IF (variable1.fac = 0 AND variable2.num = 0) variable3=1. IF (variable1.fac = 0 AND variable2.num = 1) variable3=2. IF (variable1.fac = 1 AND variable2.num = 0) variable3=3. IF (variable1.fac = 1 AND variable2.num = 1) variable3=4. I want to create four different groups out of different conditions of two variables: * variable1.fac is a factor coded with 0 and 1 * variable2.num is a numerical variable with only whole numbers My problem with R is that I can't find a way to use AND in an IF statement that doesn't produce an error or not intended solutions. An Introduction to R is really unhelpful with this problem and I wouldn't have written here, if I didn't have searched for the answer. http://tolstoy.newcastle.edu.au/R/help/05/09/12136.html was helpful in understanding how the IF statement is written in R but didn't answer my question how to add an usable AND (, |) https://stat.ethz.ch/pipermail/r-help/2008-November/178808.html looked promising but didn't do what I had intended Thanks in advance, Richard [[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] matrix position to list of coordinates
Hi Ana, d=dim(A) d [1] 2 4 cbind(rep(1:d[1], each=d[2]), rep(1:d[2], d[1])) [,1] [,2] [1,]11 [2,]12 [3,]13 [4,]14 [5,]21 [6,]22 [7,]23 [8,]24 Thanks, wr * Ana rrast...@gmail.com [2012-01-01 23:21:12 +0100]: How can I extract a list of the positions in the matrix? A=matrix(1:8, nrow=2,ncol=4) A [,1] [,2] [,3] [,4] [1,]1357 [2,]2468 Something like this pos.A 1 1 1 2 1 3 1 4 2 1 2 2 2 3 2 4 __ 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] Display warning when embedded data file is loaded
Dear all, I would like to show a warning when a data file, that is embedded in the package, is loaded. I have so far not been able to find any manual or mailing list going on about that. In code example: library(myPackage) data(myData) # Now I want a warning containing info about this loaded 'myData' file It would be great if someone could indicate if this is at all possible, and if so, how to embed it (or where I can read how to do it). Many thanks in advance, Niels __ 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] quadratic programming-maximization instead of minization
Hi, I need to maximize a quadratic function under constraints in R. For minimization I used solve.QP but for maximization it is not useful since the matrix D of the quadratic function should be positive definite hence I cannot simply change the sign. any suggestion ? thanks -- View this message in context: http://r.789695.n4.nabble.com/quadratic-programming-maximization-instead-of-minization-tp4253011p4253011.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] Conditionally adding a constant
Hello, I believe this works. f1 - function(x){ for(i in 2:length(x)) x[i] - ifelse(x[i-1] 3, x[i-1] + 2, x[i]) x } f2 - function(x){ for(i in 2:length(x)) x[i] - ifelse(is.na(x[i]) (x[i-1] 3), x[i-1] + 2, x[i]) x } df - data.frame(x = c(1,2,3,4,5), y = c(10,20,30,NA,NA)) apply(df, 2, f1) # df$x[4] 3, df$x[5] also changes apply(df, 2, f2) # only df$y has NA's Maybe there's a better way, avoiding the loop. Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/Conditionally-adding-a-constant-tp4253049p4253125.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] matrix position to list of coordinates
Hi Ana, most probably this is one of the more ugly solutions: d=dim(A) d [1] 2 4 cbind(rep(1:d[1], each=d[2]), rep(1:d[2], d[1])) [,1] [,2] [1,]11 [2,]12 [3,]13 [4,]14 [5,]21 [6,]22 [7,]23 [8,]24 Thanks, wr * Ana rrast...@gmail.com [2012-01-01 23:21:12 +0100]: How can I extract a list of the positions in the matrix? A=matrix(1:8, nrow=2,ncol=4) A [,1] [,2] [,3] [,4] [1,]1357 [2,]2468 Something like this pos.A 1 1 1 2 1 3 1 4 2 1 2 2 2 3 2 4 __ 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] find inflexion point of discrete value list with R
i have a list of values like this x y 1 3 2 2 3 3 4 4 5 5 6 4 7 3 8 2 9 3 and need the inflexion points (and all max and min). Is there a nice way to get the local max, min and inflexion points? kind regards, -- Jonas Stein n...@jonasstein.de __ 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] syntax for reading into R
dear users, we have got the following question: we have got a text-file looking like this: ... trkpt lat=48.272000 lon=16.342984 ele387/ele time2012-01-01T15:32:03Z/time sat9/sat /trkpt trkpt lat=48.271909 lon=16.343563 ele381/ele time2012-01-01T15:32:34Z/time sat9/sat /trkpt ... now we would like to create a text file looking like the following, in order to being able to read it into R afterwards. - lat;lon;ele;time;sat 48.272000;16.342984;387;2012-01-01T15:32:03Z;9 48.271909;16.343563;381;2012-01-01T15:32:34Z;9 ... does anyone know how to do this? thank you very much for your help in advance. marion [[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] Conditionally adding a constant
I am trying to add a constant to the previous value of a variable based on certain conditions. Maybe there is a simple way to do this that I am missing completely. I have given an example below: df - data.frame(x = c(1,2,3,4,5), y = c(10,20,30,NA,NA)) df x y 1 1 10 2 2 20 3 3 30 4 4 NA 5 5 NA I want to add 2 to the previous value of y, if x exceeds 3 (also will have to handle NAs in the process). The resulting output would look like: x y 1 1 10 2 2 20 3 3 30 4 4 32 5 5 34 Can someone please explain how to do it? Thank you. Ravi -- View this message in context: http://r.789695.n4.nabble.com/Conditionally-adding-a-constant-tp4253049p4253049.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] sm.density.compare - a lot of curves
Hi Przemek, Take a look at ?sm.density.compare : you forgot to include the group argument in your call. Try require(sm) rno1 = rnorm(1000) rno2 = rnorm(1000) g - rep(c(1, 2), each = 1000) y - c(rno1, rno2) sm.density.compare(y, g, model = 'equal') HTH, Jorge.- On Mon, Jan 2, 2012 at 7:00 AM, przemek wrote: Dear all, Let say I have a sets of numbers: rno1 = rnorm(1000) rno2 = rnorm(1000) If I write request as follow: sm.density.compare (rno, rno3, xfit=min(rno), max(rno2)) why I receive a lot of curves in my plot, while I have only two data sets? regards Przemek -- View this message in context: http://r.789695.n4.nabble.com/sm-density-compare-a-lot-of-curves-tp4253039p4253039.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. [[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] Predicting multiple responses
I have question related to predicting mutiple response sequences and am not sure how to go about it. I have a training set of classifiers say T0, T1..TN and am trying to predict a sequence of results (say a timeseries), say R0, R1...Rx (R0, R1.etc may or may not be independent). How does one go about it using randomForest in R ? Any ideas ? I was thinking doing multiple runs and keep appending the training set with the completed predictors ? for example, Run0: training set = T0, T1...TN and predict result V0 Run1 training set = T0, T1...TN, R0 and predict result V1 Run2 training set = T0, T1,...TN,R0,R1 etc.. I am not sure if this makes sense or using randomForest to preduct multiple responses is possible ? Any ideas is much appreciated. [[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] Very strange function() behaviour.
(To me, anyway) Incoherent. Reproducible code needed. -- Bert On Mon, Jan 2, 2012 at 1:59 AM, iliketurtles isaacm...@gmail.com wrote: Sorry if there's an easy answer to this problem, but here goes.. * INTRODUCTION CONTEXT* I'm creating a function where the number of entries in the lm(y~...) varies. i.e. depending on the function input I want lm(y~x1+x2+x3), sometimes I'll want lm(y~x1) only, et cetera. I've completed this with paste(..,sep=) and as.formula(). *The problem* Many of these possible entries [i.e. the x1, x2, x3] need their own lapply for the lm() to work, as they're all lists or matrices with many dimensions [I'm iterating along the dim of each X, which is why I need separate lapply() for each]. Except, I can't do as.formula(..) with lapply(), therefore I'm stuffed! This is the problem area: #-- rl-list() for(Q in 1:ncol(y)){ rl[[colnames(y)[Q]]]- lapply(1:length(x1),function(N){lm(y[,Q]~x1[[N]])} } #- This is the correct code for a case of 1 independent variable. But if the preceding code wants to put in x2 or x3 (which it can do fine), how do I get more lapplys to automatically layer on top of the above code, responsive to the number of x? [[Note I can't layer loops on top of it... as I'm shoving the lm() into a list(), lapply() puts the lm() in the correct dimensions of the list() but for() loops do not.]] ##P.S. just consider y to be: y-matrix(rnorm(100),ncol=50,nrow=100) ##x1, x2, x3, etc are either 1 or 2 dimensional lists... Just know that there needs to be some lapply()- or loop-esque thingy that deals with each one, otherwise it won't work. Thank you everyone. - Isaac Research Assistant Quantitative Finance Faculty, UTS -- View this message in context: http://r.789695.n4.nabble.com/Very-strange-function-behaviour-tp4252877p4252877.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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ 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] Create variable with AND IF statement
On Jan 2, 2012, at 4:11 AM, Richard Kolodziej wrote: Hello, I'm using SPSS at work but really would like to switch to R. Right now I'm trying to learn R in reproducing calculations I did with SPSS but am stuck with something that is quite simple and comprehensible in SPSS-Syntax: IF (variable1.fac = 0 AND variable2.num = 0) variable3=1. IF (variable1.fac = 0 AND variable2.num = 1) variable3=2. IF (variable1.fac = 1 AND variable2.num = 0) variable3=3. IF (variable1.fac = 1 AND variable2.num = 1) variable3=4. I want to create four different groups out of different conditions of two variables: * variable1.fac is a factor coded with 0 and 1 * variable2.num is a numerical variable with only whole numbers My problem with R is that I can't find a way to use AND in an IF statement that doesn't produce an error or not intended solutions. An Introduction to R is really unhelpful with this problem and I wouldn't have written here, if I didn't have searched for the answer. Do you not find the 'ifelse' function described in An Introduction to R in the section regarding if. http://tolstoy.newcastle.edu.au/R/help/05/09/12136.html was helpful in understanding how the IF statement is written in R but didn't answer my question how to add an usable AND (, |) Not the best answer I have ever seen in the archives. But if you had followed up by reading further in the thread you would have found the correct approach. https://stat.ethz.ch/pipermail/r-help/2008-November/178808.html looked promising but didn't do what I had intended (I think the results of interaction( variable1.fac = 0 , variable2.num = 0) should have dome very nicely, but if you wanted them a naked numbers then this would have also givne satisfaction: var3 - as.numeric( interaction( variable1.fac = 0 , variable2.num = 0) ) -- David Thanks in advance, Richard [[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. David Winsemius, MD 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] Display number in currency notation with commas
How can I display a number as currency including a $ sign and commas? -- View this message in context: http://r.789695.n4.nabble.com/Display-number-in-currency-notation-with-commas-tp4253460p4253460.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] Create variable with AND IF statement
Dear Richard, You can do this with some nested ifelse statements. Assuming variable2.num has only positive integers and variable1.fac is only 0 or 1 Variable3 - ifelse(variable1.fac == 0, ifelse(variable2.num == 0, 1, 2), ifelse(variable2.num == 0; 3; 4)) A more fancy solution as.numeric(factor(variable1.fac):factor(ifelse(variable2.num == 0, 0, 1))) Best regards, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie Kwaliteitszorg / team Biometrics Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens Richard Kolodziej Verzonden: maandag 2 januari 2012 10:11 Aan: r-help@r-project.org Onderwerp: [R] Create variable with AND IF statement Hello, I'm using SPSS at work but really would like to switch to R. Right now I'm trying to learn R in reproducing calculations I did with SPSS but am stuck with something that is quite simple and comprehensible in SPSS-Syntax: IF (variable1.fac = 0 AND variable2.num = 0) variable3=1. IF (variable1.fac = 0 AND variable2.num = 1) variable3=2. IF (variable1.fac = 1 AND variable2.num = 0) variable3=3. IF (variable1.fac = 1 AND variable2.num = 1) variable3=4. I want to create four different groups out of different conditions of two variables: * variable1.fac is a factor coded with 0 and 1 * variable2.num is a numerical variable with only whole numbers My problem with R is that I can't find a way to use AND in an IF statement that doesn't produce an error or not intended solutions. An Introduction to R is really unhelpful with this problem and I wouldn't have written here, if I didn't have searched for the answer. http://tolstoy.newcastle.edu.au/R/help/05/09/12136.html was helpful in understanding how the IF statement is written in R but didn't answer my question how to add an usable AND (, |) https://stat.ethz.ch/pipermail/r-help/2008-November/178808.html looked promising but didn't do what I had intended Thanks in advance, Richard [[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] syntax for reading into R
On Mon, Jan 2, 2012 at 3:31 PM, Marion Wenty marion.we...@gmail.com wrote: . trkpt lat=48.272000 lon=16.342984 ele387/ele time2012-01-01T15:32:03Z/time sat9/sat /trkpt trkpt lat=48.271909 lon=16.343563 ele381/ele time2012-01-01T15:32:34Z/time sat9/sat /trkpt ... now we would like to create a text file looking like the following, in order to being able to read it into R afterwards. - lat;lon;ele;time;sat 48.272000;16.342984;387;2012-01-01T15:32:03Z;9 48.271909;16.343563;381;2012-01-01T15:32:34Z;9 ... does anyone know how to do this? That looks suspiciously like a chunk of a GPX format file - GPS tracks, that kind of thing. Am I right? If so, then get the rgdal package, and read it in. You'll end up with a spatial data frame of some kind from which you can get the points and times. http://en.wikipedia.org/wiki/GPS_eXchange_Format Barry __ 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] Create variable with AND IF statement
On Jan 2, 2012, at 10:42 AM, David Winsemius wrote: On Jan 2, 2012, at 4:11 AM, Richard Kolodziej wrote: Hello, I'm using SPSS at work but really would like to switch to R. Right now I'm trying to learn R in reproducing calculations I did with SPSS but am stuck with something that is quite simple and comprehensible in SPSS- Syntax: IF (variable1.fac = 0 AND variable2.num = 0) variable3=1. IF (variable1.fac = 0 AND variable2.num = 1) variable3=2. IF (variable1.fac = 1 AND variable2.num = 0) variable3=3. IF (variable1.fac = 1 AND variable2.num = 1) variable3=4. https://stat.ethz.ch/pipermail/r-help/2008-November/178808.html looked promising but didn't do what I had intended (I think the results of interaction( variable1.fac = 0 , variable2.num = 0) should have dome very nicely, but if you wanted them a naked numbers then this would have also givne satisfaction: var3 - as.numeric( interaction( variable1.fac = 0 , variable2.num = 0) ) Well that should be filed under embarrassing contributions. Try instead: var3 - as.numeric( interaction( variable1.fac == 1 , variable2.num = 1) ) -- David David Winsemius, MD 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] syntax for reading into R
On Mon, Jan 2, 2012 at 3:54 PM, Barry Rowlingson b.rowling...@lancaster.ac.uk wrote: That looks suspiciously like a chunk of a GPX format file - GPS tracks, that kind of thing. Am I right? If so, then get the rgdal package, and read it in. You'll end up with a spatial data frame of some kind from which you can get the points and times. http://en.wikipedia.org/wiki/GPS_eXchange_Format Specifically, if I put that snippet of yours into a GPX file, I can do: trk= readOGR(m.gpx,track_points) trk coordinates track_fid track_seg_id track_seg_point_id ele 1 (16.343, 48.272) 00 0 387 2 (16.3436, 48.2719) 00 1 381 time magvar geoidheight name cmt desc src link1_href 1 2012/01/01 15:32:03+00 NA NA NA NA NA NA NA 2 2012/01/01 15:32:34+00 NA NA NA NA NA NA NA link1_text link1_type link2_href link2_text link2_type sym type fix sat 1 NA NA NA NA NA NA NA NA 9 2 NA NA NA NA NA NA NA NA 9 hdop vdop pdop ageofdgpsdata dgpsid 1 NA NA NANA NA 2 NA NA NANA NA - obviously there's a lot of stuff there you don't need, so you can do: trk@data=trk@data[,c(ele,time,sat)] trk coordinates ele time sat 1 (16.343, 48.272) 387 2012/01/01 15:32:03+00 9 2 (16.3436, 48.2719) 381 2012/01/01 15:32:34+00 9 Barry __ 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] Smoothing spline with smoothing parameters selected by generalized maximum likelihood
something like library(mgcv) gam(y~s(x,k=50),method=REML) is one option for spline smoothing y w.r.t. x and choosing the smoothing parameter by GML (GML and REML do the same thing). On 18/12/11 12:26, ali_protocol wrote: Hi there, How may I smooth spline two vectors with the smoothing parameter selected by generalized maximum likelihood (GML) .? Thanks a lot. -- View this message in context: http://r.789695.n4.nabble.com/Smoothing-spline-with-smoothing-parameters-selected-by-generalized-maximum-likelihood-tp4210679p4210679.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. -- Simon Wood, Mathematical Science, University of Bath BA2 7AY UK +44 (0)1225 386603 http://people.bath.ac.uk/sw283 __ 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] summary per group
Original-Nachricht Datum: Mon, 2 Jan 2012 14:29:07 +0100 Von: Petr PIKAL petr.pi...@precheza.cz An: Johannes Radinger jradin...@gmx.at CC: r-help@r-project.org Betreff: Re: [R] summary per group Hi Hello, I know that it'll be quite easy to do what I want but somehow I am lost as I am new to R. I want to get summary results arranged by groups. In detail I'd like get the number (levels) of Species per Family like for this dataset: SPEC - factor(c(a,a,b,b,c,c,c,d,e,e,e,e)) FAM - factor(c(A,A,A,A,B,B,B,C,C,C,C,C)) df - data.frame(SPEC,FAM) I tried tapply(SPEC, FAM, nlevels).. but it is not the result I am looking for... What is the easiest way to do that? Do I have to rearrange the dataset? To do what? Do you want number of unique entries within each level of FAM? If yes sapply(tapply(SPEC, FAM, unique), length) can do this. Regards Petr Thank you Petr, that is exactly what I was looking for... no I played a little bit around with that because I want to create a summary with FAM as a grouping variable. Beside the number of unique SPEC per FAM also want to get their levels as text. So far I know I have following: paste(unique(SPEC), collapse = ', ') But how can I use that in combination with tapply and furthermore with cbind like: SPEC - factor(c(a,a,b,b,c,c,c,d,e,e,e,e)) FAM - factor(c(A,A,A,A,B,B,B,C,C,C,C,C)) df - data.frame(SPEC,FAM) with(df, cbind(Number of SPEC=sapply(tapply(SPEC,FAM,unique),length), SPECs=tapply(SPEC,FAM,unique))) The result should look like: Number of SPEC SPECs A 2 a, b B 1 c C 2 d, e Thank you, /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] Display number in currency notation with commas
eigenvalet wrote How can I display a number as currency including a $ sign and commas? -- View this message in context: http://r.789695.n4.nabble.com/Display-number-in-currency-notation-with-commas-tp4253460p4253460.html Sent from the R help mailing list archive at Nabble.com. __ R-help@ mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. One way myNum= paste($,format(myNum, big.mark=,),sep=) HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/Display-number-in-currency-notation-with-commas-tp4253582p4253695.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] Creating ZOO Matrix from Data Frame
I believe that I have a basic understanding of zoo and how to use read.zoo on a text file, What I have not seen in the zoo help files and vignettes is how to convert a data frame to a zoo matrix for irregular time series analyses. An example data frame is structured like this: str(burns.cast) 'data.frame': 256 obs. of 47 variables: $ site : Factor w/ 143 levels BC-0.5,BC-1,..: 1 1 1 2 2 2 2 2 2 2 $ sampdate : Date, format: 1996-04-19 1996-05-21 ... $ Ca : num 76.6 NA NA NA NA ... $ Cond : num 712 403 731 NA NA NA NA NA NA NA ... $ HCO3 : num 162 152 212 NA NA NA NA NA NA NA ... $ SO4 : num 175 57 194 NA NA NA NA NA NA NA ... $ TDS : num 460 212 530 NA NA NA NA NA NA NA ... ... What I think I need is a matrix that orders sampdate, has the numeric values for TDS, and retains the factor of site (so that I can compare TDS values on a given date by site). The August 2011 version of zoo docs suggests that I need to modify the above from a data frame to a matrix, but there is more than a single class involved. Would something like this work? z - zoo(burns.cast$TDS, order.by = burns.cast$sampdate, style = vertical) And where do I include the site factor? A pointer to docs or an example will be much appreciated. Rich __ 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] find inflexion point of discrete value list with R
Jonas Stein news at jonasstein.de writes: i have a list of values like this x y 1 3 2 2 [snip] and need the inflexion points (and all max and min). Is there a nice way to get the local max, min and inflexion points? diff(y) gives you the first difference, the analogue of the gradient diff(diff(y)) gives the second difference, the analogue of the second derivative. dy - diff(y) d2y - diff(dy) which(dy==0) ## critical values sign(s2y)[which(dy==0)] ## test for max/min/saddle which(d2y==0) ## inflection points __ 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] find inflexion point of discrete value list with R
Ben Bolker bbolker at gmail.com writes: Jonas Stein news at jonasstein.de writes: [snip] [snip] sign(s2y)[which(dy==0)] ## test for max/min/saddle oops, obviously this should be sign(d2y)[which(dy==0)] __ 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] summary per group
On Jan 2, 2012, at 11:14 AM, Johannes Radinger wrote: Thank you Petr, that is exactly what I was looking for... no I played a little bit around with that because I want to create a summary with FAM as a grouping variable. Beside the number of unique SPEC per FAM also want to get their levels as text. So far I know I have following: paste(unique(SPEC), collapse = ', ') But how can I use that in combination with tapply and furthermore with cbind like: SPEC - factor(c(a,a,b,b,c,c,c,d,e,e,e,e)) FAM - factor(c(A,A,A,A,B,B,B,C,C,C,C,C)) df - data.frame(SPEC,FAM) with(df, cbind(Number of SPEC=sapply(tapply(SPEC,FAM,unique),length), SPECs=tapply(SPEC,FAM,unique))) You probably do not want yoru resutls coming back as tables (which is what tapply returns, but as vectors.) So use `ave` instead of `tapply`. The result should look like: Number of SPEC SPECs A 2 a, b B 1 c C 2 d, e Thank you, /johannes David Winsemius, MD 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] Base function for flipping matrices
Hadley, Your request is reminding me of the analysis of aray functions in Philip S Abrams dissertation http://www.slac.stanford.edu/cgi-wrap/getdoc/slac-r-114.pdf AN APL MACHINE The section that starts on page 17 with this paragraph is the one that immediately applies C. The Standard Form for Select Expressions In this section the selection operators considered are take, drop, reversal, transpose, and subscripting by scalars or _J-vectors. Because of the similarity among the selection operators, we might expect that an expression consisting only of selection operators applied to a single array could be expressed equivalently in terms of some simpler set of operators. This expectation is fulfilled in the standard form for select expressions, to be discussed below. I look forward to seeing where you take this in R. Rich On Mon, Jan 2, 2012 at 8:38 AM, Hadley Wickham had...@rice.edu wrote: But if not, it seems to me that it should be added as an array method to ?rev with an argument specifying which indices to rev() over. Yes, agreed. Sometimes arrays seem like something bolted onto R that is missing a lot of functionality. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ 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.htmlhttp://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] Remove me from the mailing list
Dear Sir/Madam, Please kindly remove me from the mailing list as I no longer intend to receive emails from R help. Best [[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] Base function for flipping matrices
Hadley, I started to throw some functions that I needed to be extended to arrays together as package arrayhelpers. If you consider that a good home for the new functions, they would be more than welcome. Currently I have the package at r-forge, but I wouldn't mind github, either (so far I just use git-svn). Unit tests use svUnit, not testthat, though. Happy new year to everyone, Claudia Am 02.01.2012 18:38, schrieb Richard M. Heiberger: Hadley, Your request is reminding me of the analysis of aray functions in Philip S Abrams dissertation http://www.slac.stanford.edu/cgi-wrap/getdoc/slac-r-114.pdf AN APL MACHINE The section that starts on page 17 with this paragraph is the one that immediately applies C. The Standard Form for Select Expressions In this section the selection operators considered are take, drop, reversal, transpose, and subscripting by scalars or _J-vectors. Because of the similarity among the selection operators, we might expect that an expression consisting only of selection operators applied to a single array could be expressed equivalently in terms of some simpler set of operators. This expectation is fulfilled in the standard form for select expressions, to be discussed below. I look forward to seeing where you take this in R. Rich On Mon, Jan 2, 2012 at 8:38 AM, Hadley Wickham had...@rice.edu wrote: But if not, it seems to me that it should be added as an array method to ?rev with an argument specifying which indices to rev() over. Yes, agreed. Sometimes arrays seem like something bolted onto R that is missing a lot of functionality. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ 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.htmlhttp://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. -- Claudia Beleites Spectroscopy/Imaging Institute of Photonic Technology Albert-Einstein-Str. 9 07745 Jena Germany email: claudia.belei...@ipht-jena.de phone: +49 3641 206-133 fax: +49 2641 206-399 __ 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] Remove me from the mailing list
On 02.01.2012 18:53, Danai Katsande wrote: Dear Sir/Madam, Please kindly remove me from the mailing list as I no longer intend to receive emails from R help. Best [[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. Please see the footer of each mail you get that points you to the management facilities to unsubscribe yourself. Uwe Ligges __ 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] clear plot linear mixed model
Am 02-01-2012 10:54, schrieb ken knoblauch: Christof Klußcklussat email.uni-kiel.de writes: lme- lme(conc ~ name/time - 1, random=conc~time|nr,method=ML,data=measurements) see plot.augPred in the nlme package thx, but how to set primary? I always get the error plot(augPred(lme)) augPred.lme without primary can only be used with fits of groupedData objects greetings Christof __ 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] Conditionally adding a constant
Here is another approach. Probably with some thought and fingerwork, rle() could be used to avoid the while loop, but that should only slow things down if there are long runs of NAs --- there can be a lot of NAs as long as they are spaced apart and it should still be quite efficient. f - function(x, y) { i - which(x 3) cond - TRUE while (cond) { y[i] - y[i - 1] + 2L cond - any(is.na(y)) } return(y) } df - data.frame(x = c(1,2,3,4,5), y = c(10,20,30,NA,NA)) df$y - f(df$x, df$y) Cheers, Josh On Mon, Jan 2, 2012 at 4:47 AM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, I believe this works. f1 - function(x){ for(i in 2:length(x)) x[i] - ifelse(x[i-1] 3, x[i-1] + 2, x[i]) x } f2 - function(x){ for(i in 2:length(x)) x[i] - ifelse(is.na(x[i]) (x[i-1] 3), x[i-1] + 2, x[i]) x } df - data.frame(x = c(1,2,3,4,5), y = c(10,20,30,NA,NA)) apply(df, 2, f1) # df$x[4] 3, df$x[5] also changes apply(df, 2, f2) # only df$y has NA's Maybe there's a better way, avoiding the loop. Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/Conditionally-adding-a-constant-tp4253049p4253125.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. -- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, Statistical Consulting Group University of California, Los Angeles https://joshuawiley.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] Conditionally adding a constant
Here is a way of doing it without loops: df - data.frame(x = c(1,2,3,4,5), y = c(10,20,30,NA,NA)) require(zoo) # need na.locf to fix the NAs # replace NA with preceeding values df$y - na.locf(df$y) df x y 1 1 10 2 2 20 3 3 30 4 4 30 5 5 30 # assuming that you want to increment the counts when x 3 inc - cumsum(df$x 3) * 2 inc [1] 0 0 0 2 4 df$y - df$y + inc df x y 1 1 10 2 2 20 3 3 30 4 4 32 5 5 34 On Mon, Jan 2, 2012 at 1:59 PM, Joshua Wiley jwiley.ps...@gmail.com wrote: Here is another approach. Probably with some thought and fingerwork, rle() could be used to avoid the while loop, but that should only slow things down if there are long runs of NAs --- there can be a lot of NAs as long as they are spaced apart and it should still be quite efficient. f - function(x, y) { i - which(x 3) cond - TRUE while (cond) { y[i] - y[i - 1] + 2L cond - any(is.na(y)) } return(y) } df - data.frame(x = c(1,2,3,4,5), y = c(10,20,30,NA,NA)) df$y - f(df$x, df$y) Cheers, Josh On Mon, Jan 2, 2012 at 4:47 AM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, I believe this works. f1 - function(x){ for(i in 2:length(x)) x[i] - ifelse(x[i-1] 3, x[i-1] + 2, x[i]) x } f2 - function(x){ for(i in 2:length(x)) x[i] - ifelse(is.na(x[i]) (x[i-1] 3), x[i-1] + 2, x[i]) x } df - data.frame(x = c(1,2,3,4,5), y = c(10,20,30,NA,NA)) apply(df, 2, f1) # df$x[4] 3, df$x[5] also changes apply(df, 2, f2) # only df$y has NA's Maybe there's a better way, avoiding the loop. Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/Conditionally-adding-a-constant-tp4253049p4253125.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. -- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, Statistical Consulting Group University of California, Los Angeles https://joshuawiley.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. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ 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] Base function for flipping matrices
Your request is reminding me of the analysis of aray functions in Philip S Abrams dissertation http://www.slac.stanford.edu/cgi-wrap/getdoc/slac-r-114.pdf AN APL MACHINE The section that starts on page 17 with this paragraph is the one that immediately applies C. The Standard Form for Select Expressions In this section the selection operators considered are take, drop, reversal, transpose, and subscripting by scalars or _J-vectors. Because of the similarity among the selection operators, we might expect that an expression consisting only of selection operators applied to a single array could be expressed equivalently in terms of some simpler set of operators. This expectation is fulfilled in the standard form for select expressions, to be discussed below. That's fantastic - thanks for the pointer. One thing I'd like to do with the plyr package is generate a natural (and minimal) set of operators for data frames in a similar way APL did for arrays. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ 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] Create variable with AND IF statement
I usually do this kind of thing like this: variable3 - rep(1,length(variable1.fac)) variable3[ variable1.fac == 0 variable2.num = 1 ] - 2 variable3[ variable1.fac == 1 variable2.num == 0 ] - 3 variable3[ variable1.fac == 1 variable2.num = 1 ] - 4 This approach is easy to read and understand, and I would (personally) consider it analogous to the SPSS approach. This approach does require that the variables all have the same length -- which may be intrinsically built in to the SPSS data structure, but is not guaranteed in R (unless all of the variables are contained in a data frame). The key concept is that in R, the if() function is for logical objects of length=1, only. The ifelse() function is for logical objects of length 1. In R terminology, we would say that ifelse() is a vectorized function, but if() is not. The SPSS if function appears to behave in a vectorized manner. Although nested ifelse() functions can be used in this case, I find them harder to read. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 1/2/12 1:11 AM, Richard Kolodziej richard.kolodz...@web.de wrote: Hello, I'm using SPSS at work but really would like to switch to R. Right now I'm trying to learn R in reproducing calculations I did with SPSS but am stuck with something that is quite simple and comprehensible in SPSS-Syntax: IF (variable1.fac = 0 AND variable2.num = 0) variable3=1. IF (variable1.fac = 0 AND variable2.num = 1) variable3=2. IF (variable1.fac = 1 AND variable2.num = 0) variable3=3. IF (variable1.fac = 1 AND variable2.num = 1) variable3=4. I want to create four different groups out of different conditions of two variables: * variable1.fac is a factor coded with 0 and 1 * variable2.num is a numerical variable with only whole numbers My problem with R is that I can't find a way to use AND in an IF statement that doesn't produce an error or not intended solutions. An Introduction to R is really unhelpful with this problem and I wouldn't have written here, if I didn't have searched for the answer. http://tolstoy.newcastle.edu.au/R/help/05/09/12136.html was helpful in understanding how the IF statement is written in R but didn't answer my question how to add an usable AND (, |) https://stat.ethz.ch/pipermail/r-help/2008-November/178808.html looked promising but didn't do what I had intended Thanks in advance, Richard [[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] quadratic programming-maximization instead of minization
I don't have experience with this in R and I'm not sure I understand the question that well but maybe something like nearPD()? Ken Hutchison On Jan 2, 2012, at 6:36 AM, riccardo24 riccardo.giacome...@gmail.com wrote: Hi, I need to maximize a quadratic function under constraints in R. For minimization I used solve.QP but for maximization it is not useful since the matrix D of the quadratic function should be positive definite hence I cannot simply change the sign. any suggestion ? thanks -- View this message in context: http://r.789695.n4.nabble.com/quadratic-programming-maximization-instead-of-minization-tp4253011p4253011.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] find inflexion point of discrete value list with R
On Jan 2, 2012, at 11:49 AM, Ben Bolker wrote: Jonas Stein news at jonasstein.de writes: i have a list of values like this x y 1 3 2 2 [snip] and need the inflexion [sic] points (and all max and min). Is there a nice way to get the local max, min and inflexion points? diff(y) gives you the first difference, the analogue of the gradient diff(diff(y)) gives the second difference, the analogue of the second derivative. dy - diff(y) d2y - diff(dy) which(dy==0) ## critical values sign(s2y)[which(dy==0)] ## test for max/min/saddle which(d2y==0) ## inflection points I would think that testing for d2y==0 would be akin to the error in numeric analysis warned about in FAQ 7.31. Seems unlikely that in real data that there would always be three points in a row with equal differences at a true inflection and even then, many of the ones you did find satisfying that criterion would not be in fact inflection points. Wouldn't it be better to fit a spline and then do your testing on the spline approximation? Counter-example: x=1:10 y=c(1,2,3,5,7,10,13,16,20,24) dy - diff(y) d2y - diff(dy) which(d2y==0) [1] 1 3 5 6 8 And actually the original data was a pretty good counter-example as well. -- David Winsemius, MD 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] Creating ZOO Matrix from Data Frame
On Mon, 2 Jan 2012, Gabor Grothendieck wrote: Assuming you need a separate column for each site see the read.zoo split= argument. An example is here: http://r.789695.n4.nabble.com/building-time-series-zoo-its-from-a-data-frame-tp2240349p2240814.html I created a new data frame for a single stream and it has this structure: str(burns.tds) 'data.frame': 2472 obs. of 3 variables: $ site: Factor w/ 137 levels BC-0.5,BC-1,..: 5 5 5 5 5 5 5 5 ... $ sampdate: Date, format: 1992-03-27 1992-04-30 ... $ quant : num 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 8.08 ... This is in 'long' form with the date as the second column: head(burns.tds) site sampdate quant 599 BC-3 1992-03-27 0.1 600 BC-3 1992-04-30 0.1 601 BC-3 1992-05-30 0.1 603 BC-3 1992-06-19 0.1 1214 BC-3 1992-07-20 0.1 1215 BC-3 1992-08-10 0.1 I've read the read.zoo help and above URL and cannot get the syntax correct. Emulating the example at the bottom of the referenced Web page produces an error that I interpret as a need to exclude NAs. Adding na.omit to the command still produces an error: burns.tds.z - read.zoo(burns.tds, split = 1, format = %Y-%m-%d, na.omit) Error in strptime(format(x, scientific = FALSE), tz = tz, format = format): invalid 'tz' value How do I resolve this invalid 'tz' value? Or, is there another problem but this is the error presented to me? Rich __ 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] Create variable with AND IF statement
Could it be if(variable1.fac == 0 variable2.num == 0) {variable3 = 1} # brackets {} aren't strictly required for a one liner. if(variable1.fac == 0 variable2.num = 0) {variable3 = 2} # brackets {} aren't strictly required for a one liner. if(variable1.fac == 1 variable2.num == 0) {variable3 = 3} # brackets {} aren't strictly required for a one liner. if(variable1.fac == 1 variable2.num = 1) {variable3 = 4} # brackets {} aren't strictly required for a one liner. On 1/2/2012 2:11 AM, Richard Kolodziej wrote: Hello, I'm using SPSS at work but really would like to switch to R. Right now I'm trying to learn R in reproducing calculations I did with SPSS but am stuck with something that is quite simple and comprehensible in SPSS-Syntax: IF (variable1.fac = 0 AND variable2.num = 0) variable3=1. IF (variable1.fac = 0 AND variable2.num= 1) variable3=2. IF (variable1.fac = 1 AND variable2.num = 0) variable3=3. IF (variable1.fac = 1 AND variable2.num= 1) variable3=4. I want to create four different groups out of different conditions of two variables: * variable1.fac is a factor coded with 0 and 1 * variable2.num is a numerical variable with only whole numbers My problem with R is that I can't find a way to use AND in an IF statement that doesn't produce an error or not intended solutions. An Introduction to R is really unhelpful with this problem and I wouldn't have written here, if I didn't have searched for the answer. http://tolstoy.newcastle.edu.au/R/help/05/09/12136.html was helpful in understanding how the IF statement is written in R but didn't answer my question how to add an usable AND (, |) https://stat.ethz.ch/pipermail/r-help/2008-November/178808.html looked promising but didn't do what I had intended Thanks in advance, Richard [[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] find inflexion point of discrete value list with R
On 12-01-02 04:09 PM, David Winsemius wrote: On Jan 2, 2012, at 11:49 AM, Ben Bolker wrote: Jonas Stein news at jonasstein.de writes: i have a list of values like this x y 1 3 2 2 [snip] and need the inflexion [sic] points (and all max and min). Is there a nice way to get the local max, min and inflexion points? diff(y) gives you the first difference, the analogue of the gradient diff(diff(y)) gives the second difference, the analogue of the second derivative. dy - diff(y) d2y - diff(dy) which(dy==0) ## critical values sign(s2y)[which(dy==0)] ## test for max/min/saddle which(d2y==0) ## inflection points I would think that testing for d2y==0 would be akin to the error in numeric analysis warned about in FAQ 7.31. Seems unlikely that in real data that there would always be three points in a row with equal differences at a true inflection and even then, many of the ones you did find satisfying that criterion would not be in fact inflection points. Wouldn't it be better to fit a spline and then do your testing on the spline approximation? Counter-example: x=1:10 y=c(1,2,3,5,7,10,13,16,20,24) dy - diff(y) d2y - diff(dy) which(d2y==0) [1] 1 3 5 6 8 And actually the original data was a pretty good counter-example as well. The original post wasn't entirely clear, but I thought the data were indeed integers and that the discrete-state version of min/max/inflection point was indeed what was wanted. Yes, if the underlying variable is continuous you might want to use splinefun(), with its deriv= argument, and uniroot(), to find maxima and minima. Might be a little tricky in general, although with an interpolation spline between a finite set of points you can at least deal with it exhaustively. Ben __ 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] Conditionally adding a constant
Hello again, I believe we are all missing something. Isn't it possible to have NAs as the first values of 'y'? And isn't it also possible to have x[1] 3? Here is my point (I have changed function 'f2' to predict for such cases, 'f1' is rubbish) # Rui f3 - function(x, y){ inx - which(x 3) ynx - which(is.na(y)) for(i in which(inx %in% ynx)) y[ynx[i]] - y[ynx[i]-1] + 2L y } # Jim's, as a function, 'na.rm' option added or else 'df3' would produce an error require(zoo) f4 - function(x, y){ y - na.locf(y, na.rm=FALSE) inc - cumsum(x 3) * 2 y + inc } df - data.frame(x = c(1,2,3,4,5), y = c(10,20,30,NA,NA)) df df2 - data.frame(x = c(1,2,3,4,5), y = c(10,20,NA,40,NA)) df2 df3 - data.frame(x = c(1,2,3,4,5), y = rev(c(10,20,30,NA,NA))) df3 # Joshua f(df$x, df$y) # works f(df2$x, df2$y)# infinite loop f(df3$x, df3$y)# infinite loop # Rui f3(df$x, df$y) # works f3(df2$x, df2$y) # works as expected? f3(df3$x, df3$y) # works as expected? # Jim f4(df$x, df$y) # works f4(df2$x, df2$y) # works as expected? f4(df3$x, df3$y) # works as expected? If this makes sense, the performance tests are very much in favour of Jim's solution. # If this is what is asked for, test the performance # with large enough N N - 1.e5 dftest - data.frame(x=1:N, y=c(sample(c(rep(NA, 5), 10*1:5), N, replace=TRUE))) sum(is.na(dftest))/N# proportion of NAs in 'dftest' t2 - system.time(invisible(apply(dftest, 2, f2)))[c(1, 3)] t3 - system.time(invisible(f3(dftest$x, dftest$y)))[c(1, 3)] t4 - system.time(invisible(f4(dftest$x, dftest$y)))[c(1, 3)] rbind(t2=t2, t3=t3, t4=t4, t2.t3=t2/t3, t2.t4=t2/t4, t3.t4=t3/t4) Sample output user.self elapsed t2 2.93000 2.95000 t3 0.22000 0.22000 t4 0.01000 0.01000 t2.t3 13.31818 13.40909 t2.t4 293.0 295.0 t3.t4 22.0 22.0 A factor of 300 over the initial solution or 20+ over the other loop based one. Downside, it needs an extra package loaded, but 'zoo' is rather common place. Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/Conditionally-adding-a-constant-tp4253049p4254470.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] Create variable with AND IF statement
On Jan 2, 2012, at 4:22 PM, David Stevens wrote: Could it be NO. You are not reading the documentation for if carefully enough, despite several efforts to point you in the right direction. You cannot make literal transliterations of SPSS syntax work in the manner you imagine. -- David. if(variable1.fac == 0 variable2.num == 0) {variable3 = 1} # brackets {} aren't strictly required for a one liner. if(variable1.fac == 0 variable2.num = 0) {variable3 = 2} # brackets {} aren't strictly required for a one liner. if(variable1.fac == 1 variable2.num == 0) {variable3 = 3} # brackets {} aren't strictly required for a one liner. if(variable1.fac == 1 variable2.num = 1) {variable3 = 4} # brackets {} aren't strictly required for a one liner. On 1/2/2012 2:11 AM, Richard Kolodziej wrote: Hello, I'm using SPSS at work but really would like to switch to R. Right now I'm trying to learn R in reproducing calculations I did with SPSS but am stuck with something that is quite simple and comprehensible in SPSS- Syntax: IF (variable1.fac = 0 AND variable2.num = 0) variable3=1. IF (variable1.fac = 0 AND variable2.num= 1) variable3=2. IF (variable1.fac = 1 AND variable2.num = 0) variable3=3. IF (variable1.fac = 1 AND variable2.num= 1) variable3=4. I want to create four different groups out of different conditions of two variables: * variable1.fac is a factor coded with 0 and 1 * variable2.num is a numerical variable with only whole numbers My problem with R is that I can't find a way to use AND in an IF statement that doesn't produce an error or not intended solutions. An Introduction to R is really unhelpful with this problem and I wouldn't have written here, if I didn't have searched for the answer. http://tolstoy.newcastle.edu.au/R/help/05/09/12136.html was helpful in understanding how the IF statement is written in R but didn't answer my question how to add an usable AND (, |) https://stat.ethz.ch/pipermail/r-help/2008-November/178808.html looked promising but didn't do what I had intended Thanks in advance, Richard [[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. David Winsemius, MD 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] Conditionally adding a constant
Good points, Rui. On Mon, Jan 2, 2012 at 12:48 PM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello again, I believe we are all missing something. Isn't it possible to have NAs as the first values of 'y'? And isn't it also possible to have x[1] 3? Theoretically, yes, in the OPs data, maybe? If the data is a time series (or time series like), the zoo package is not a bad environment to be working in anyways. There are all sorts of handy functions (I had almost recommended na.approx() which replaces NAs with a linear interpolation) based on the OPs little example dataset. Not sure if the +2 thing is just an attempt at interpolation though or something more general. Here is my point (I have changed function 'f2' to predict for such cases, 'f1' is rubbish) # Rui f3 - function(x, y){ inx - which(x 3) ynx - which(is.na(y)) for(i in which(inx %in% ynx)) y[ynx[i]] - y[ynx[i]-1] + 2L y } # Jim's, as a function, 'na.rm' option added or else 'df3' would produce an error require(zoo) f4 - function(x, y){ y - na.locf(y, na.rm=FALSE) inc - cumsum(x 3) * 2 y + inc } df - data.frame(x = c(1,2,3,4,5), y = c(10,20,30,NA,NA)) df df2 - data.frame(x = c(1,2,3,4,5), y = c(10,20,NA,40,NA)) df2 df3 - data.frame(x = c(1,2,3,4,5), y = rev(c(10,20,30,NA,NA))) df3 # Joshua f(df$x, df$y) # works f(df2$x, df2$y) # infinite loop f(df3$x, df3$y) # infinite loop # Rui f3(df$x, df$y) # works f3(df2$x, df2$y) # works as expected? f3(df3$x, df3$y) # works as expected? # Jim f4(df$x, df$y) # works f4(df2$x, df2$y) # works as expected? f4(df3$x, df3$y) # works as expected? If this makes sense, the performance tests are very much in favour of Jim's solution. # If this is what is asked for, test the performance # with large enough N N - 1.e5 dftest - data.frame(x=1:N, y=c(sample(c(rep(NA, 5), 10*1:5), N, replace=TRUE))) sum(is.na(dftest))/N # proportion of NAs in 'dftest' t2 - system.time(invisible(apply(dftest, 2, f2)))[c(1, 3)] t3 - system.time(invisible(f3(dftest$x, dftest$y)))[c(1, 3)] t4 - system.time(invisible(f4(dftest$x, dftest$y)))[c(1, 3)] rbind(t2=t2, t3=t3, t4=t4, t2.t3=t2/t3, t2.t4=t2/t4, t3.t4=t3/t4) Sample output user.self elapsed t2 2.93000 2.95000 t3 0.22000 0.22000 t4 0.01000 0.01000 t2.t3 13.31818 13.40909 t2.t4 293.0 295.0 t3.t4 22.0 22.0 A factor of 300 over the initial solution or 20+ over the other loop based one. Downside, it needs an extra package loaded, but 'zoo' is rather common place. Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/Conditionally-adding-a-constant-tp4253049p4254470.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. -- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, Statistical Consulting Group University of California, Los Angeles https://joshuawiley.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] Very strange function() behaviour.
Hi Bert, Sorry for the sub-par post.. again. I've revamped my OP, I hope it's sufficient now. Thank you. - Isaac Research Assistant Quantitative Finance Faculty, UTS -- View this message in context: http://r.789695.n4.nabble.com/as-formula-with-either-lapply-or-for-loop-tp4252877p4254847.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] tm.plugin.sentiment
Hello, Can you please, as a matter of urgency, tell me which R version support tm.plugin.sentiment and how I can install the package in R studio. I use window 7. Thanks. [[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] Is using glht with Tukey for lme post-hoc comparisons an appropriate substitute to TukeyHSD?
Hello, I am trying to determine the most appropriate way to run post-hoc comparisons on my lme model. I had originally planned to use Tukey HSD method as I am interested in all possible comparisons between my treatment levels. TukeyHSD, however, does not work with lme. The only other code that I was able to find, and which also seems to be widely used, is glht specified with Tukey: summary(glht(model, linfct=mcp(Treatment=Tukey))) Out of curiosity, I ran TukeyHSD and the glht code for a simple ANOVA and found that they had quite different p-values. If the glht code is not running TukeyHSD, what does the Tukey in the code specify? Is using glht code appropriate if I am interested in a substitute for TukeyHSD? Are there any other options for multiple comparisons for lme models? I am really interested in knowing if the Tukey contrasts generated from the glht code is providing me with appropriate p-values for my post-hoc comparisons. I feel like I have reached a dead end and am not sure where else to look for information on this issue. I would be grateful for any feedback on this matter. Anne Cheverie M.Sc. Candidate Dalhousie University __ 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] Conditionally adding a constant
If you are worried about an NA in the first, then use the following: y - c(NA, 1, 2, NA, 4, NA) y - na.locf(y, na.rm = FALSE) y [1] NA 1 2 2 4 4 y - na.locf(y, fromLast = TRUE) y [1] 1 1 2 2 4 4 On Mon, Jan 2, 2012 at 5:07 PM, Joshua Wiley jwiley.ps...@gmail.com wrote: Good points, Rui. On Mon, Jan 2, 2012 at 12:48 PM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello again, I believe we are all missing something. Isn't it possible to have NAs as the first values of 'y'? And isn't it also possible to have x[1] 3? Theoretically, yes, in the OPs data, maybe? If the data is a time series (or time series like), the zoo package is not a bad environment to be working in anyways. There are all sorts of handy functions (I had almost recommended na.approx() which replaces NAs with a linear interpolation) based on the OPs little example dataset. Not sure if the +2 thing is just an attempt at interpolation though or something more general. Here is my point (I have changed function 'f2' to predict for such cases, 'f1' is rubbish) # Rui f3 - function(x, y){ inx - which(x 3) ynx - which(is.na(y)) for(i in which(inx %in% ynx)) y[ynx[i]] - y[ynx[i]-1] + 2L y } # Jim's, as a function, 'na.rm' option added or else 'df3' would produce an error require(zoo) f4 - function(x, y){ y - na.locf(y, na.rm=FALSE) inc - cumsum(x 3) * 2 y + inc } df - data.frame(x = c(1,2,3,4,5), y = c(10,20,30,NA,NA)) df df2 - data.frame(x = c(1,2,3,4,5), y = c(10,20,NA,40,NA)) df2 df3 - data.frame(x = c(1,2,3,4,5), y = rev(c(10,20,30,NA,NA))) df3 # Joshua f(df$x, df$y) # works f(df2$x, df2$y) # infinite loop f(df3$x, df3$y) # infinite loop # Rui f3(df$x, df$y) # works f3(df2$x, df2$y) # works as expected? f3(df3$x, df3$y) # works as expected? # Jim f4(df$x, df$y) # works f4(df2$x, df2$y) # works as expected? f4(df3$x, df3$y) # works as expected? If this makes sense, the performance tests are very much in favour of Jim's solution. # If this is what is asked for, test the performance # with large enough N N - 1.e5 dftest - data.frame(x=1:N, y=c(sample(c(rep(NA, 5), 10*1:5), N, replace=TRUE))) sum(is.na(dftest))/N # proportion of NAs in 'dftest' t2 - system.time(invisible(apply(dftest, 2, f2)))[c(1, 3)] t3 - system.time(invisible(f3(dftest$x, dftest$y)))[c(1, 3)] t4 - system.time(invisible(f4(dftest$x, dftest$y)))[c(1, 3)] rbind(t2=t2, t3=t3, t4=t4, t2.t3=t2/t3, t2.t4=t2/t4, t3.t4=t3/t4) Sample output user.self elapsed t2 2.93000 2.95000 t3 0.22000 0.22000 t4 0.01000 0.01000 t2.t3 13.31818 13.40909 t2.t4 293.0 295.0 t3.t4 22.0 22.0 A factor of 300 over the initial solution or 20+ over the other loop based one. Downside, it needs an extra package loaded, but 'zoo' is rather common place. Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/Conditionally-adding-a-constant-tp4253049p4254470.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. -- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, Statistical Consulting Group University of California, Los Angeles https://joshuawiley.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. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ 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] where to ask questions regarding package=ncdf?
Should one ask questions relating to the R package 'ncdf' here? or look for a more netCDF-oriented (but probably less R-oriented) list? Why I ask: I'm relatively new to R, which I've only used in the past for graphics. I'm trying to learn R as an alternative to manipulating netCDF files with NCO (which works well but lacks all the other R goodnesses). Hence I've got a range of questions which are more-or-less R-related and more-or-less netCDF-related, and I'm wondering where to go for answers to questions that are less generically R-related, and more about the ncdf implementation. (FWIW I'm currently using package=ncdf rather than package=ncdf4 because the group with which I'm working currently uses netCDF libraries built without netcdf4/hdf.) __ 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] where to ask questions regarding package=ncdf?
On Mon, Jan 2, 2012 at 6:08 PM, Tom Roche tom_ro...@pobox.com wrote: Should one ask questions relating to the R package 'ncdf' here? or look for a more netCDF-oriented (but probably less R-oriented) list? Hi Tom, you can ask here and I can give a shot at answering them (I'm the author of the ncdf and ncdf4 packages). The netcdf library also has a mailing list run out of ucar, but that doesn't usually address packages that use netcdf so much as the library itself. Regards, --Dave -- David W. Pierce Division of Climate, Atmospheric Science, and Physical Oceanography Scripps Institution of Oceanography, La Jolla, California, USA (858) 534-8276 (voice) / (858) 534-8561 (fax)dpie...@ucsd.edu [[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] [newbie] pager for large matrix?
summary: I'd like a tool to use within an R session (better yet an ESS buffer) that would * (minimally) allow me to page (à la `less`) a large sparse matrix * (preferably) page row-wise (i.e., show all values for row=1 before proceeding to row=2) details: Apologies if this is a FAQ, but I didn't find anything in `help.print` or google=R pager. (If there's a better way to search for answers to this sort of question, please lemme know.) I'm new to R, though not to computing. I've been using linux for many years (and before that cygwin) and am very fond of `less` for paging output. I'm using R package=ncdf to load parts of a large netCDF file, e.g., var_01 - get.var.ncdf(filedata, var, start=c(1,1,1,1), count=c(459,299,1,1)) class(var_01) [1] matrix dim(var_01) [1] 459 299 I'd like to be able to view values directly (more on why and how follows), but when I do print(var_01) I get output like [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [1,] NA NA NA NA NA NA NA NA NANANANA ... [334,] NA NA NA NA NA NA NA NA NANANANA [,13] [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [1,]NANANANANANANANANANA ... [196,]NANANANANA 5.36 6.11 6.87 9.44NA ... [210,] 0.19 0.80 2.01 3.93NANANANANANA ... [334,]NANANANANANANANANANA and so on ... for a very long time. I can then scroll up the buffer (I'm running R inside of ESS http://ess.r-project.org/Manual/ess.html ) but it's a PITA, since `print` - prints the whole 459x299 mx all at once. I'd much prefer to be able to control the flow of output, à la `less`, so that's my major ask: what to use for an R pager (whether in a console or an ESS buffer)? - is printing hundreds of rows at a time. `print` is correctly sensing the width of the console (actually an emacs frame) and only printing as many columns as will fit in that width (see example above). However, for some reason `print` is also choosing to format output by a row height row.h=334 (not sure how it chose 334), which is *waaay* more rows than I can handle at once. I'd much prefer row-wise output, i.e., one row at a time, e.g., [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [1,] ... [,13] [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [1,] ... ... [,291] [,292] [,293] [,294] [,295] [,296] [,297] [,298] [,299] [1,] ... [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [2,] ... For extra credit, I'd prefer a tool that sensed when a row was all NA and didn't waste my time. E.g., if all the cells in the first row contained value=NA, but the second row contained non-NA values, the output would be like [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [1,] NA... [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [2,] ... [,13] [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [2,] ... ... [,291] [,292] [,293] [,294] [,295] [,296] [,297] [,298] [,299] [2,] ... But that's gravy: all I really want is a pager, and preferably one that will allow me to output row-wise. Is there such a tool for R? or ESS? TIA, Tom Roche tom_ro...@pobox.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] Changing X axis of ggplot
Thanks to Joshua Wiley for turning me on to ggplot2. I am making a plot using this: p - ggplot(dallas, aes(x = offense_hour)) + geom_bar() + coord_polar() Dallas is a data frame, and offense_hour is a column with chron objects from the chron library. In this case, the chron object was created with the times function. It is only a time (H:M:S) with no date attached. The plot shows up fine, but the X axis labels are 0.0 through 1.0. How do I convert this to 0:00 through 23:59 (or whatever may be appropriate given the breaks)? My searches lead me to scale_x_discrete, but I am not clear if that's even the right function. Aren __ 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 using glht with Tukey for lme post-hoc comparisons an appropriate substitute to TukeyHSD?
glht is probably what you should be using. Both TukeyHSD and glht give essesntially identical confidence intervals for the example in ?glht. What aren't you satisfied with? amod - aov(breaks ~ tension, data = warpbreaks) confint(glht(amod, linfct = mcp(tension = Tukey))) TukeyHSD(amod) On Mon, Jan 2, 2012 at 6:19 PM, Anne Aubut an438...@dal.ca wrote: Hello, I am trying to determine the most appropriate way to run post-hoc comparisons on my lme model. I had originally planned to use Tukey HSD method as I am interested in all possible comparisons between my treatment levels. TukeyHSD, however, does not work with lme. The only other code that I was able to find, and which also seems to be widely used, is glht specified with Tukey: summary(glht(model, linfct=mcp(Treatment=Tukey))**) Out of curiosity, I ran TukeyHSD and the glht code for a simple ANOVA and found that they had quite different p-values. If the glht code is not running TukeyHSD, what does the Tukey in the code specify? Is using glht code appropriate if I am interested in a substitute for TukeyHSD? Are there any other options for multiple comparisons for lme models? I am really interested in knowing if the Tukey contrasts generated from the glht code is providing me with appropriate p-values for my post-hoc comparisons. I feel like I have reached a dead end and am not sure where else to look for information on this issue. I would be grateful for any feedback on this matter. Anne Cheverie M.Sc. Candidate Dalhousie University __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] nls and rbinom function: step factor 0.000488281 reduced below 'minFactor' of 0.000976562
I am trying to learn nls using a simple simulation. I assumed that the binomial prob varies linearly as 0.2 + 0.3*x in x {0,1}, and the objective is to recover the known parameters a=0.2, b=0.3 ..data frame d has 1000 rows... d$x-runif(0,1) d$y-rbinom(1000,1,0.2+0.3*d$x) table(d$y,cut(d$x,breaks=5)); (-0.000585,0.199] (0.199,0.399] (0.399,0.599] (0.599,0.799] (0.799,0.999] 0 154 149 130 122 114 1 34 48 71 76 102 z - nls(y ~ rbinom(1000,1,a+b*x),data=d,start= list(a =0.1,b=0.2),trace=T); 374 : 0.1 0.2 361 : 0.1 0.2 350 : 0.1 0.2 Error in nls(y ~ rbinom(1000, 1, a + b * x), data = d, start = list(a = 0.1, : step factor 0.000488281 reduced below 'minFactor' of 0.000976562 I have tried plinear, got the same Additionaly- why does the parameters not change with the iteration ? [[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] Changing X axis of ggplot
Aren, On 2 January 2012 19:34, Aren Cambre a...@arencambre.com wrote: I am making a plot using this: p - ggplot(dallas, aes(x = offense_hour)) + geom_bar() + coord_polar() The plot shows up fine, but the X axis labels are 0.0 through 1.0. How do I convert this to 0:00 through 23:59 (or whatever may be appropriate given the breaks)? Seeing as there is no source code, I'm taking a stab in the dark, but the below gives me a pie chart: to - as.POSIXlt('23:59:59', format='%H:%M:%S', origin=Sys.Date()) from - as.POSIXlt('00:00:00', format='%H:%M:%S', origin=Sys.Date()) range - seq(from, to, by = .5) dallas - data.frame(offense_hour = range, stuff = rnorm(c(1:length(range p - ggplot(dallas, aes(x = offense_hour) + geom_bar() + coord_polar) -- Sent from my mobile device Envoyait de mon portable __ 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] Options for generating editable figures?
Hello all, I'm using R to produce figures for people who want to be able to edit the figures directly, and who use PowerPoint a lot. I use a Mac, and I'd appreciate any advice about how to approach this. Here's what I've come up with so far: 1) I can use xfig() and then ask them to install Inkscape to edit the files. Downsides are no transparency and a learning curve with Inkscape. 2) I can do the same as above but with svg() instead of xfig(). But for reasons I don't understand, when I use svg() I can't seem to edit the resulting figures' text objects in Inkscape. 3) I can try to install UniConvertor, which sounds like quite a task for someone of my modest skills. This would supposedly allow me to create .wmf files, which might (and I've read conflicting things about this) be importable into PowerPoint as editable graphics. 4) I found an old suggestion in the archives that an EPS could be imported into PowerPoint and made editable. This almost worked for me (using Inkscape to convert a cairo_ps()-generated file to EPS) -- but only using PowerPoint under Windows, and lots of vectors and all text were lost along the way. Am I on the right track? Am I missing any better pathways? I know similar questions have come up before, but the discussions I found in the archives were old, and maybe things have changed in recent years. Thanks for any advice! --Allen McBride R version: 2.13.1 Platform: Mac OS 10.7.2 __ 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] Biglm source code alternatives (E.g. Call to Fortran)
Hi everyone, I have been looking at the Bigglm (Basically does Generalised Linear Models for big data under the Biglm package) command and I have done some profiling on this code and found that to do a GLM on a 100mb file (9 million rows by 5 columns matrix(most of the numbers were either a 0,1 or 2 randomly generated)) it took about 2 minutes on a linux machine with 8gb of RAM and 4 cores. Ideally I want to run this much quicker probably around 30 seconds to 60 seconds and after viewing the profiling code I noticed these things: summaryRprof('method2.out') $by.self self.time self.pct total.time total.pct model.matrix.default 24.84 19.4 26.40 20.6 .Call 21.00 16.4 21.00 16.4 as.character 17.92 14.0 17.92 14.0 [.data.frame 14.04 11.0 22.54 17.6 * 6.44 5.0 6.44 5.0 update.bigqr 5.34 4.2 15.32 12.0 - 4.52 3.5 4.52 3.5 anyDuplicated.default 4.12 3.2 4.12 3.2 / 3.76 2.9 3.76 2.9 attr 3.26 2.5 3.26 2.5 | 2.96 2.3 2.96 2.3 unclass 2.82 2.2 2.82 2.2 na.omit2.42 1.9 17.18 13.4 sum 2.02 1.6 2.02 1.6 I did some further investigation and it appears the .Call command to fortran seems slow. This function is under the coef.bigqr.R and singcheck.bigqr.R functions in the biglm package. Is there an alternative way to implement the call to Fortran? As I thought matrix inversion and QR/Cholesky decomposition can be done much faster on low level design software platforms like Fortran so I was surprised by the 21 second timeframe. Furthermore are there any other packages or platforms I can implement to speed up the as.character or model.matrix commands. My expertise in R is very limited but I realise R also has the ability to do parallel computing. Is this also a possible solution to running a GLM on a big dataset very quickly. Alternatively I could increase memory and add more cores but this isn't really a long term solution as I know that I will eventually work with bigger datasets. In fact GLM is such a common tool that I think this would benefit a lot of people in the R community if it could be run quicker for bigger data using existing packages such as ff, doMC, parallel, biglm, bigmemory. Your help would be greatly appreciated, hardworker -- View this message in context: http://r.789695.n4.nabble.com/Biglm-source-code-alternatives-E-g-Call-to-Fortran-tp4255774p4255774.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] About source()
Hello, I am a beginner to the R language and find it fantastic and well-designed, quite different from other programming languages. This is the first time I post on the r-help mailing list. In invoking the function source(filename), it seems that the filename has to exist in the current working directory, otherwise it has to be specified in full path. So is there any mechanism(such as environment variable) to specify an additional directory of .R files that source() could search in? Thanks in advance! Li Sun Department of Physics University of California, San Diego __ 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 X axis of ggplot
Hi Aren, Could you perhaps send us the output of: dput(dallas[1:40, offense_hour, drop = FALSE]) I believe your problem, but getting it to work in ggplot2 will be easiest working with your actual data (or a bit of it anyway). for ggplot2 specific questions, you might also checkout: groups.google.com/group/ggplot2 a lot of very clever ggplot2ers there (including the author much more than he is around Rhelp). Cheers, Josh On Mon, Jan 2, 2012 at 7:34 PM, Aren Cambre a...@arencambre.com wrote: Thanks to Joshua Wiley for turning me on to ggplot2. I am making a plot using this: p - ggplot(dallas, aes(x = offense_hour)) + geom_bar() + coord_polar() Dallas is a data frame, and offense_hour is a column with chron objects from the chron library. In this case, the chron object was created with the times function. It is only a time (H:M:S) with no date attached. The plot shows up fine, but the X axis labels are 0.0 through 1.0. How do I convert this to 0:00 through 23:59 (or whatever may be appropriate given the breaks)? My searches lead me to scale_x_discrete, but I am not clear if that's even the right function. Aren __ 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. -- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, Statistical Consulting Group University of California, Los Angeles https://joshuawiley.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] About source()
On 03/01/12 17:02, Li SUN wrote: Hello, I am a beginner to the R language and find it fantastic and well-designed, quite different from other programming languages. What a refreshingly sensible attitude!!! :-) This is the first time I post on the r-help mailing list. In invoking the function source(filename), it seems that the filename has to exist in the current working directory, otherwise it has to be specified in full path. So is there any mechanism(such as environment variable) to specify an additional directory of .R files that source() could search in? I'm no expert on this, and others may correct me, but (1) I don't believe any such mechanism exists. (2) It's probably not a good idea, even if such a mechanism were to exist. Directories have a tree structure, rather than being linearly ordered in the way that data bases on your R search path are ordered. I believe you would run all sorts of risks of confusion and of getting the wrong file were you to invoke such a mechanism. It is ``good practice'' to have separate directories associated with different projects and to situate all files, that you might wish to source in respect of a given project, in the directory associated with that project. I know that this is an irritating sort of response --- ``No, you can't do that, and you shouldn't do it anyway!'' --- but I sincerely believe this to be true. That being said, I also believe that you could program up such a mechanism yourself. I.e. build a function source2() which would have a hard coded list of directories to search, and would make use of the try() function. Might be a good exercise for you, given that you are starting out in R and looking to upgrade your skills! :-) cheers, Rolf Turner __ 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 it possible to right align text in R graphics?
Incidentally, gMail (on Windows) correctly rendered the Hebrew (Shalom Olam), so it would seem that this probably is a plotting issue rather than an OS issue I tested a Persian text with this kind of parentheses in linux and windows, and it seem it is indeed an OS issue. The text renders correct on my linux 2.6.32 i686 system with R 2.14.1 but incorrect on my windows 7 (6.1.7600) 32 bit system with R 2.14.0. -- Majid Einian, PhD Candidate in Economics, Graduate School of Management and Economics, Sharif University of Technology, Tehran, IRAN [[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] An R interface to Model Building
Hello all, To anyone who is interested, I'm trying to learn a bit more about developing applications in R with user interfaces. I've been playing around with gWidgets to develop a model building interface. I'd appreciate any comments, suggestions, or guidance on how to better structure my R code and organize the programming task. In addition, any suggestions for features and improvement to this fledgling project would be welcomed. The code and some screenshots are available here... http://r-rime.blogspot.com/ Thanks! __ 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] summary per group
Hi Hi Hello, I know that it'll be quite easy to do what I want but somehow I am lost as I am new to R. I want to get summary results arranged by groups. In detail I'd like get the number (levels) of Species per Family like for this dataset: SPEC - factor(c(a,a,b,b,c,c,c,d,e,e,e,e)) FAM - factor(c(A,A,A,A,B,B,B,C,C,C,C,C)) df - data.frame(SPEC,FAM) I tried tapply(SPEC, FAM, nlevels).. but it is not the result I am looking for... What is the easiest way to do that? Do I have to rearrange the dataset? To do what? Do you want number of unique entries within each level of FAM? If yes sapply(tapply(SPEC, FAM, unique), length) can do this. Regards Petr Thank you Petr, that is exactly what I was looking for... no I played a little bit around with that because I want to create a summary with FAM as a grouping variable. Beside the number of unique SPEC per FAM also want to get their levels as text. So far I know I have following: paste(unique(SPEC), collapse = ', ') But how can I use that in combination with tapply and furthermore with cbind like: SPEC - factor(c(a,a,b,b,c,c,c,d,e,e,e,e)) FAM - factor(c(A,A,A,A,B,B,B,C,C,C,C,C)) df - data.frame(SPEC,FAM) with(df, cbind(Number of SPEC=sapply(tapply(SPEC,FAM,unique),length), SPECs=tapply(SPEC,FAM,unique))) Quite close with(df, cbind(Number of SPEC=sapply(tapply(SPEC,FAM,unique),length), SPECs=sapply(tapply(SPEC,FAM,unique), paste, collapse=,))) You can easily look on chunks of this code with(df, sapply(tapply(SPEC,FAM,unique),length)) with(df, sapply(tapply(SPEC,FAM,unique), paste, collapse=,)) with(df, tapply(SPEC,FAM,unique)) actually you could do better with res - with(df, tapply(SPEC,FAM,unique)) and cbind(Number of SPEC=sapply(res,length),SPECs=sapply(res, paste, collapse=,)) One comment (quite important). With cbind the result is matrix. Matrix is a vector with dimensions and as such it can have only values of one type. In this case you end with character values so the numbers are converted to character. If you want it to stay nubers you need to use data.frame see ?matrix ?data.frame and R-intro especially part regarding objects and their properties. Regards Petr The result should look like: Number of SPEC SPECs A 2 a, b B 1 c C 2 d, e Thank you, /johannes -- NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie! Jetzt informieren: http://www.gmx.net/de/go/freephone __ 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.