[R] recommended way to group function calls in Sweave
Dear all When using Sweave, I'm always hitting the same bump: I want to group repetitive calls in a function, but I want both the results and the function calls in the printed output. Let me explain myself. Consider the following computation in an Sweave document: summary(iris[,1:2]) cor(iris[,1:2]) When using these two calls directly, I obtain the following output: summary(iris[,1:2]) Sepal.LengthSepal.Width Min. :4.300 Min. :2.000 1st Qu.:5.100 1st Qu.:2.800 Median :5.800 Median :3.000 Mean :5.843 Mean :3.057 3rd Qu.:6.400 3rd Qu.:3.300 Max. :7.900 Max. :4.400 cor(iris[,1:2]) Sepal.Length Sepal.Width Sepal.Length1.000 -0.1175698 Sepal.Width-0.1175698 1.000 However, if I try to group the calls in a function: f - function(d, ind){ print(summary(d[ , ind])) print(cor(d[ , ind])) return(invisible(NULL)) } Then I get a different output in the Sweave PDF: f(iris, 1:2) Sepal.LengthSepal.Width Min. :4.300 Min. :2.000 1st Qu.:5.100 1st Qu.:2.800 Median :5.800 Median :3.000 Mean :5.843 Mean :3.057 3rd Qu.:6.400 3rd Qu.:3.300 Max. :7.900 Max. :4.400 Sepal.Length Sepal.Width Sepal.Length1.000 -0.1175698 Sepal.Width-0.1175698 1.000 Of course I can use 'echo=F' to remove the ' f(iris, 1:2)' in the above, but how can I do to keep the original calls 'summary(d[ , ind])' and 'cor(d[ , ind])'? Or even better, could the actual calls be used, after the replacement of arguments by their values: 'summary(iris[,1:2])' and 'cor(iris[,1:2])'. Or is the recommended way to use cat()-ed statements: f - function(d, ind){ cat('Variable summary:\n') print(summary(d[ , ind])) cat('\nCorrelation table:\n') print(cor(d[ , ind])) return(invisible(NULL)) } To obtain such output: f(iris, 1:2) Variable summary: Sepal.LengthSepal.Width Min. :4.300 Min. :2.000 1st Qu.:5.100 1st Qu.:2.800 Median :5.800 Median :3.000 Mean :5.843 Mean :3.057 3rd Qu.:6.400 3rd Qu.:3.300 Max. :7.900 Max. :4.400 Correlation table: Sepal.Length Sepal.Width Sepal.Length1.000 -0.1175698 Sepal.Width-0.1175698 1.000 What is the recommended way of grouping repetitive function calls? What do you usually use in your own documents? Regards Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] recommended way to group function calls in Sweave
On Wed, Apr 25, 2012 at 3:41 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: I would use the last method, or if the calls were truly repetitive (i.e. always identical, not just the same pattern), use a named chunk. Labeled chunks are indeed what I was looking for [1]. As far as I understand, this is what Sweave functions (or are these macros?) look like: = d - iris ind - 1:2 @ sw= summary(d[ , ind]) cor(d[ , ind]) @ = d - iris ind - 2:4 sw @ Regards Liviu [1] vignette('Sweave', 'utils') __ 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] Organizations where IT has approved the use of R software
On Fri, Apr 13, 2012 at 8:56 AM, Michael Bibo michael_b...@health.qld.gov.au wrote: Have you seen this from the archives? http://www.mail-archive.com/r-help@r-project.org/msg45768.html In addition see [1], which highlights the likes of Google, Merck or Stanford University. Liviu [1] http://www.r-project.org/foundation/memberlist.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] plyr: set '.progress' argument to default to text
Dear all Is it possible to set globally the option .progress = text to all the apply functions in 'plyr'. For example, current default is daply(..., .progress = none). I would like to set it to daply(..., .progress = text), so as to avoid writing the argument every time I call such a function. I looked into ?daply and ?create_progress_bar without much luck. Regards Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] plyr: set '.progress' argument to default to text
On Tue, Apr 10, 2012 at 5:32 PM, R. Michael Weylandt michael.weyla...@gmail.com wrote: You might try the Defaults package. Thanks for the hint. Unfortunately library(Defaults) setDefaults('create_progress_bar', name = text) doesn't do the trick. But one can set defaults for each *ply() function individually: setDefaults('ddply', .progress = text) setDefaults('daply', .progress = text) Regards Liviu __ 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 generated means are different from the boxplot!
Hello On Fri, Apr 6, 2012 at 10:35 AM, Jhope jeanwaij...@gmail.com wrote: Hi R-listers, 1) I am having trouble understanding why the means I have calculated from Aeventexhumed (A, B, and C) are different from the means showing on the boxplot I generated (see attached). I have added the script as to how my data is organized. For starters, boxplots do not display means but medians. [1] [1] http://en.wikipedia.org/wiki/Boxplot 2) Also when I went through the data manually the means I calculated for each nesting event are slightly different than what I generated through R (see below). A, B, C 0.2155051, 0.1288241, 0.1124618 Just guessing, perhaps it is due to some missing values. Regards Liviu Thanks in advance, Jean --- require(plyr) Loading required package: plyr resp - read.csv(file.choose()) envir - read.csv(file.choose()) resp - resp[!is.na(resp$Aeventexhumed), ] resp$QuadratEvent - paste(resp$QuadratID, resp$Aeventexhumed, sep=) resp$QuadratEvent - as.character(resp$QuadratEvent) envir - envir[!is.na(envir$Aeventexhumed), ] envir$QuadratEvent - paste(envir$QuadratID, envir$Aeventexhumed, sep=) envir$QuadratEvent - as.character(envir$QuadratEvent) ExDate - Sector - Quadrat - Aeventexhumed - NULL ST1 - ST2 - ST3 - ST4 - ST0 - NULL Shells - Hatchlings - MaxHatch - DeadHatch - NULL Oldeggs - TotalEggs - QuadratEvent - NULL for (q in unique(as.character(resp$QuadratEvent))) { + s - resp[as.character(resp$QuadratEvent) == q, ] + ExDate - c(ExDate, as.character(s$ExDate[1])) + Sector - c(Sector, as.character(s$Sector[1])) + Quadrat - c(Quadrat, as.character(s$Quadrat[1])) + Aeventexhumed - as.character(c(Aeventexhumed, as.character(s$Aeventexhumed[1]))) + QuadratEvent- c(QuadratEvent, q) + ST1 - c(ST1, sum(s$ST1, na.rm=TRUE)) + ST2 - c(ST2, sum(s$ST2, na.rm=TRUE)) + ST3 - c(ST3, sum(s$ST3, na.rm=TRUE)) + ST4 - c(ST4, sum(s$ST4, na.rm=TRUE)) + ST0 - c(ST0, sum(s$ST0, na.rm=TRUE)) + Shells - c(Shells, sum(s$Shells, na.rm=TRUE)) + Hatchlings - c(Hatchlings, sum(s$Hatchlings, na.rm=TRUE)) + MaxHatch - c(MaxHatch, sum(s$MaxHatch, na.rm=TRUE)) + DeadHatch - c(DeadHatch, sum(s$DeadHatch, na.rm=TRUE)) + Oldeggs - c(Oldeggs, sum(s$Oldeggs, na.rm=TRUE)) + TotalEggs - c(TotalEggs, sum(s$TotalEggs, na.rm=TRUE)) + } responses - data.frame(QuadratEvent, ExDate, Sector, Quadrat, + Aeventexhumed, ST0, ST1, ST2, ST3, ST4, Shells, + Hatchlings, MaxHatch, DeadHatch, Oldeggs, + TotalEggs, stringsAsFactors=FALSE) responses$QuadratEvent - as.character(responses$QuadratEvent) data.to.analyze - join(responses, envir, by=QuadratEvent) data.to.analyze$NotHatched - data.to.analyze$TotalEggs - data.to.analyze$Shells data.to.analyze$Rayos - paste(Rayos, data.to.analyze$Rayos, sep=.) Hsuccess - Shells/TotalEggs tapply(Hsuccess, Aeventexhumed, mean, na.rm=TRUE) A B C 0.2156265 0.1288559 0.1124327 boxplot(HSuccess ~ Aeventexhumed, data = data.to.analyze, col = blue, + main = Hatching Success of Arribadas in 2010, + xlab = Arribada Event, + ylab = Hatching Success % (Shells / Total Eggs)) http://r.789695.n4.nabble.com/file/n4536926/hatch_Aeventexhumed.png -- View this message in context: http://r.789695.n4.nabble.com/R-generated-means-are-different-from-the-boxplot-tp4536926p4536926.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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] reclaiming lost memory in R
On Fri, Apr 6, 2012 at 2:21 PM, Ramiro Barrantes ram...@precisionbioassay.com wrote: Please let me know if you have any other suggestions or clues. See this older post by Brian [1] and check ?Memory-limits. Otherwise, I remember someone suggesting that even if R releases the memory internally, the OS may still keep it reserved for the R process. (Unfortunately I cannot find the reference.) Regards Liviu [1] http://tolstoy.newcastle.edu.au/R/e10/help/10/05/3851.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] spaghetti plots in R
On Wed, Apr 4, 2012 at 4:22 PM, uday uday_143...@hotmail.com wrote: I would like to plat some spaghetti plots from my data , ma data is as See: require(sos) findFn('spaghetti') Liviu follows ak[1:3,] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [1,] 0.3211745 0.4132568 0.5649930 0.6920562 0.7760113 0.8118568 0.8609301 0.9088819 0.9326736 [2,] 0.3159234 0.4071270 0.5579212 0.6844584 0.7684690 0.8243702 0.8677043 0.8931288 0.9261926 [3,] 0.3075260 0.3993699 0.5493242 0.6765600 0.7614591 0.8127050 0.8537816 0.8884786 0.9343690 [,10] [,11] [,12] [1,] 0.9605178 1 1.003940 [2,] 0.9647617 1 1.012930 [3,] 0.9618874 1 1.007103 dim(ak[1:3,]) [1] 3 12 pre[1:3,] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 10.34615 52.02116 146.1736 243.2864 347.4150 431.6711 521.4271 629.0045 729.9594 827.8628 [2,] 10.34615 52.02539 146.3670 244.3871 350.1785 454.6706 546.5499 638.3344 741.9849 842.5700 [3,] 10.34615 52.02754 146.4656 244.9480 351.5865 457.1768 550.1341 643.0880 748.1114 850.0670 [,11] [,12] [1,] 921.5508 956.4445 [2,] 953.9648 995.8201 [3,] 951.6384 987.9105 dim(pre) 3 12 I have tried plot(ak[1,],pre[1,],type=l) lines(ak[2,],pre[2,],type=l,col=red) but it only works for few data, but I have very big list and data is in matrix format. I would be very glad if someone can help me to fix this issue. -- View this message in context: http://r.789695.n4.nabble.com/spaghetti-plots-in-R-tp4532021p4532021.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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] spaghetti plots in R
On Wed, Apr 4, 2012 at 5:04 PM, uday uday_143...@hotmail.com wrote: Hi Liviu , thanks for post , but I could not find findFn('spaghetti') , I can see the following functions in sos package Extract.findFn findFn After installing 'sos', use the 'findFn()' function. For example, run findFn('spaghetti') See the documentation of ?findFn. Alternatively, look into RcmdrPlugin.sos. Regards Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to use Latex code in R loop?
On Sun, Apr 1, 2012 at 4:48 PM, Manish Gupta mandecent.gu...@gmail.com wrote: Hi, I am newbie in Latex and R. I am working on one report in which i need to read file and display content of file by formatting (adding color boxes and colorful text for each record). For this i need to use latex code in R loop. How can i use Latex code in R loop. Any example will help me a lot. See Sweave FAQ [1]. Liviu [1] http://www.statistik.lmu.de/~leisch/Sweave/FAQ.html#x1-11000A.9 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] proper order of calls when estimating nested models
Dear all How should one proceed when estimating nested models containing missing data. What I would like to do is to first estimate the model with the control variables only, and then estimate the model containing also the variables of interest. For example, summary(reg.a - lm(IMC ~ STYLE + SEXE + AGE, imc)) Call: lm(formula = IMC ~ STYLE + SEXE + AGE, data = imc) Residuals: Min 1Q Median 3Q Max -10.720 -2.428 -0.550 1.712 32.206 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 24.858780.23407 106.202 2e-16 *** STYLE0.095440.12057 0.7920.429 SEXE-1.829980.11490 -15.926 2e-16 *** AGE 0.456650.02839 16.087 2e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 3.746 on 5969 degrees of freedom (576 observations deleted due to missingness) Multiple R-squared: 0.07776,Adjusted R-squared: 0.07729 F-statistic: 167.8 on 3 and 5969 DF, p-value: 2.2e-16 summary(reg.b - update(reg.a, . ~ . + DEMANDEC + LATITUDEC + SUPSUPC)) Call: lm(formula = IMC ~ STYLE + SEXE + AGE + DEMANDEC + LATITUDEC + SUPSUPC, data = imc) Residuals: Min 1Q Median 3Q Max -10.687 -2.424 -0.552 1.677 32.258 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 24.916000.24010 103.773 2e-16 *** STYLE0.101650.12455 0.816 0.4144 SEXE-1.871950.11654 -16.063 2e-16 *** AGE 0.455430.02932 15.530 2e-16 *** DEMANDEC 0.220410.10960 2.011 0.0444 * LATITUDEC -0.273780.11106 -2.465 0.0137 * SUPSUPC -0.142350.08169 -1.743 0.0815 . --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 3.739 on 5785 degrees of freedom (757 observations deleted due to missingness) Multiple R-squared: 0.08293,Adjusted R-squared: 0.08197 F-statistic: 87.18 on 6 and 5785 DF, p-value: 2.2e-16 Note that both have been estimated on different samples. If I try the following I get an error: anova(reg.a, reg.b) Error in anova.lmlist(object, ...) : models were not all fitted to the same size of dataset Should I reverse the order of calls? Should I always first estimate the complete model, and then the model containing only the control vars? Regards Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] Recommendations regarding textbooks
On Thu, Mar 22, 2012 at 1:17 PM, richard willey richard.wil...@gmail.com wrote: I was hoping to get some advice regarding teaching R in an academic environment. thinks regarding “An R Companion to Applied Regression”. CAR features an excellent introduction to R programming. Liviu __ 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] vif function using lm object
On Wed, Dec 21, 2011 at 9:28 AM, arunkumar akpbond...@gmail.com wrote: Hi, can anyone please explain why the vif should have more than 2 terms. *vif.lm(lmobj) : model contains fewer than 2 terms* why it is throwng error if it is one variable. The _VIF_ is a measure of _multicollinearity_, which occurs between two or more predictors in a regression model. In other words, you cannot have collinearity in a single predictor. Also, to compute the VIF you need to regress one regressor on all the remaining regressors. If you have a single regressor, then you cannot estimate a VIF. See the related articles on Wikipedia. Regards Liviu - Thanks in Advance Arun -- View this message in context: http://r.789695.n4.nabble.com/vif-function-using-lm-object-tp4220904p4220904.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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] Multicollinearty in logistic regression models
On Fri, Dec 16, 2011 at 1:47 PM, David Winsemius dwinsem...@comcast.net wrote: Harrell's rms package has a vif function that is intended for use with fits from his logistic regression model function, lrm. This uses the variance Also see vif() in 'car'. Liviu __ 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] nice report generator?
On Wed, Dec 7, 2011 at 7:43 PM, Janko Thyson janko.thyson.rst...@googlemail.com wrote: I like knitr. IMHO Yihui really came up with a killer package there: http://yihui.github.com/knitr/ If we're talking about nice, I'll chip in for LyX. It has support for Sweave, and will soon support knitr. This eliminates (most of) the burden of learning LaTeX. Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to view/edit large matrix/array in R?
On Tue, Dec 6, 2011 at 4:42 AM, Michael comtech@gmail.com wrote: I didn't mean the speed of saving the file is slow... I meant the manual procedures of exporting and then opening Excel, etc. is slow and inconvenient and unproductive... You may want to use RExcel then. Liviu On Mon, Dec 5, 2011 at 9:38 PM, R. Michael Weylandt michael.weyla...@gmail.com michael.weyla...@gmail.com wrote: I think what most everyone is getting at is that the visual identification of numeric outliers is an exceedingly difficult task and one we humans are not well evolved for. Rather they are all suggesting you use visual techniques to spot and fix outliers individually. This practice has a long and reputable history in statistics and has been shown to be far more efficient than simply scanning pages of numbers for a single misplaced decimal. In conjunction, I'd also recommend use of the identify() function, which serves just this purpose. If you have so much data that the csv export is unbearably slow it seems unlikely you can check it all by hand. Another, more general, methodology if you are worried about data corruption is to use robust statistics when applicable. Michael On Dec 5, 2011, at 10:27 PM, Michael comtech@gmail.com wrote: In R-Studio, edit gives non-grid based format which is similar to fix... But exporting to Excel is time-consuming... On Mon, Dec 5, 2011 at 9:17 PM, jim holtman jholt...@gmail.com wrote: 'edit' does allow you to change it. If all else fails, export to Excel, split the screen and then synchronize the two displays. On Mon, Dec 5, 2011 at 9:52 PM, Michael comtech@gmail.com wrote: View doesn't allow editing? And not multi-window so I cannot put variables side-by-side for comparsion? Thanks! On Mon, Dec 5, 2011 at 7:37 PM, jim holtman jholt...@gmail.com wrote: Have you tried ?View ?edit On Mon, Dec 5, 2011 at 8:12 PM, Bert Gunter gunter.ber...@gene.com wrote: ... and do you really think perusing thousands of numbers by eye is any way to edit/check data?! Personal viewpoint: I would say that this is a large area of statistics and data analysis that the discipline fails to address in any systematic way ... perhaps because there is no way to address it systematically? Contrary views and corrections -- especially references! -- would be very welcome. My advice would be: graphics! -- but I can't provide anything more useful without the specifics of the problem. Some packages may provide the interactivity you seek -- check the CRAN GUI task view, R Commander, etc. -- Bert On Mon, Dec 5, 2011 at 5:01 PM, Michael comtech@gmail.com wrote: head, tail and fix commands don't really work well if I have large matrix/array for which I would like to be able to scroll up and dow, left and right ... Could anybody please help me? 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.htmlhttp://www.r-project.org/posting-guide.html 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.htmlhttp://www.r-project.org/posting-guide.html 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. -- 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. [[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.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. -- Do you know how to read?
Re: [R] Help! Big problem when using browser() to do R debugging?
On Sat, Dec 3, 2011 at 2:38 AM, Michael comtech@gmail.com wrote: Hi all, Could you please help me? I am having the following weird problem when debugging R programs using browser(): In my function, I've inserted a browser() in front of Step 1. My function has 3 steps and at the end of each step, it will print out the message Step i is done... However, after I hit ENTER when the program stopped before Step 1 and entered into the debugging mode, it not only executed the next line(i.e. the Step 1), but also all the (many) remaining lines in that function, as shown below: Browse[1] [1] Step 1 is done.. [1] Step 2 is done.. [1] Step 3 is done.. Then it automatically quited the debugging mode and when I tried to check the value of myobj, I've got the following error message: names(myobj) Error: object 'myobj' not found No suitable frames for recover() So my question is: why did one key stroke ENTER lead it to execute all the remaining lines in that function and then returned from the function and quited the debugging mode? As soon as you get into 'debug' mode, type 'n', hit enter, then you can simply hit enter to evaluate the fun step by step. To exit the step-by-step, type 'c' and hit enter: this will evaluate the rest of the function. Regards Liviu Thanks a lot! __ 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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] detecting autocorrelation structure in panel data
On Mon, Nov 28, 2011 at 3:54 AM, Matteo Richiardi matteo.richia...@gmail.com wrote: Hello, I'm a newby in R. I have created a data.frame holding panel data, with Take a look at the 'plm' package and its vignette. Regards Liviu the following columns: id,time,y, say: periods = 100 numcases = 100 df = data.frame( id = rep(1:numcases,periods), time = rep(1:periods, each = numcases) ) df = transform(df,y=c(rnorm(numcases*periods)+id) I want to check whether y is autocorrelated. I came across the acf() function, but I cannot understand how to specify that my time variable is time and that individuals are identified by their id. I have also tried to convert my data.frame in a ts or a xts object, but got really lost there. I'd really apreciate help... Thank you, Matteo __ 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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] First read (was: Re: Looping and paste)
On Thu, Nov 24, 2011 at 9:27 AM, Patrick Burns pbu...@pburns.seanet.com wrote: It's very seldom that I disagree with Bert, but here is one time. I don't think An Introduction to R is a suitable first read for people with little computational experience. I must agree with Patrick here. The 'Intro to R' may be appropriate for someone already versed in statistics and/or programming, but it is hardly useful as a first read for the neophytes. Better (I modestly suggest) would be: http://www.burns-stat.com/pages/Tutor/hints_R_begin.html To chip in, the first two chapters of Fox and Weisberg (2011) make for an excellent introduction to R programming. It's gentle, but also covers many of the difficulties and misunderstandings that one would encounter in R. Regards Liviu which includes some other references. 'Hints' is imperfect and incomplete but it suffers slightly less from the curse of knowledge than a lot of other R documentation. Pat On 24/11/2011 00:15, Bert Gunter wrote: ... and you can of course do the assignment: Bndy- paste (BndY,to,50+seq_len(BndY), mN, sep = ) An Introduction to R tells you about such fundamentals and should be a first read for anyone learning R. --- Bert On Wed, Nov 23, 2011 at 4:10 PM, Bert Gunterbgun...@gene.com wrote: Don't do this! paste() is vectorized. paste (BndY,to,50+seq_len(BndY), mN, sep = ) Cheers, Bert On Wed, Nov 23, 2011 at 3:31 PM, B77Sbps0...@auburn.edu wrote: out- vector(list) Ylab- for(i in 1:length(BndY)) { out[i]- paste(BndY[i], to ,BndY[i],mN) } Ylab- do.call(c, out) markm0705 wrote Dear R helpers I'm trying to make up some labels for plot from this vector BndY-seq(from = 18900,to= 19700, by = 50) using Ylab-for(i in BndY) {c((paste(i, to ,i+50,mN)))} but the vector created is NULL However if i use for(i in BndY) {print(c(paste(i, to ,i+50,mN)))} I can see the for loop is making the labels I'm looking for but not sure on my error in assigning them to a vector Thanks in advance -- View this message in context: http://r.789695.n4.nabble.com/Looping-and-paste-tp4101892p4102066.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 -- Patrick Burns pbu...@pburns.seanet.com twitter: @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of 'Some hints for the R beginner' and 'The R Inferno') __ 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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] understanding all.equal() output: Mean relative difference
Dear all How should one parse all.equal() output? I'm specifically referring to the 'mean relative difference' messages. For example, all.equal(pi, 355/113) [1] Mean relative difference: 8.491368e-08 But I'm not sure how to understand these messages. When they're close to 0 (or 1xe-16), then it's intuitive. But when they're big, all.equal(1, 4) [1] Mean relative difference: 3 all.equal(2, 4) [1] Mean relative difference: 1 all.equal(3, 4) [1] Mean relative difference: 0.333 the messages start making much less sense. I tried Wikipedia [1], but the description is cryptic, as is the help page. Also, Fox and Weisberg (2011) don't explain this particular message. Regards Liviu [1] http://en.wikipedia.org/wiki/Mean_difference#Relative_mean_difference -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] proper work-flow with 'formula' objects and lm()
Dear all I have a work-flow issue with lm(). When I use lm(y1~x1, anscombe) Call: lm(formula = y1 ~ x1, data = anscombe) Coefficients: (Intercept) x1 3.0001 0.5001 I get as expected the formula, y1 ~ x1, in the print()ed results or summary(). However, if I pass through a formula object (form - formula(y1~x1)) y1 ~ x1 lm(form, anscombe) Call: lm(formula = form, data = anscombe) Coefficients: (Intercept) x1 3.0001 0.5001 then I only get the object name in the call, 'form', instead of the formula. When passing a 'formula' object to lm, is it possible to retain in the resulting 'lm' object the actual formula used for the regression: y1 ~ x1? Regards Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] proper work-flow with 'formula' objects and lm()
On Thu, Nov 24, 2011 at 9:14 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: It is retained. terms(fit) will give it to you, if fit is an lm object. Thank you. The following works nicely. (form - formula(y1~x1)) y1 ~ x1 x - lm(form, anscombe) formula(terms(x)) y1 ~ x1 However, I was hoping that there was a way to input the 'form' object so that summary(x) would print the underlying formula used, not the formula object name. I was thinking of something in the style of x - lm(deparse(form), anscombe) summary(x) Can this be done? Regards Liviu __ 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] proper work-flow with 'formula' objects and lm()
On Thu, Nov 24, 2011 at 10:25 PM, Prof Brian Ripley rip...@stats.ox.ac.uk wrote: Yes. That's a job for substitute (the second time today). form - formula(y1~x1) x - eval(substitute(lm(f, anscombe), list(f = form))) summary(x) Call: lm(formula = y1 ~ x1, data = anscombe) That's what I wanted. Thanks! However, I do want to simplify the syntax and define a new function: x.lm - function(formula, data, ...) { eval(substitute(lm(f, data, ...), list(f = formula))) } For the simple case it works just fine (form - formula(y1~x1)) y1 ~ x1 x - x.lm(form, anscombe) But it fails when I try to input more lm() arguments: (x - x.lm(form, anscombe, subset=-5)) Error in eval(expr, envir, enclos) : ..1 used in an incorrect context, no ... to look in Am I doing something obviously wrong? Regards Liviu __ 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] proper work-flow with 'formula' objects and lm()
On Thu, Nov 24, 2011 at 11:55 PM, Prof Brian Ripley rip...@stats.ox.ac.uk wrote: You would get exactly the same problem with ...,, anway. Here's a commonly used approach in R sources: x.lm - function(formula, data, ...) { Call - match.call(expand.dots = TRUE) Call[[1]] - as.name(lm) Call$formula - as.formula(terms(formula)) eval(Call) } From limited testing this seems to do exactly what I wanted! I thank all those who came up with suggestions. Regards Liviu On Thu, 24 Nov 2011, Liviu Andronic wrote: On Thu, Nov 24, 2011 at 10:25 PM, Prof Brian Ripley rip...@stats.ox.ac.uk wrote: Yes. That's a job for substitute (the second time today). form - formula(y1~x1) x - eval(substitute(lm(f, anscombe), list(f = form))) summary(x) Call: lm(formula = y1 ~ x1, data = anscombe) That's what I wanted. Thanks! However, I do want to simplify the syntax and define a new function: x.lm - function(formula, data, ...) { eval(substitute(lm(f, data, ...), list(f = formula))) } For the simple case it works just fine (form - formula(y1~x1)) y1 ~ x1 x - x.lm(form, anscombe) But it fails when I try to input more lm() arguments: (x - x.lm(form, anscombe, subset=-5)) Error in eval(expr, envir, enclos) : ..1 used in an incorrect context, no ... to look in Am I doing something obviously wrong? Regards Liviu -- 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, UK Fax: +44 1865 272595 -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] [OT] 1 vs 2-way anova technical question
On Tue, Nov 22, 2011 at 2:09 PM, Giovanni Azua brave...@gmail.com wrote: Mr. Gunter did not read/understand my problem, and there were no useful tips but only ad hominem attacks. By your side-taking I suspect you are in the same party club if you want to defend him maybe you should start by tying better your dog so to speak. I believe that most of the readers of this thread got put off by your offending and misplaced remarks. To echo other posters, it would be nice to get your e-mail address banned from the list. Regards Liviu __ 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] changelog for MASS?
On Thu, Nov 17, 2011 at 7:33 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote: Hmmm...sorry -- the only thing I can suggest is maybe striking some sort of deal that you change when it gets however many months out of date: if you look here (http://cran.r-project.org/src/contrib/Archive/MASS/), you can see the last time each version of MASS was updated and by seeing what you You can also get this info on crantastic (scroll to 'prev versions'): http://crantastic.org/packages/MASS Regards Liviu have, you can see about how out of date you are. In the context of MASS, I wouldn't worry so much: it's tied to a book, not active research, so I don't think it gets updated too often in big ways. The other thing is to actually compare differences in the source code, though that might be more trouble than it's worth. Michael On Mon, Nov 14, 2011 at 4:30 PM, Xu Wang xuwang...@gmail.com wrote: Thanks Michael, But I can't see the dates on the NEWS so I have no idea what changed from last version or from whichever version we actually have installed. Do you see what I mean? Thanks, Xu -- View this message in context: http://r.789695.n4.nabble.com/changelog-for-MASS-tp4034473p4040941.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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] Running R with browser without installing anything
On Thu, Oct 20, 2011 at 7:29 PM, Bogaso Christofer bogaso.christo...@gmail.com wrote: Dear all, the company I work for has Matlab installed for statistical/mathematical calculations and really not ready to go with R (even installing exe file for R). Therefore I was wondering is it possible to do analysis R using browser like IE, without installing anything? Look into RStudio Server. Liviu Thanks for your suggestion. [[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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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 and Forex
On Wed, Oct 12, 2011 at 3:29 AM, Yves S. Garret yoursurrogate...@gmail.com wrote: Hi all, I recently started learning about Forex and found this O'Reilly book in Barnes Nobles about R. I bought it out of pure curiosity. I like what I see. However, I have a question. Has anyone tried to bring these two ideas together in a financial and trading sense? Are there any libraries or modules in R that can aid in this venture? fortune('equity') I have never heard anyone (knowledgable or otherwise) claim that, in the absence of transition costs, SAS is better than R for equity modeling. If you come across any such claim, I would be happy to refute it. -- David Kane R-SIG-Finance (December 2004) You may want to address this question to r-sig-finance, and check out the Finance Task View [1]. Regards Liviu [1] http://cran.at.r-project.org/web/views/Finance.html --Yves [[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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] Understanding the workflow between sweave, R and Latex
On Fri, Sep 30, 2011 at 2:41 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: As an aside, I don't recommend the workflow you describe: it's very slow and cumbersome. It's much better to tell your text editor how to run both Sweave and Latex in one command. In the upcoming release of R 2.14.0, this Another approach is to use LyX. The latest stable release comes with an Sweave module that provides out-of-the box support for Sweave documents. Once everything is configured, and on a Mac it should be fairly straightforward in this case, then compiling documents is usually a matter of pressing a button or activating a key combination. LyX takes care of a lot of automation for you, including BibTeX et al. Regards Liviu __ 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] extracting p-values in scientific notation
Dear all How does print.htest display the p-value in scientific notation? (x - cor.test(iris[[1]], iris[[3]])) Pearson's product-moment correlation data: iris[[1]] and iris[[3]] t = 21.65, df = 148, p-value 2.2e-16 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: 0.8270 0.9055 sample estimates: cor 0.8718 Above the p-value comes as ' 2.2e-16', while inspecting the object I get a good old '0'. x$p.value [1] 0 I tried to inspect print.htest but couldn't find it. I also played with format, round and the like to no avail. Any pointers? Regards Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] extracting p-values in scientific notation
Thanks all for your pointers. The following does trick: base::format.pval(x$p.value) ##Hmisc also has such a function [1] 2e-16 On Mon, Oct 3, 2011 at 10:25 AM, Rolf Turner rolf.tur...@xtra.co.nz wrote: Isn't it true that 0 2.2e-16? Yes, but it doesn't mean that the p-value actually hits absolute zero. And cor.test, as Ted noticed, returns identical(x$p.value, 0) [1] TRUE Not that this makes a great practical difference in my case, but I would still prefer to print 2e-16 in my Sweave document. Regards Liviu __ 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] Supporting R/Membership
On Sat, Sep 24, 2011 at 5:43 PM, Joshua Wiley jwiley.ps...@gmail.com wrote: I printed the form to mail off, but anecdotally I had planned on this for well over a year and kept putting it off. If this is something that useRs and the R Foundation would be interested in, I would be happy to help work on setting something up and maintaining it. If the R Core accepts this, I would very much prefer to have an on-line system to make donations. Personally I would like to make a donation, but I'm uncomfortable with sending my credit card details by mail. Regards Liviu __ 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] Reading R Code aloud
On Wed, Sep 14, 2011 at 4:50 AM, cwdillon cwdil...@gmail.com wrote: Well, I've bee reading the R Manual, Nathan Yau's book on Flowing Data, and a few others like this to my kids to get them to go to sleep. I started off doing it the *wrong* way, just to keep it boring but slipped into doing it the *correct* way for my own sanity. It puts the kids to sleep in no time and I actually get some meaningful reading in. The familiar narrative style and topics such as hotdog (hdb) eating contests are not as effective as R manuals and getting the kids to sleep; even with the code. This is a pearl! May I nominate this as a fortune? Liviu __ 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] Solve your R problems
On Mon, Sep 12, 2011 at 9:41 AM, Patrick Burns pbu...@pburns.seanet.com wrote: R-help is all about solving R problems. So here ya go: http://www.portfolioprobe.com/2011/09/12/solve-your-r-problems/ Sweet. :) May I suggest a font change: anything but the default CM should do the trick. For one I prefer Palatino Optima (you'll most likely have access to Palladio or Pagella, and Classico), but it tends to be heavy on longer documents. You could use Aldum, if you have access to it, instead of Palatino: it's the book-design version of Palatino. I hear that Minion Pro fonts are very good (again, if you have access), and there are some very free alternatives such as Libertine Biolinum. Although the default CM tend to be very hard to read, I guess they could fit in handily with the theme of your document. Regards Liviu __ 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] Latex + R + sweave
On Mon, Sep 12, 2011 at 9:21 AM, Twaha Mlwilo uddessy2...@hotmail.com wrote: Hello all, Good day, I have problem on how to remove the source code from the pdf output.Here I mean this. code in sweave Rnw files = x-c(1,2,3,4,5,6) x mean(x) sd(x) @ then would like it appear as mean = 3.5 sd=1.3 x=1,2,3,4,5,6 Try this: echo=F= x-c(1,2,3,4,5,6) x mean(x) sd(x) @ See ?RweaveLatex. Also, try mean = \Sexpr{mean(x)} in your document. You could also play with ?paste in the code chunk, or with generating a matrix with appropriate row names, and printing that. Regards Liviu __ 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] problem with plm package
(please reply to the list, too, as it increases your chances of getting a helpful answer) On Sat, Sep 3, 2011 at 2:51 AM, loth lorien lothlorie...@hotmail.com wrote: Hi Liviu, Thank you for your suggestions, but they didn't seem to work. I got R to estimate a fixed effects model for me: formula-plm(RoE~RoA+NIM+Cash.TL+CAR+NPL.Loans, data=ComBank, model=within) But when I try to estimate a random effects model for a panel data set I still get the error message: missing value where TRUE/FALSE needed I am suspecting that something may relate to the data. Do you have persistent variables that change seldom? Maybe that's causing a problem for the 'random' estimator. Is your panel balanced? If not, does it contain very few observations for some ids? To make sure that the functions work as expected on your system, try to replicate some of the examples in the 'plm' vignette. Regards Liviu There must be something simple that I am missing, but at the moment, I can't figure out what it is. Thanks again, Ashraf From: landronim...@gmail.com Date: Thu, 1 Sep 2011 10:37:57 +0200 Subject: Re: [R] problem with plm package To: lothlorie...@hotmail.com CC: r-help@r-project.org On Thu, Sep 1, 2011 at 4:25 AM, Ash lothlorie...@hotmail.com wrote: Hi, I am trying to complete a very simple panel analysis on some bank data. Call: Formula-plm(RoE~RoA+CAR+Inc.Dep+Cash.TL+NPL.Loans, data=Banks1, model=random, index=c(Bank.I.D.,Year)) summary(Formula) I get the following error code: ERROR: missing value where TRUE/FALSE needed Does anyone know what true/false field I am missing? I am not sure what goes wrong, but try first to Banks1.p - pdata.frame(Banks1, index=c(Bank.I.D.,Year) and see if that went fine, and then Banks1.fit - plm(RoE~RoA+CAR+Inc.Dep+Cash.TL+NPL.Loans, data=Banks1.p, model=random) It may help if you posted str(Banks1) Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] problem with plm package
On Thu, Sep 1, 2011 at 4:25 AM, Ash lothlorie...@hotmail.com wrote: Hi, I am trying to complete a very simple panel analysis on some bank data. Call: Formula-plm(RoE~RoA+CAR+Inc.Dep+Cash.TL+NPL.Loans, data=Banks1, model=random, index=c(Bank.I.D.,Year)) summary(Formula) I get the following error code: ERROR: missing value where TRUE/FALSE needed Does anyone know what true/false field I am missing? I am not sure what goes wrong, but try first to Banks1.p - pdata.frame(Banks1, index=c(Bank.I.D.,Year) and see if that went fine, and then Banks1.fit - plm(RoE~RoA+CAR+Inc.Dep+Cash.TL+NPL.Loans, data=Banks1.p, model=random) It may help if you posted str(Banks1) Liviu __ 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] !!!function to do the knn!!!
I would nominate the following fortune: On Thu, Sep 1, 2011 at 12:16 PM, Petr PIKAL petr.pi...@precheza.cz wrote: Try to call 112 if you are in Europe. David Winsemius: Thank your for your entry in the Poorly Capitalized and Inadequately Searched Posting Contest. mark: help, help ,help!!! Petr PIKAL: Try to call 112 if you are in Europe. Liviu __ 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] Treat an Unquoted Character String as a Data Frame
On Thu, Sep 1, 2011 at 5:48 PM, Jean V Adams jvad...@usgs.gov wrote: Try this data - eval(parse(text=paste(study, level, ., population, sep=))) ..or this: data - get(paste(study, level, ., population, sep=)) Liviu Jean - dbateman wrote on 08/31/2011 17:44:44: I have several datasets that come from different studies (fv02 and fv03), they represent different levels (patients and lesions), and they have different patient populations (itt, mitt, mitt3). I wanted to write some code that would pass my three requirements into a function I wrote, produce the output, but not have to require me to also pass a unique plot title or output filename for each function call. The title and file name would be created in the function according to the three input parameters. My datasets are named like this (all six are repeated for fv03 in place of fv02): fv02patients.itt fv02patients.mitt fv02patients.mitt3 fv02lesions.itt fv02lesions.mitt fv02lesions.mitt3 Taking the first dataset as an example, I currently have this code: study=fv02 level=patients population=itt noquote(paste(study,level,.,population,sep=)) This produces the desired fv02patients.itt, but it is just an unquoted character string rather than a data frame. Here is a condensed look at my function: waterfall=function(data,title,file) { barplot(height=data$brpercent,main=paste(Best Change in Tumor Volume\n,title)), savePlot(filename=file,type=pdf) } waterfall(data=fv02patients.itt,title=EC-FV-02 ITT Patients,file=fv02_itt_patients_waterfall) It may be easier to leave it the way I have it, but if this is possible, I would still be interested in knowing. [[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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to split a data frame by two variables
On Thu, Sep 1, 2011 at 7:53 PM, Changbin Du changb...@gmail.com wrote: HI, Dear R community, I want to split a data frame by using two variables: let and g It's not clear what you want to do, but investigate the following: require(plyr) Loading required package: plyr ddply(x, .(let, g), function(y) mean(y$g)) let g V1 1a 1 1 2a 2 2 3b 1 1 4b 2 2 5c 1 1 6c 2 2 7d 1 1 8d 2 2 9e 1 1 10 e 2 2 This splits the df in groups of unique 'let' and 'g', and computes the mean for each such group. Regards Liviu __ 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] Grouping variables in a data frame
On Sat, Aug 27, 2011 at 7:26 AM, Andra Isan andra_i...@yahoo.com wrote: Hi All, I have a data frame as follow: user_id time age location gender . and I learn a logistic regression to learn the weights (glm with family= (link = logit))), my response value is either zero or one. I would like to group the users based on user_id and time and see the y values and predicted y values at the same time. Or plot them some how. Is there any way to somehow group them together so that I can learn more about my data by grouping them? It's very difficult to help you because you haven't followed the posting guide. But I suspect you're looking for the following: require(plyr) Loading required package: plyr data(mtcars) ##considering 'gear' as 'id' and 'carb' as time ddply(mtcars, .(gear, carb), function(x) mean(x$hp)) gear carbV1 1 31 104.0 2 32 162.5 3 33 180.0 4 34 228.0 5 41 72.5 6 42 79.5 7 44 116.5 8 52 102.0 9 54 264.0 1056 175.0 1158 335.0 This will compute the mean of 'hp' for each group of id time. Liviu I would like to get these at the end user_id time y predicted_y Thanks a lot, Andra __ 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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] obtaining p-values for lm.ridge() coefficients (package 'MASS')
Dear Michael Thank you for your pointers. On Tue, Aug 23, 2011 at 4:05 PM, Michael Friendly frien...@yorku.ca wrote: First, you should be using rms::ols, as Design is old. Good to know. I've always wondered why Design and rms, in many cases, were providing similar functions and (upon cursory inspection) identical documentation. Second, penalty in ols() is not the same as the ridge constant in lm.ridge, but rather a penalty on the log likelihood. The documentation for ols refers to ?lrm for the description. I see. At the same time ?rms::ols contains: The penalized maximum likelihood estimate (penalized least squares or ridge estimate) of beta is (X'X + P)^{-1} X'Y., while ?rms::lrm defines P as penalty \times diag(pf) \times penalty.matrix \times diag(pf), where pf is the vector of square roots of penalty factors computed from penalty. This is suspiciously similar to the definition of the classical Ridge Regression beta estimates (X'X + kI)^{-1} X'Y, where k is the lambda constant and I the identity matrix. Hence I was wondering if rms::ols could be forced to use 'P = kI', and thus compute the classical Ridge estimates? I tried to hack rms::ols to ensure that it passed 'kI' to lm.pfit(..., penalty.matrix = ...), but I get strange results so I must be missing something. (See attached.) Third, other ridge estimators (e.g., ElemStatLearn::simple.ridge also give slightly different results for the same data due to differences in the way scaling is handled. And ?ElemStatLearn::prostate points to several other 'ridge'-related functions. However, similar to MASS::lm.ridge, simple.ridge() roughly stops at estimating the betas, hence my question: is the purpose of Ridge Regression to stabilize the coefficients (when the design matrix is collinear) and use the results to infer the relative importance of the coefficients on the response, while keeping the unpenalized model for prediction purposes? Or am I missing something? Thank you Liviu __ 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] obtaining p-values for lm.ridge() coefficients (package 'MASS')
The attachment seems to have been dropped, so I'm pasting the code below. Sorry for that Liviu On Wed, Aug 24, 2011 at 1:44 PM, Liviu Andronic landronim...@gmail.com wrote: Second, penalty in ols() is not the same as the ridge constant in lm.ridge, but rather a penalty on the log likelihood. The documentation for ols refers to ?lrm for the description. I see. At the same time ?rms::ols contains: The penalized maximum likelihood estimate (penalized least squares or ridge estimate) of beta is (X'X + P)^{-1} X'Y., while ?rms::lrm defines P as penalty \times diag(pf) \times penalty.matrix \times diag(pf), where pf is the vector of square roots of penalty factors computed from penalty. This is suspiciously similar to the definition of the classical Ridge Regression beta estimates (X'X + kI)^{-1} X'Y, where k is the lambda constant and I the identity matrix. Hence I was wondering if rms::ols could be forced to use 'P = kI', and thus compute the classical Ridge estimates? I tried to hack rms::ols to ensure that it passed 'kI' to lm.pfit(..., penalty.matrix = ...), but I get strange results so I must be missing something. (See attached.) ols.ridge - function (formula, data, weights, subset, na.action = na.delete, method = qr, model = FALSE, x = FALSE, y = FALSE, se.fit = FALSE, linear.predictors = TRUE, penalty = 0, penalty.matrix, tol = 1e-07, sigma = NULL, var.penalty = c(simple, sandwich), ridge=TRUE, ...) { call - match.call() var.penalty - match.arg(var.penalty) m - match.call(expand = FALSE) mc - match(c(formula, data, subset, weights, na.action), names(m), 0) m - m[c(1, mc)] m$na.action - na.action m$drop.unused.levels - TRUE m[[1]] - as.name(model.frame) if(ridge) lambda - penalty if (length(attr(terms(formula), term.labels))) { dul - .Options$drop.unused.levels if (!length(dul) || dul) { on.exit(options(drop.unused.levels = dul)) options(drop.unused.levels = FALSE) } X - Design(eval.parent(m)) options(drop.unused.levels = dul) atrx - attributes(X) atr - atrx$Design nact - atrx$na.action Terms - atrx$terms assig - DesignAssign(atr, 1, Terms) penpres - FALSE if (!missing(penalty) any(unlist(penalty) != 0)) penpres - TRUE if (!missing(penalty.matrix) any(penalty.matrix != 0)) penpres - TRUE if (penpres missing(var.penalty)) warning(default for var.penalty has changed to \simple\) if (method == model.frame) return(X) scale - as.character(formula[2]) attr(Terms, formula) - formula weights - model.extract(X, weights) if (length(weights) penpres) stop(may not specify penalty with weights) Y - model.extract(X, response) n - length(Y) if (model) m - X X - model.matrix(Terms, X) if (length(atr$colnames)) dimnames(X)[[2]] - c(Intercept, atr$colnames) else dimnames(X)[[2]] - c(Intercept, dimnames(X)[[2]][-1]) if (method == model.matrix) return(X) } else { if (length(weights)) stop(weights not implemented when no covariables are present) assig - NULL yy - attr(terms(formula), variables)[1] Y - eval(yy, sys.parent(2)) nmiss - sum(is.na(Y)) if (nmiss == 0) nmiss - NULL else names(nmiss) - as.character(yy) Y - Y[!is.na(Y)] yest - mean(Y) coef - yest n - length(Y) if (!length(sigma)) sigma - sqrt(sum((Y - yest)^2)/(n - 1)) cov - matrix(sigma * sigma/n, nrow = 1, ncol = 1, dimnames = list(Intercept, Intercept)) fit - list(coefficients = coef, var = cov, non.slopes = 1, fail = FALSE, residuals = Y - yest, df.residual = n - 1, intercept = TRUE) if (linear.predictors) { fit$linear.predictors - rep(yest, n) names(fit$linear.predictors) - names(Y) } if (model) fit$model - m if (x) fit$x - matrix(1, ncol = 1, nrow = n, dimnames = list(NULL, Intercept)) if (y) fit$y - Y fit$fitFunction - c(ols, lm) oldClass(fit) - c(ols, rms, lm) return(fit) } if (!penpres) { fit - if (length(weights)) lm.wfit(X, Y, weights, method = method, ...) else lm.fit(X, Y, method = method, ...) cov.unscaled - chol2inv(fit$qr$qr) r - fit$residuals yhat - Y - r if (length(weights)) { sse - sum(weights * r^2) m - sum(weights * yhat/sum(weights)) ssr - sum(weights * (yhat - m)^2) r2 - ssr/(ssr + sse) if (!length(sigma)) sigma - sqrt(sse/fit$df.residual
Re: [R] debugging functions in R
On Wed, Aug 24, 2011 at 4:20 PM, Eran Eidinger e...@taykey.com wrote: Hi, I am not sure if this is the right list to ask this question (though I did not find a more appropriate one). I've started using R a month ago, and small scripts work fine. However, when I start writing more complex code, it gets messy. 1. Is there any way to debug normally, with breakpoints? fortune('browser') My solution when I run into mysteries like this is to put 'browser()' in the function just before or after the line of interest. The magnitude and direction of my stupidity usually become clear quickly. -- Patrick Burns R-help (February 2006) Use browser() to inspect the environment and execute the code one step at a time. Liviu 2. I am using the Eclipse plugin (StatET), and tried JGR(). Is there an IDE that enables breakpoints? 3. Is there an equivalent to include in other programming languages? So many functions in one file are very messy. I would like to break it to several files. 4. Any way to create a local context of variables inside a function? Otherwise I have to be careful to give different names inside functions, to those in the workspace. I should point that I am a long time Matlab user and am probably expecting some things that don't necessarily exist in R... I know it's a lot, if there is a more appropriate forum to ask these, please point me in that direction. Thanks, Eran. * * [[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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] obtaining p-values for lm.ridge() coefficients (package 'MASS')
Dear all I'm familiarising myself with Ridge Regressions in R and the following is bugging me: How does one get p-values for the coefficients obtained from MASS::lm.ridge() output (for a given lambda)? Consider the example below (adapted from PRA [1]): require(MASS) data(longley) gr - lm.ridge(Employed ~ .,longley,lambda = seq(0,0.1,0.001)) plot(gr) select(gr) modified HKB estimator is 0.004275 modified L-W estimator is 0.0323 smallest value of GCV at 0.003 ##let's choose 0.03 for lambda coef(gr)[gr$lam == 0.03,] GNP.deflator GNP Unemployed Armed.Forces Population Year -1620.429355 0.021060 0.007994-0.013146-0.007752 -0.101880 0.869116 But how does one obtain the customary 'lm' summary information for the model above? I tried supplying the chosen lambda to Design::ols() using its 'penalty' argument, but strangely the results differ. See below. require(Design) Design::ols(Employed ~ GNP.deflator + GNP + Unemployed + Armed.Forces + Population + Year,data=longley,penalty = 0.03,tol=1e-12) Linear Regression Model Design::ols(formula = Employed ~ GNP.deflator + GNP + Unemployed + Armed.Forces + Population + Year, data = longley, penalty = 0.03, tol = 1e-12) n Model L.R. d.f. R2 Sigma 16 78.22 7.05 0.9929 0.3438 Residuals: Min 1Q Median 3Q Max -0.42480 -0.17774 -0.02169 0.16834 0.77203 Coefficients: Value Std. Error t Pr(|t|) Intercept-1580.022688 518.501881 -3.0473 0.016006 GNP.deflator 0.023161 0.068862 0.3363 0.745322 GNP 0.008351 0.015160 0.5509 0.596839 Unemployed -0.013057 0.002651 -4.9255 0.001178 Armed.Forces-0.007691 0.002097 -3.6671 0.006406 Population -0.096757 0.144240 -0.6708 0.521355 Year 0.847932 0.269614 3.1450 0.013812 Adjusted R-Squared: 0.9866 ##the above seems more similar to a lambda of 0.032 than the one required (0.03) coef(gr)[gr$lam %in% c(0.03, 0.032),] ##lm.ridge output GNP.deflator GNP Unemployed Armed.Forces Population Year 0.030 -1620 0.02106 0.007994 -0.01315-0.007752 -0.10188 0.8691 0.032 -1580 0.02316 0.008351 -0.01306-0.007691 -0.09676 0.8479 The difference between the coefficients of MASS::lm.ridge and Design::ols is small, but they're different nonetheless and I'm wondering if I'm doing something wrong. Perhaps Design::ols uses a penalty different from the one specified? Alternatively, is there some other way to perform diagnostics on Ridge Regression models? Thank you Liviu [1] http://cran.r-project.org/doc/contrib/Faraway-PRA.pdf __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to navigate (zoom, pan) in a plot/graph
On Sun, Aug 21, 2011 at 3:04 PM, Eran Eidinger e...@taykey.com wrote: Thank you Uwe, That solves the second question. Still looking for some solution to zooming in and out dynamically. Try package 'playwith'. Liviu __ 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] Hmisc::rcorr on a 'data.frame'?
Dear all ?Hmisc::rcorr states that it takes as main argument a numeric matrix. But is it normal that it fails in such an ugly way on a data frame? (See below.) If the function didn't attempt any conversion to a matrix, I would have expected it to state that in the error message that it didn't accept 'data.frame' objects in its input. Also, I vaguely remember having used in the past rcorr() on data frames. Regards Liviu require(Hmisc) rcorr(mtcars[ , 1:4]) Error in storage.mode(x) - if (.R.) double else single : (list) object cannot be coerced to type 'double' rcorr(as.matrix(mtcars[ , 1:4])) mpg cyl disphp mpg 1.00 -0.85 -0.85 -0.78 cyl -0.85 1.00 0.90 0.83 disp -0.85 0.90 1.00 0.79 hp -0.78 0.83 0.79 1.00 n= 32 P mpg cyl disp hp mpg 0 00 cyl 0 00 disp 0 00 hp0 0 0 -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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 only the top-right half of a correlation matrix?
Dear all Is there an easy way to display only one half (top-right or bottom-left) of a correlation matrix? require(Hmisc) rcorr(as.matrix(mtcars[ , 1:4])) mpg cyl disphp mpg 1.00 -0.85 -0.85 -0.78 cyl -0.85 1.00 0.90 0.83 disp -0.85 0.90 1.00 0.79 hp -0.78 0.83 0.79 1.00 n= 32 P mpg cyl disp hp mpg 0 00 cyl 0 00 disp 0 00 hp0 0 0 Since the two sides are identical, there is little value in having both displayed at the same time. Moreover, it considerably slows down the inspection of the results. Thank you Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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 only the top-right half of a correlation matrix?
On Fri, Aug 19, 2011 at 9:02 PM, Peter Langfelder peter.langfel...@gmail.com wrote: Use as.dist: here's an example. Seems promising, but for one issue: I would like to keep the diagonal and thus specify 'diag=T', but then as.dist() replaces the diagonal values with zero. (See below.) Is there a way to prevent it from doing that? Either keep the original values, or not display anything in the diagonal (as for the upper part)? Regards Liviu (xb - rcorr(as.matrix(mtcars[ , 1:4]))) mpg cyl disphp mpg 1.00 -0.85 -0.85 -0.78 cyl -0.85 1.00 0.90 0.83 disp -0.85 0.90 1.00 0.79 hp -0.78 0.83 0.79 1.00 n= 32 P mpg cyl disp hp mpg 0 00 cyl 0 00 disp 0 00 hp0 0 0 round(as.dist(xb$r, T), 2) mpg cyl disphp mpg 0.00 cyl -0.85 0.00 disp -0.85 0.90 0.00 hp -0.78 0.83 0.79 0.00 __ 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 only the top-right half of a correlation matrix?
On Fri, Aug 19, 2011 at 9:38 PM, Peter Langfelder peter.langfel...@gmail.com wrote: if as.dist doesn't work, use brute force: x = matrix(rnorm(5*100), 100, 5) mat = signif(cor(x), 2); mat[lower.tri(mat)] = data.frame(mat) Yes, brute force works. This isn't quite how I wanted to do this, but the following seems to work for me. Thanks all Liviu require(Hmisc) print.rcorr - function (x, upper=FALSE, ...) { r - format(round(x$r, 2)) if(!is.null(upper)) r[if(!upper) upper.tri(r) else lower.tri(r)] - '' print(data.frame(r)) n - x$n if (all(n == n[1, 1])) cat(\nn=, n[1, 1], \n\n) else { cat(\nn\n) print(n) } cat(\nP\n) P - x$P P - ifelse(P 0.0001, 0, P) p - format(round(P, 4)) p[is.na(P)] - if(!is.null(upper)) p[if(!upper) upper.tri(p) else lower.tri(p)] - '' print(p, quote = FALSE) invisible() } (xb - rcorr(as.matrix(mtcars[ , 1:4]))) mpg cyl disphp mpg 1.00 cyl -0.85 1.00 disp -0.85 0.90 1.00 hp -0.78 0.83 0.79 1.00 n= 32 P mpg cyl disp hp mpg cyl 0 disp 0 0 hp0 0 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] round() a data frame containing 'character' variables?
On Wed, Aug 10, 2011 at 5:52 PM, Jean V Adams jvad...@usgs.gov wrote: As it says in ?format the digits argument specifies ... how many significant digits are to be used ... enough decimal places will be used so that the smallest (in magnitude) number has this many significant digits ... In your example, the last value in column a is 0.06348058 which is written as 0.063 to two significant digits. I did inspect the help page (several times), but the significant digits formulation was a little too cryptic to me. Now I understand better, thanks. There is no way (that I know of) to make the format() function do the same sort of thing as round(). If digits won't meet your needs, you could try something like this data.frame(lapply(x, function(y) if(is.numeric(y)) round(y, 2) else y)) Quite awkward, but this is more or less what I was looking for. Again, thanks. Regards Liviu __ 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] round() a data frame containing 'character' variables?
Hello On Thu, Aug 11, 2011 at 4:34 PM, Martin Maechler maech...@stat.math.ethz.ch wrote: Well, as you say it's View() only, so why don't you just view the result of something like print(data, digits = 2) Unfortunately print(..., digits = 2) suffers of the same deficiencies as format(..., digits = 2): they both display a minimal number of _significant_ digits. What I would need, however, is to specify the number of decimal places as in round(..., digits = 2). (it does correspond to signif(), rather than round(), but I think that that's more sensible anyway). Although I do appreciate the rationale behind ?signif, for several subjective reasons---easiness of inspecting round()-ed data or aesthetics in printing round()-ed data in Sweave (as in I cannot send format()-ed data to my advisor)---I would prefer to ?round my data. Is there any chance that 'base' would feature a round() function that doesn't stumble when processing non-numeric data (simply by ignoring it), or a format() or print() function with a 'round=NULL' argument? Regards Liviu __ 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] round() a data frame containing 'character' variables?
On Thu, Aug 11, 2011 at 4:58 PM, David Winsemius dwinsem...@comcast.net wrote: numVars - sapply(iris, is.numeric) iris[numVars] - lapply(iris[numVars], round, digits = 2) head(iris) Then drop the assignment operation and just print: ( lapply(iris[numVars], round, digits = 2) ) That's a nice catch, thanks. The only problem with this approach is that non-numeric variables are simply discarded, while I would prefer for them to be simply ignored. Or set your digits argument to print: print( head(iris), digits=1) Or did I miss something? As I explained in today's reply to Martin, print(..., digits = 2) and format(..., digits = 2) both display a minimal number of _significant_ digits. However, for various reasons, I need to specify the number of decimal places as in round(..., digits = 2). Both print() and format() don't provide an obvious way to do that. Regards Liviu __ 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] round() a data frame containing 'character' variables?
On Wed, Aug 10, 2011 at 5:52 PM, Jean V Adams jvad...@usgs.gov wrote: data.frame(lapply(x, function(y) if(is.numeric(y)) round(y, 2) else y)) Building on this, I came up with a 'data.frame' method for round(). I'm not sure how orthodox it is, but it seems to do the job as intended: round.data.frame - function(x, digits = 0) { data.frame(lapply(x, function(y) if(is.numeric(y)) round(y, digits) else y)) } Here's an example: set.seed(2) x - data.frame(a=rnorm(10), b=rnorm(10), c=rnorm(10), d=letters[1:10]) print(x, digits=2) ##it displays 2, 3 or 4 digits, instead of the desired 2 a b c d 1 -0.90 0.418 2.0908 a 2 0.18 0.982 -1.1999 b 3 1.59 -0.393 1.5896 c 4 -1.13 -1.040 1.9547 d 5 -0.08 1.782 0.0049 e 6 0.13 -2.311 -2.4517 f 7 0.71 0.879 0.4772 g 8 -0.24 0.036 -0.5966 h 9 1.98 1.013 0.7922 i 10 -0.14 0.432 0.2896 j round(x, 2) a b c d 1 -0.90 0.42 2.09 a 2 0.18 0.98 -1.20 b 3 1.59 -0.39 1.59 c 4 -1.13 -1.04 1.95 d 5 -0.08 1.78 0.00 e 6 0.13 -2.31 -2.45 f 7 0.71 0.88 0.48 g 8 -0.24 0.04 -0.60 h 9 1.98 1.01 0.79 i 10 -0.14 0.43 0.29 j Would such a method get any chance of inclusion in 'base'? Regards Liviu __ 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] convert 'list' to 'vector'?
On Wed, Aug 10, 2011 at 11:39 PM, David Winsemius dwinsem...@comcast.net wrote: is.vector(x) [1] TRUE You probably didn't realize that lists _are_ vectors before this. Nice to know. Hopefully this expected invitation to grilling will not result in severe burns. I note that one of the *apply family would have been successful in returning the desired object in conjunction with c() : rapply(x, c) [1] a b c d e f g h i j k l `rapply` is designed to do a complete traversal of the list structure and its default how argument is unlist. It was linked from the page where you were looking at `simplify2array`. This also does the job nicely. As does c(x, recursive=T) [1] a b c d e f g h i j k l per Peter's suggestion. Thanks all for all the solutions. Regards Liviu __ 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] round() a data frame containing 'character' variables?
Dear all It is difficult to use round(..., digits=2) on a data frame since one has to first take care to remove non-numeric variables such as 'character' or 'factor': head(round(iris, 2)) Error in Math.data.frame(list(Sepal.Length = c(5.1, 4.9, 4.7, 4.6, 5, : non-numeric variable in data frame: Species head(round(iris[1:4], 2)) Sepal.Length Sepal.Width Petal.Length Petal.Width 1 5.1 3.5 1.4 0.2 2 4.9 3.0 1.4 0.2 3 4.7 3.2 1.3 0.2 4 4.6 3.1 1.5 0.2 5 5.0 3.6 1.4 0.2 6 5.4 3.9 1.7 0.4 Is there an elegant way to use round() on a data frame containing 'character' variables without removing them? Thank you Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] round() a data frame containing 'character' variables?
Hello On Wed, Aug 10, 2011 at 11:41 AM, Dimitris Rizopoulos d.rizopou...@erasmusmc.nl wrote: One approach is the following: numVars - sapply(iris, is.numeric) iris[numVars] - lapply(iris[numVars], round, digits = 2) head(iris) That's interesting, but still doesn't do what I need. Since it's a read-only View() operation I would like to avoid at all cost modifying the original data frame. And since my data frames are relatively big, I would like to avoid generating unnecessary copies. Basically I would need round() to ignore objects that it knows it cannot handle. Any other ideas? Thanks Liviu __ 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] round() a data frame containing 'character' variables?
Hello On Wed, Aug 10, 2011 at 2:31 PM, Jean V Adams jvad...@usgs.gov wrote: The function format() might serve your needs. This looks very promising, but yields some strange results. See below: x - data.frame(a=rnorm(10), b=rnorm(10), c=rnorm(10), d=letters[1:10]) x a bc d 1 0.54114449 -0.11195580 1.526279364 a 2 3.27109063 0.50848249 -0.215760332 b 3 -0.27064475 -1.04749725 0.082319811 c 4 -0.06638611 -0.58600572 0.004148253 d 5 -0.06170739 -0.37885203 0.689125494 e 6 0.53211363 -0.09150913 -0.463972307 f 7 -0.43314431 -0.28981614 -0.973410994 g 8 0.52137857 -1.15077343 0.163120205 h 9 -1.39581552 1.27378389 0.136708313 i 10 0.06348058 -0.00369746 -0.570214119 j format(x, digits=2) ##it displays 3 or 4 digits, instead of the required 2 a b c d 1 0.541 -0.1120 1.5263 a 2 3.271 0.5085 -0.2158 b 3 -0.271 -1.0475 0.0823 c 4 -0.066 -0.5860 0.0041 d 5 -0.062 -0.3789 0.6891 e 6 0.532 -0.0915 -0.4640 f 7 -0.433 -0.2898 -0.9734 g 8 0.521 -1.1508 0.1631 h 9 -1.396 1.2738 0.1367 i 10 0.063 -0.0037 -0.5702 j format(x, digits=2, nsmall=1, scientific=7) ##no change when setting related arguments a b c d 1 0.541 -0.1120 1.5263 a 2 3.271 0.5085 -0.2158 b 3 -0.271 -1.0475 0.0823 c 4 -0.066 -0.5860 0.0041 d 5 -0.062 -0.3789 0.6891 e 6 0.532 -0.0915 -0.4640 f 7 -0.433 -0.2898 -0.9734 g 8 0.521 -1.1508 0.1631 h 9 -1.396 1.2738 0.1367 i 10 0.063 -0.0037 -0.5702 j round(x[1:3], digits=2) ##works as expected a b c 1 0.54 -0.11 1.53 2 3.27 0.51 -0.22 3 -0.27 -1.05 0.08 4 -0.07 -0.59 0.00 5 -0.06 -0.38 0.69 6 0.53 -0.09 -0.46 7 -0.43 -0.29 -0.97 8 0.52 -1.15 0.16 9 -1.40 1.27 0.14 10 0.06 0.00 -0.57 Any ideas why format() and round() give so different results? Can format() be set to behave similarly to round? Regards Liviu __ 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] convert 'list' to 'vector'?
Dear all How does one convert a non-symmetric list to a vector? See below: x - list() x[[1]] - letters[1:5] x[[2]] - letters[6:10] x[[3]] - letters[11:12] x [[1]] [1] a b c d e [[2]] [1] f g h i j [[3]] [1] k l paste(x) [1] c(\a\, \b\, \c\, \d\, \e\) c(\f\, \g\, \h\, \i\, \j\) [3] c(\k\, \l\) as.vector(x) [[1]] [1] a b c d e [[2]] [1] f g h i j [[3]] [1] k l simplify2array(x) [[1]] [1] a b c d e [[2]] [1] f g h i j [[3]] [1] k l What I would need to get instead is: letters[1:12] [1] a b c d e f g h i j k l Any ideas? Regards Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] convert 'list' to 'vector'?
On Wed, Aug 10, 2011 at 9:02 PM, R. Michael Weylandt michael.weyla...@gmail.com wrote: unlist() Thanks all! This is perfect, and very R-ish: never where a novice would expect it to be. Cheers Liviu __ 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] convert 'list' to 'vector'?
On Wed, Aug 10, 2011 at 9:32 PM, David Winsemius dwinsem...@comcast.net wrote: Thanks all! This is perfect, and very R-ish: never where a novice would expect it to be. Well, since `unlist` is linked in the See Also on the help page for `list`, I can only hope you meant that in complete jest. More or less. I would have expected that to transform a 'list' into a 'vector' I should look into 'as.vector' (or its See Also), and I would have never guessed to look for 'unlist'. R documentation is sometimes (often?) hard to parse, and when learning R more often than not you're looking in the wrong place. But yes, it was intended as humour (although I did expect to get grilled). As the Posting Guide says: ... sometimes `read the manual' is the appropriate response. I did, but I was on the wrong track. It actually hasn't occurred to me to check ?list, but See Also in both ?as.vector and ?simplify2array does not link to 'unlist'. Since these are the two places where I turned to in the first place, and I have also played extensively with sapply(..., simplify=...) arguments, and there was nothing obvious in their respective See Also, I figured that I did my homework reasonably well. Regards Liviu __ 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 silent R
On Fri, Aug 5, 2011 at 3:54 PM, khadeeja ismail haj...@yahoo.com wrote: other attached packages: [1] Rcmdr_1.6-2 I bet that this is what generates the lack of error messages. Check Rcmdr documentation on how to turn it off. Liviu __ 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] Life Cycle Assessment with R.
On Mon, Jul 25, 2011 at 8:03 PM, Jose Bustos Melo jbustosm...@yahoo.es wrote: Who knows if there's people working in Life Cycle Assesment (carbon emition) with R? or If there's someone interested in doing a package about it, please let me know! Some of the places to check would be: rseek.org http://cran.at.r-project.org/web/packages/ http://cran.at.r-project.org/web/views/ (which includes an 'Environmetrics' View) I would also check Bioconductor. http://en.wikipedia.org/wiki/Bioconductor Regards Liviu __ 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] add label attribute to objects?
Dear all I know that the R way of documenting things is to work on your project in package development mode, and document each object (such as data frames) in a *.Rd files. This should work for gurus. What about a simpler way to document things, geared for mere mortals? I was thinking of a label() or tag() function that could store and retrieve an alphanumeric comment for a given object (for example, either on 'iris' or on 'iris$Species'). Using 'sos' I found some potential candidates. require(sos) xb - findFn('label attribute') found 307 matches; retrieving 16 pages 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 grepFn( 'label', xb) There is Hmisc::label, which seems to address my concern, but I cannot get it to work on data frames. Am I doing something wrong here? require(Hmisc) #works fine on vectors, but loses the label upon conversion age - c(21,65,43) y - 1:3 label(age) - Age in Years str(age) Class 'labelled' atomic [1:3] 21 65 43 ..- attr(*, label)= chr Age in Years #fails on df x - iris label(x) Sepal.Length Sepal.Width Petal.Length Petal.Width Species Warning message: In mapply(FUN = label, x = x, default = default, MoreArgs = list(self = TRUE), : longer argument not a multiple of length of shorter label(x) - 'some random comment' label(x) Sepal.Length Sepal.Width Petal.Length Petal.Width Species Warning message: In mapply(FUN = label, x = x, default = default, MoreArgs = list(self = TRUE), : longer argument not a multiple of length of shorter #however the label attribute exists!! str(x) 'data.frame': 150 obs. of 5 variables: $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ... $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ... $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ... $ Species : Factor w/ 3 levels setosa,versicolor,..: 1 1 1 1 1 1 1 1 1 1 ... - attr(*, label)= chr some random comment I've also found mefa::label(), which actually does what it advertises, but as 'label' in Hmisc it has one significant drawback: Inheritance is not implemented, so by any transformation of the object into another one, the label is lost. #works fine on vectors, but loses the label upon conversion (x - 1:10) [1] 1 2 3 4 5 6 7 8 9 10 (label(x) - x is a vector) [1] x is a vector str(x) atomic [1:10] 1 2 3 4 5 6 7 8 9 10 - attr(*, label)= chr x is a vector str(as.numeric(x)) num [1:10] 1 2 3 4 5 6 7 8 9 10 #works fine on df, but loses the label upon conversion x - iris (label(x) - x is a vector) [1] x is a vector str(x) 'data.frame': 150 obs. of 5 variables: $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ... $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ... $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ... $ Species : Factor w/ 3 levels setosa,versicolor,..: 1 1 1 1 1 1 1 1 1 1 ... - attr(*, label)= chr x is a vector str(as.matrix(x)) chr [1:150, 1:5] 5.1 4.9 4.7 4.6 5.0 5.4 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:5] Sepal.Length Sepal.Width Petal.Length Petal.Width ... Are any of you aware of a label() function that implements inheritance? Also, is there a reason for not having a similar label() implementation in base R? (Folks coming from the SPSS world would expect it.) Regards Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] Strange graphs
On Mon, Jul 18, 2011 at 5:04 PM, UnitRoot akhussa...@gmail.com wrote: Hello, I am facing problems with plotting graphs in R. It was working well since today, but I cannot get some graphs for unknown reasons. Initially it gave me diagonal straight lines. Now it is giving me very strange curves. I have tried to re-install the softwear. It still did not help. Please, help me out. Oh, I am using fGarch package outputs and based on them trying to plot the graphs. I do not know if it is because of the package that I am using. You have provided too little information. To get any significant help: PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Regards Liviu __ 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] Low Pain Unicode Characters in pdf graph?
On Sun, May 15, 2011 at 3:06 PM, ivo welch ivo.we...@gmail.com wrote: Dear R-experts---is there a relatively low-pain way to get unicode characters into a plot to a pdf device? Have you tried Cairo package or cairo_pdf()? Both are making use of Cairo, which uses UTF-8 and automatically embeds fonts. Regards Liviu __ 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] GUI Experience - Box Plots
On Fri, Jun 3, 2011 at 6:46 AM, Vikas Garud information4vi...@gmail.com wrote: Hi, This is to share my experience of using GUI's for using various Quality Management/Assurance tools. A few days back, I had I had written a mail about Box plots and received some very good suggestions, including that for simple scripts. Thanks everybody for the same. Based on the suggestions, I am trying three GUI's: R Commander, JGR-Deducer combination and RKward. For Box Plots, I found the JGR-Deducer combination the best choice. I could not get box plots - Factors and Dodging - in R Commander and RKward, though the reply on RKward mailing list suggests that the newer version of RKward should solve the problem. Thank you everybody for all the help. I'll be asking questions about various tools that I would like to deploy through GUI's for R. I'll also be sharing my experiences. A good place would be r-sig-gui. Regards Liviu Vikas Garud __ 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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] Box Plot under GUI (R Commander/RKward)
On Tue, May 17, 2011 at 2:15 PM, Jannis bt_jan...@yahoo.de wrote: Otherwise I would stick to SPSS/Excel/Sigmaplot or browse for some R GUIs with some basics beeing implemented on a click basis like RStudio, Rkward or TinnR. All R GUI implementations are however limited to basic plotting/analysis routines and I fear you will get stuck pretty soon when relying on the GUI. Also Deducer. Liviu __ 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] Powerful PC to run R
On Fri, May 13, 2011 at 5:25 PM, John C Frain fra...@gmail.com wrote: Given the price of the Thinkpad X201 I would be very upset if it overheated and would contact my supplier for a replacement. Consider getting an aluminium cooling pad, such as those provided by Zalman. It helps keeping my HP from overheating and shutting down. Liviu I also understand that this CPU may slow down if it is overheated. You would probably get a better performance from a desktop workstation or a larger laptop with better ventilation. As already stated a large mumer of cpu's and multithreading are of little advantage when you are running standard R. John On 13 May 2011 11:38, Michael Haenlein haenl...@escpeurope.eu wrote: Dear all, I'm currently running R on my laptop -- a Lenovo Thinkpad X201 (Intel Core i7 CPU, M620, 2.67 Ghz, 8 GB RAM). The problem is that some of my calculations run for several days sometimes even weeks (mainly simulations over a large parameter space). Depending on the external conditions, my laptop sometimes shuts down due to overheating. I'm now thinking about buying a more powerful desktop PC or laptop. Can anybody advise me on the best configuration to run R as fast as possible? I will use this PC exclusively for R so any other factors are of limited importance. Thanks, Michael Michael Haenlein Assocaite Professor of Marketing ESCP Europe Paris, France [[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. -- John C Frain Economics Department Trinity College Dublin Dublin 2 Ireland www.tcd.ie/Economics/staff/frainj/home.html mailto:fra...@tcd.ie mailto:fra...@gmail.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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] What does the - operator mean?
On Thu, Apr 21, 2011 at 9:59 PM, Thomas Lumley tlum...@uw.edu wrote: The Evil and Wrong use is to modify variables in the global environment. I'm a bit at a loss. Why is it so wrong and evil? In other words, how should one modify variables in the global environment? Through the use of return()? Regards Liviu __ 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] CairoPDF, Fonts, and Windows 7
On Sat, Apr 16, 2011 at 6:39 PM, Al Roark hrbuil...@hotmail.com wrote: Hi All: I have some basic questions about Cairo graphics engine. I'm trying to use the Cairo package to produce PDF output, mainly because I perceive it to be easy to use with a wide variety of fonts. You may also want to try cairo_pdf() that, I think, supports Windows since 2.13.0. But right now, I'm stuck trying to figure out what fonts are available to be used with Cairo, specifically the CairoPDF function. I've been able to successfully produce some test PDFs with grid graphics and CairoPDF (and the font Georgia), so my basic setup is working. I've tried to experiment with the CairoFonts() function but get the message: the R Cairo package was not installed with fontconfig. Please consider installing the cairo graphics engine (www.cairographics.org) with freetype and fontconfig support I'm not quite sure how to interpret this. My version of Cairo comes from the GTK+ 2.22 bundle from the GTK+ Project website. It is possible that you need to install fontconfig separately. On Linux it is a separate package, but I know that it is widely used in LaTeX, so it might be possible that you need to have a LaTeX distribution installed, such as miktex. Or install LyX (complete); this should also take care of fontconfig. But these are mere guesses. Regards Liviu I'm running R 2.12.2 on Windows 7. Any feedback or direction toward informative resources is much appreciated. Cheers,Al [[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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] trouble with \SweaveOpts{grdevice=...}
Dear all I've just tried the brand new 'grdevice' option in Sweave but couldn't make it work. When I declare \SweaveOpts{grdevice=pdf} or \SweaveOpts{grdevice=cairo_pdf} trying to plot something simple fig=T, echo=T= plot(1:10,1:10,main='Some title') @ would result in an Sweave error: 18:16:47.299: 1 : term verbatim 18:16:47.308: 2 : echo term verbatim pdf pdf 18:16:47.391: Error in dev(name = chunkprefix, width = options$width, height = options$height, : 18:16:47.392: unused argument(s) (name = chunkprefix) 18:16:47.393: Calls: Sweave - Anonymous - dev 18:16:47.396: Execution halted Systemcall.cpp(238): Systemcall: 'Rscript --verbose --no-save --no-restore /usr/local/share/lyx-svn/scripts/lyxsweave.R /tmp/lyx_tmpdir.J15281/lyx_tmpbuf5/newfile2.Rnw /tmp/lyx_tmpdir.J15281/lyx_tmpbuf5/newfile2.tex ISO-8859-15 /tmp/' finished with exit code 1 Error: Cannot convert file An error occurred while running: Rscript --verbose --no-save --no-restore /usr/local/share/lyx-svn/scripts/lyxsweave.R /tmp/lyx_tmpdir.J15281/lyx_tmpbuf5/newfile2.Rnw /tmp/lyx_tmpdir.J15281/lyx_tmpbuf5/newfile2.tex ISO-8859-15 /tmp/ 18:16:47.978: Error while previewing format: pdf2 If I comment out the statement %\SweaveOpts{grdevice=pdf} the compilation proceeds as expected. Hoping that it gets through, I'm attaching the Sweave file. Am I doing something wrong? Regards Liviu sessionInfo() R version 2.13.0 (2011-04-13) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] Sweave and Slides (Beamer)
Hello I sympathise with you, since Beamer can quickly drive one mad. On Fri, Apr 15, 2011 at 3:11 AM, Brett Presnell presn...@stat.ufl.edu wrote: So, is this useful to anyone besides me? What trick(s) am I missing that would make it easier/better, or that would obviate altogether the need for such manipulations? Not a solution that would work in all cases, have you tried reducing the font size? Default Beamer font size is quite generous and leaves some space for manoeuvring. For example, in my Beamer Sweave presentations I put this in the preamble: \AtBeginDocument{ \DefineVerbatimEnvironment{Sinput}{Verbatim} {xleftmargin=2em,fontsize= \footnotesize} \DefineVerbatimEnvironment{Soutput}{Verbatim}{xleftmargin=2em,fontsize= \footnotesize} \DefineVerbatimEnvironment{Scode}{Verbatim}{xleftmargin=2em,fontsize= \footnotesize} } Regards Liviu __ 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] By function
Hello On Fri, Apr 8, 2011 at 12:38 AM, Raoni Rodrigues caciquesamu...@gmail.com wrote: Hello all! I have a data frame with nine variables and 293 cases. (attached goes the csv file). The CSV didn't get through so it's difficult to replicate your example. Please post the output of: str(cpue) I need to calculate a index using the sum of one variable (N) divided by the length of other variable (Fisherman), but for each day (Date). I tried to use that codes: by (cpue, cpue$Date, function (x) sum (cpue$N)/length(cpue$Fisherman)) [..] In both codes, as result, I received the same value for all Date value. And, oddly, this result is the value of calculation for all data frame, as I used just: sum (cpue$N)/length(cpue$Fishermans) From the code above, this is expected since in the function() statement you use the entire df (cpue) and not the subset (x). Try this: by (cpue, cpue$Date, function (x) sum (x$N)/length(x$Fisherman)) Sorry for the basic question, but I worked on this simple code all day and can't do it work out! And have no idea why... I'm using R 2.11 in Windows XP. It is often a good a idea to post the output of sessionInfo() Regards Liviu Since now, thanks for the attention and all help, Best, Raoni __ 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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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 licence
On Thu, Apr 7, 2011 at 9:45 AM, Stanislav Bek stanislav.pavel@gmail.com wrote: Hi, is it possible to use some statistic computing by R in proprietary software? I don't know if this covers your case, but SAS and SPSS provide interfaces to R. Regards Liviu Our software is written in c#, and we intend to use http://rdotnet.codeplex.com/ to get R work there. Especially we want to use loess function. Thanks, Best regards, Stanislav [[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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] plyr workaround to converting by() to a data frame
Dear all Is there a clean plyr version of the following by() and do.call(rbind, ...) construct: df-data.frame(a=1:10,b=11:20,c=21:30,grp1=c(x,y),grp2=c(x,y),grp3=c(x,y)) dfsum-by(df[c(a,b,c)], df[c(grp1,grp2,grp3)], range) as.data.frame(dfsum) Error in as.data.frame.default(dfsum) : cannot coerce class 'by' into a data.frame do.call(rbind, dfsum) [,1] [,2] [1,]1 29 [2,]2 30 Thank you Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] Sweave Cairo driver?
Dear all I would like to use Sweave with the Cairo() graphics device instead of pdf(), since the former supports Unicode, allows for easier font selection out of a greater range of available fonts, and automatically embeds fonts into the resulting PDF. Following this older discussion [1], has anyone come up with an Sweave driver that uses the Cairo graphics device? Thank you Liviu [1] http://tolstoy.newcastle.edu.au/R/e12/help/10/10/0986.html -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] Sweave Cairo driver?
On Thu, Apr 7, 2011 at 6:39 AM, Prof Brian Ripley rip...@stats.ox.ac.uk wrote: This is simple in 2.13.0 RC, which allows you to add graphics devices for Sweave. Interesting. Which help files should I look into? On Wed, 6 Apr 2011, Liviu Andronic wrote: since the former supports Unicode, allows for easier font selection out of a greater range of available fonts, and automatically embeds fonts into the resulting PDF. As does cairo_pdf(), builtin to R and more reliable in my experience. Thank you, I didn't know that, and it looks nice, indeed. Regards Liviu __ 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] Sweave Cairo driver?
Dear Brian On Thu, Apr 7, 2011 at 6:39 AM, Prof Brian Ripley rip...@stats.ox.ac.uk wrote: allows for easier font selection out of a greater range of available fonts, As does cairo_pdf(), builtin to R and more reliable in my experience. I've looked into the help pages and searched the lists, but could only find out that The default font family is Helvetica. How could I use a different font with cairo_pdf? In Cairo (the R package), there is a ?CairoFontMatch and ?CairoFonts. Are there equivalents for cairo_pdf? Thank you Liviu __ 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 coloring in R console
Hello On Fri, Apr 1, 2011 at 12:32 PM, January Weiner january.wei...@mpiib-berlin.mpg.de wrote: I have found the packages xterm256 and highlight, but I was not able to figure out how to use it to highlight the syntax in console output. I've been in this position before, without finding a solution for syntax highlighting in the default R console. Also, I tried several GUI interfaces, but I was not able to find something that suits me better than the default R console. R cmdr is definitely not for me, as I don't want to fundamentally change the way I am managing my data in R. Rkwrd seems to be nice (from screenshots), but its installation requires all the base KDE libraries, which I don't want to install. Recently RStudio was introduced [1] and, although beta, it received quasi-unanimous acclaim from the community, so you risk finding it useful too. [1] http://alternativeto.net/software/rstudio/about Regards Liviu I tried JGR, the GUI for R, but I have found the following problems with this package: - I was not able to change the background color from a repulsive grey, - apparently, GNU readline is not implemented in that package, that is, there is no functionality similar to ctrl-r (which searches through the history for matching commands), something I use frequently, and - tab expansion is of limited use (e.g. doesn't browse files in the current directory when expanding quoted arguments e.g. in read.table). All in all, I'd be happy to continue using the plain R console, but syntax highlighting would be nice. Any advice would be extremely welcome. Kind regards, January sessionInfo() R version 2.12.2 (2011-02-25) Platform: i486-pc-linux-gnu (32-bit) locale: [1] LC_CTYPE=en_US.utf8 LC_NUMERIC=C LC_TIME=en_US.utf8 LC_COLLATE=en_US.utf8 LC_MONETARY=C [6] LC_MESSAGES=en_US.utf8 LC_PAPER=en_US.utf8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base -- __ 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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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 coloring in R console
On Fri, Apr 1, 2011 at 3:48 PM, January Weiner january.wei...@mpiib-berlin.mpg.de wrote: RStudio might be a fine program, but it does not feature syntax highlighting, which is the only thing I am missing from R Console (it only colors the commands typed). The idea is that you shouldn't use the R console for you main programming needs, but only for quick and dirty checks. For the bulk of programming tasks you are invited to use the integrated editor (File New Script). The editor window does feature syntax highlighting, and a very helpful completion mechanism (via tab). Sending lines for execution to the terminal is as easy as clicking 'run lines' or ctrl+enter. If you're not a fan of keeping scripts for your projects you can easily use temporary files that you don't save. Moreover, the very idea of squeezing all R windows into one window-desktop would be counterproductive in my particular case. Notice that all panes are freely resizable and can be resized to the point of becoming hidden. Future releases will give more control over the panes layout (I think). Regards Liviu Thank you anyways! j. [1] http://alternativeto.net/software/rstudio/about Regards Liviu I tried JGR, the GUI for R, but I have found the following problems with this package: - I was not able to change the background color from a repulsive grey, - apparently, GNU readline is not implemented in that package, that is, there is no functionality similar to ctrl-r (which searches through the history for matching commands), something I use frequently, and - tab expansion is of limited use (e.g. doesn't browse files in the current directory when expanding quoted arguments e.g. in read.table). All in all, I'd be happy to continue using the plain R console, but syntax highlighting would be nice. Any advice would be extremely welcome. Kind regards, January sessionInfo() R version 2.12.2 (2011-02-25) Platform: i486-pc-linux-gnu (32-bit) locale: [1] LC_CTYPE=en_US.utf8 LC_NUMERIC=C LC_TIME=en_US.utf8 LC_COLLATE=en_US.utf8 LC_MONETARY=C [6] LC_MESSAGES=en_US.utf8 LC_PAPER=en_US.utf8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base -- __ 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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail -- Dr. January Weiner 3 -- Max Planck Institute for Infection Biology Charitéplatz 1 D-10117 Berlin, Germany Web : www.mpiib-berlin.mpg.de Tel : +49-30-28460514 __ 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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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 coloring in R console
On Fri, Apr 1, 2011 at 5:05 PM, January Weiner january.wei...@mpiib-berlin.mpg.de wrote: Dear Liviu, thanks for the programming tip! However, I do all my editing in vim, which has had syntax highlighting for quite a while, as well as auto-completion and a number of other goodies. But while I do most of my programing in vim, For info, vim has plug-in for R. I do most of my scientific studies simply using the R interface and keeping a manually edited lab book apart from the scripts. Clearly, one can do as much with Rstudio -- I just don't see any advantages, but I do see a disadvantage in my specific case: all sub-windows are confined to the desktop. In other words, having multiple plots on one monitor and a terminal with R command line is not possible. I see. This would be more of a hack, but you could use playwith as an external graphics device. Otherwise, there seems to be an easy hack: x11() plot(1:10) A question, though. Given that I have projects assorted in various directories, how can I start RStudio opening a project stored in .RData and .Rhistory of a given directory? I.e., how can I make RStudio open the current directory (like R does), and not $HOME? This is a known issue and the RStudio devels plan to address this. Currently I simply open RStudio in $HOME (and make sure that there is no existent .RData there), then open the .RData from my project's directory (by clicking on it in the right-hand Files pane) and then in the same pane I hit More Set as working dir. A bit cumbersome, but seems to work, and a small price to pay for all the available functionality. Regards Liviu Thanks nonetheless, j. On Fri, Apr 1, 2011 at 4:20 PM, Liviu Andronic landronim...@gmail.com wrote: On Fri, Apr 1, 2011 at 3:48 PM, January Weiner january.wei...@mpiib-berlin.mpg.de wrote: RStudio might be a fine program, but it does not feature syntax highlighting, which is the only thing I am missing from R Console (it only colors the commands typed). The idea is that you shouldn't use the R console for you main programming needs, but only for quick and dirty checks. For the bulk of programming tasks you are invited to use the integrated editor (File New Script). The editor window does feature syntax highlighting, and a very helpful completion mechanism (via tab). Sending lines for execution to the terminal is as easy as clicking 'run lines' or ctrl+enter. If you're not a fan of keeping scripts for your projects you can easily use temporary files that you don't save. Moreover, the very idea of squeezing all R windows into one window-desktop would be counterproductive in my particular case. Notice that all panes are freely resizable and can be resized to the point of becoming hidden. Future releases will give more control over the panes layout (I think). Regards Liviu Thank you anyways! j. [1] http://alternativeto.net/software/rstudio/about Regards Liviu I tried JGR, the GUI for R, but I have found the following problems with this package: - I was not able to change the background color from a repulsive grey, - apparently, GNU readline is not implemented in that package, that is, there is no functionality similar to ctrl-r (which searches through the history for matching commands), something I use frequently, and - tab expansion is of limited use (e.g. doesn't browse files in the current directory when expanding quoted arguments e.g. in read.table). All in all, I'd be happy to continue using the plain R console, but syntax highlighting would be nice. Any advice would be extremely welcome. Kind regards, January sessionInfo() R version 2.12.2 (2011-02-25) Platform: i486-pc-linux-gnu (32-bit) locale: [1] LC_CTYPE=en_US.utf8 LC_NUMERIC=C LC_TIME=en_US.utf8 LC_COLLATE=en_US.utf8 LC_MONETARY=C [6] LC_MESSAGES=en_US.utf8 LC_PAPER=en_US.utf8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base -- __ 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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail -- Dr. January Weiner 3 -- Max Planck Institute for Infection Biology Charitéplatz 1 D-10117 Berlin, Germany Web : www.mpiib-berlin.mpg.de Tel : +49-30-28460514 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r
Re: [R] Performance Difference? Windows vs. Linux
On Fri, Mar 18, 2011 at 11:00 PM, Brigid Mooney bkmoo...@gmail.com wrote: I'm not trying to start a Windows vs. Linux debate, but I've been using R on a Windows machine for a while, and was recently wondering if R's performance would be faster on a Linux machine. And similarly, if any incremental increase in processing speed would be worth the time it would take me to migrate my entire system to Linux (including a database that I access via an R package.) It would help to know what is your system. A sessionInfo() would be a start. Liviu I don't know how much it matters what R is doing - but I've got R pulling a large amount data from a database, performing many complex computations on that data, and then writing output data to a database. Thanks so much for the input, Brigid __ 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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] Teaching R: To quote, or not to quote?
On Wed, Mar 9, 2011 at 9:57 AM, Ingmar Visser i.vis...@uva.nl wrote: FWIW, the style for JSS now enforces (via Achimitization) the use of quotes as you show above. An excellent candidate for the fortunes package! We should probably address Achim for that. :) Regards Liviu best, Ingmar [[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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] sorting subsetting a data.frame
On Mon, Mar 7, 2011 at 1:38 AM, David Winsemius dwinsem...@comcast.net wrote: subset(x[order(x$Species1), ], Sepal.Length==6.7 ) Thank you all for the suggestions. Now I can do exactly what I wanted. Regards Liviu __ 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] sorting subsetting a data.frame
Dear all This may be obvious, but I cannot get it working. I'm trying to subset sort a data frame in one go. x - iris x$Species1 - as.character(x$Species) ##subsetting alone works fine with(x, x[Sepal.Length==6.7,]) ##sorting alone works fine with(x, x[order(Sepal.Length, rev(sort(Species1))),]) ##gets subsetted, but not sorted as expected with(x, x[(Sepal.Length==6.7) order(Sepal.Length, rev(sort(Species1))),]) ##gets subsetted, but sorts very strangely xa - with(x, x[Sepal.Length==6.7,]); with(xa, xa[order(Sepal.Length, rev(sort(Species1))),]) xa - with(x, x[Sepal.Length==6.7,]); with(xa, xa[order(rev(sort(Species1))),]) I've checked The R Inferno, Quick-R and several other places with no obvious solution. Any ideas? Regards Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] sorting subsetting a data.frame
On Sun, Mar 6, 2011 at 11:49 PM, Liviu Andronic landronim...@gmail.com wrote: Dear all This may be obvious, but I cannot get it working. I'm trying to subset sort a data frame in one go. x - iris x$Species1 - as.character(x$Species) ##subsetting alone works fine with(x, x[Sepal.Length==6.7,]) ##sorting alone works fine with(x, x[order(Sepal.Length, rev(sort(Species1))),]) ##gets subsetted, but not sorted as expected with(x, x[(Sepal.Length==6.7) order(Sepal.Length, rev(sort(Species1))),]) ##gets subsetted, but sorts very strangely xa - with(x, x[Sepal.Length==6.7,]); with(xa, xa[order(Sepal.Length, rev(sort(Species1))),]) xa - with(x, x[Sepal.Length==6.7,]); with(xa, xa[order(rev(sort(Species1))),]) And of course I found the culprit after sending the e-mail: wrong call order. The following does what I want, although it's a bit messy: xa - with(x, x[Sepal.Length==6.7,]); with(xa, xa[rev(order(sort(Species1))),]) xa - subset(x, Sepal.Length==6.7); with(xa, xa[rev(order((sort(Species1,]) Regards Liviu I've checked The R Inferno, Quick-R and several other places with no obvious solution. Any ideas? Regards Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] sorting subsetting a data.frame
On Sun, Mar 6, 2011 at 11:53 PM, Liviu Andronic landronim...@gmail.com wrote: On Sun, Mar 6, 2011 at 11:49 PM, Liviu Andronic landronim...@gmail.com wrote: Dear all This may be obvious, but I cannot get it working. I'm trying to subset sort a data frame in one go. x - iris x$Species1 - as.character(x$Species) ##subsetting alone works fine with(x, x[Sepal.Length==6.7,]) ##sorting alone works fine with(x, x[order(Sepal.Length, rev(sort(Species1))),]) ##gets subsetted, but not sorted as expected with(x, x[(Sepal.Length==6.7) order(Sepal.Length, rev(sort(Species1))),]) ##gets subsetted, but sorts very strangely xa - with(x, x[Sepal.Length==6.7,]); with(xa, xa[order(Sepal.Length, rev(sort(Species1))),]) xa - with(x, x[Sepal.Length==6.7,]); with(xa, xa[order(rev(sort(Species1))),]) And of course I found the culprit after sending the e-mail: wrong call order. The following does what I want, although it's a bit messy: xa - with(x, x[Sepal.Length==6.7,]); with(xa, xa[rev(order(sort(Species1))),]) xa - subset(x, Sepal.Length==6.7); with(xa, xa[rev(order((sort(Species1,]) But it still doesn't work on my data! Any ideas for a different approach? Liviu Regards Liviu I've checked The R Inferno, Quick-R and several other places with no obvious solution. Any ideas? Regards Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] problems with playwith
On Tue, Mar 1, 2011 at 5:58 PM, R Heberto Ghezzo, Dr heberto.ghe...@mcgill.ca wrote: hello, i tried to run playwith but : library(playwith) Loading required package: lattice Loading required package: cairoDevice Loading required package: gWidgetsRGtk2 Loading required package: gWidgets Error in inDL(x, as.logical(local), as.logical(now), ...) : unable to load shared object 'H:/R/cran/RGtk2/libs/i386/RGtk2.dll': LoadLibrary failure: The specified procedure could not be found. Failed to load RGtk2 dynamic library, attempting to install it. Did you install RGtk2? [1] Liviu [1] https://code.google.com/p/playwith/ Learn more about GTK+ at http://www.gtk.org If the package still does not load, please ensure that GTK+ is installed and that it is on your PATH environment variable IN ANY CASE, RESTART R BEFORE TRYING TO LOAD THE PACKAGE AGAIN Error : .onAttach failed in attachNamespace() for 'gWidgetsRGtk2', details: call: .Call(name, ..., PACKAGE = PACKAGE) error: C symbol name S_gtk_icon_factory_new not in DLL for package RGtk2 Error: package 'gWidgetsRGtk2' could not be loaded Sys.getenv(PATH) PATH H:\\R/GTK/bin;H:\\R/GTK/lib;H:\\R/ImageMagick;C:\\windows\\system32;C:\\windows;C:\\windows\\System32\\Wbem;C:\\windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\Common Files\\Ulead Systems\\MPEG;C:\\Program Files\\QuickTime\\QTSystem\\;H:\\R\\GTK\\GTK2-Runtime\\bin;H:\\PortableUSB/PortableApps/MikeTex/miktex/bin packages(lattice, cairoDevice, gWidgetsRGtk2, gWidgets, RGtk2, playwith) were reinstalled program GTK was reinstalled. using R-2-12-2 on Windows 7 Can anybody suggest a solution? thanks R.Heberto Ghezzo Ph.D. Montreal - Canada __ 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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Is there any Command showing correlation of all variables in a dataset?
On Tue, Mar 1, 2011 at 11:41 AM, JoonGi joo...@hanmail.net wrote: Thanks in advance. I want to derive correlations of variables in a dataset Specifically library(Ecdat) data(Housing) attach(Housing) cor(lotsize, bathrooms) this code results only the correlationship between two variables. But I want to examine all the combinations of variables in this dataset. And I will finally make a table in Latex. How can I test correlations for all combinations of variables? with one simple command? See Rcmdr for an example. Liviu -- View this message in context: http://r.789695.n4.nabble.com/Is-there-any-Command-showing-correlation-of-all-variables-in-a-dataset-tp3329599p3329599.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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] When is *interactive* data visualization useful to use?
On Fri, Feb 18, 2011 at 8:00 PM, Tom Hopper tomhop...@gmail.com wrote: Tal, One interactive capability that I have repeatedly wished for (but never taken the time to develop with the existing R tools) is the ability to interactively zoom in on and out of a data set, I believe that you can do this with playwith. See this [1]. Regards Liviu [1] http://code.google.com/p/playwith/wiki/Screenshots#Time_series_plot_(Lattice) and to interactively create call-outs of sections of the data. Much of the data that I deal with takes the form of time series where both the full data and small section carry meaningful information. Some of the capabilities of Deducer approach interactive graphing, such as adjusting alpha values or smoothers, though the updates don't happen in quite real-time. - Tom On Friday, February 11, 2011, Tal Galili tal.gal...@gmail.com wrote: Hello all, Before getting to my question, I would like to apologize for asking this question here. My question is not directly an R question, however, I still find the topic relevant to R community of users - especially due to only * partial* (current) support for interactive data visualization (see here: http://cran.r-project.org/web/views/Graphics.html were with iplots we are waiting for iplots extreme, and with rggobi, it currently can not run with R 2.12 and windows 7 OS). And now for my question: While preparing for a talk I will give soon, I recently started digging into two major (Free) tools for interactive data visualization: GGobihttp://www.ggobi.org/ and mondrian http://rosuda.org/mondrian/ - both offer a great range of capabilities (even if they're a bit buggy). I wish to ask for your help in articulating (both to myself, and for my future audience) *When is it helpful to use interactive plots? Either for data exploration (for ourselves) and data presentation (for a client)?* For when explaining the data to a client, I can see the value of animation for: - Using identify/linking/brushing for seeing which data point in the graph is what. - Presenting a sensitivity analysis of the data (e.g: if we remove this point, here is what we will get) - Showing the effect of different groups in the data (e.g: let's look at our graphs for males and now for the females) - Showing the effect of time (or age, or in general, offering another dimension to the presentation) For when exploring the data ourselves, I can see the value of identify/linking/brushing when exploring an outlier in a dataset we are working on. But other then these two examples, I am not sure what other practical use these techniques offer. Especially for our own data exploration! It could be argued that the interactive part is good for exploring (For example) a different behavior of different groups/clusters in the data. But when (in practice) I approached such situation, what I tended to do was to run the relevant statistical procedures (and post-hoc tests) - and what I found to be significant I would then plot with colors clearly dividing the data to the relevant groups. From what I've seen, this is a safer approach then wondering around the data (which could easily lead to data dredging (were the scope of the multiple comparison needed for correction is not even clear). I'd be very happy to read your experience/thoughts on this matter. Thanks in advance, Tal Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ 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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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-/Text-editor for Windows?
Hello On Fri, Jan 28, 2011 at 8:03 PM, Jonathan P Daily jda...@usgs.gov wrote: Geany also handles a ton of filetypes, but lacks a direct interface to R in the windows version - I wrote an AutoHotKey script that did this for me in about 5 minutes. Could you please expand on that? I prefer to use Geany when working on Linux, but I always found it annoying the Windows limitation. Thank you Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to get coefficient and scores of Principal component analysis in R?
Hello On Fri, Jan 28, 2011 at 8:16 PM, Zunqiu Chen che...@ohsu.edu wrote: It might be a simple question. But I could not find the answer from function “prcomp” or “princomp”. Does anyone know what are the codes to get coefficient and scores of Principal component analysis in R? Try these: https://stat.ethz.ch/pipermail/r-help/2010-November/261719.html http://www.statmethods.net/advstats/factor.html http://www.unt.edu/rss/class/Jon/R_SC/Module7/M7_PCAandFA.R http://stats.stackexchange.com/questions/612/is-psychprincipal-function-still-pca-when-using-rotation http://zoonek2.free.fr/UNIX/48_R/05.html#1 Liviu __ 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] speed up in R apply
On Wed, Jan 5, 2011 at 10:49 PM, Young Cho young.s...@gmail.com wrote: When introduced to R, I learned how to use *apply whenever I could to avoid for-loops and all. And, getting the habit, I think I somehow got the mis-conception that it is a magic source, always an optimal way of coding in R. See [1] for an article on vectorisation and loops in R. Liviu [1] http://www.r-project.org/doc/Rnews/Rnews_2008-1.pdf Thanks a lot for all of your helpful advice and comment! Young On Wed, Jan 5, 2011 at 3:09 PM, David Winsemius dwinsem...@comcast.netwrote: On Jan 5, 2011, at 2:40 PM, Douglas Bates wrote: On Wed, Jan 5, 2011 at 1:22 PM, David Winsemius dwinsem...@comcast.net wrote: On Jan 5, 2011, at 10:03 AM, Young Cho wrote: Hi, I am doing some simulations and found a bottle neck in my R script. I made an example: a = matrix(rnorm(500),100,5) tt = Sys.time(); sum(a[,1]*a[,2]*a[,3]*a[,4]*a[,5]); Sys.time() - tt [1] -1291.026 Time difference of 0.2354031 secs tt = Sys.time(); sum(apply(a,1,prod)); Sys.time() - tt [1] -1291.026 Time difference of 20.23150 secs Is there a faster way of calculating sum of products (of columns, or of rows)? You should look at crossprod and tcrossprod. Hmm. Not sure that would help, David. You could use a matrix multiplication of a %*% rep(1, ncol(a)) if you wanted the row sums but of course you could also use rowSums to get those. Thanks for pointing that out. I misread the OP's code. And is this an expected behavior? Yes. For loops and *apply strategies are slower than the proper use of vectorized functions. To expand a bit on David's point, the apply function isn't magic. It essentially loops over the rows, in this case. By multiplying columns together you are performing the looping over the rows in compiled code, which is much, much faster. If you want to do this kind of operation effectively in R for a general matrix (i.e. not knowing in advance that it has exactly 5 columns) you could use Reduce a - matrix(rnorm(500),100,5) system.time(pr1 - a[,1]*a[,2]*a[,3]*a[,4]*a[,5]) user system elapsed 0.15 0.09 0.37 system.time(pr2 - apply(a, 1, prod)) user system elapsed 22.090 0.140 22.902 all.equal(pr1, pr2) [1] TRUE system.time(pr3 - Reduce(get(*), as.data.frame(a), rep(1, nrow(a Slightly faster would be: system.time(pr3 - Reduce(*, as.data.frame(a))) And thanks for the nice example. Using a data.frame to feed Reduce materially enhances its value to me. user system elapsed 0.410 0.010 0.575 all.equal(pr3, pr2) [1] TRUE -- David Winsemius, MD West Hartford, CT [[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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] Cost-benefit/value for money analysis
On Wed, Jan 5, 2011 at 12:29 PM, Graham Smith myotis...@gmail.com wrote: maximal choices would break the budget. This sounds like a homework problem and I don't see any student effort yet. Search terms include: decision analysis , cost-benefit analysis, or utility theory. Hopefully, my response to Ben will clarify my question, and why I am asking it. At the moment (and that may change) I'm not specifically interested in how you do it R, just as to whether there is a package aimed at this kind of Cost Benefit analysis. Try this: require(sos) findFn('cost benefit') found 12 matches Regards Liviu __ 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] Sweave for big data analysis
(slightly off-topic) Hello On Sat, Jan 1, 2011 at 12:20 AM, Yihui Xie x...@yihui.name wrote: I still recommend the pgfSweave package (as usual) -- you can cache both data objects (using cacheSweave) and graphics (using pgf). Do these packages re-implement Sweave, or just use it as a dependency? For example, if Sweave gets updated, will the changes be automatically available for pgfSweave users or not? Regards Liviu Regards, Yihui -- Yihui Xie xieyi...@gmail.com Phone: 515-294-2465 Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA On Fri, Dec 31, 2010 at 2:35 PM, Lars Bishop lars...@gmail.com wrote: Hi, Maybe I'm missing the point here...but let's suppose you are working with large data sets and using functions that take a significant amount of time to run in R. I woulnd't like to run these functions every time I call Sweave(myfile.Rnw) within R. What is the common practice to use Sweave in these situations. I would just run the function once, save the results and only load them each time I run Sweave on the .Rnw file. Makes sense? Sorry, the question seems silly, but I'd appreciate your thoughts. Thanks, Lars. [[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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] latex() etc.: How to nicely format a matrix for a LaTeX document?
On Thu, Dec 30, 2010 at 9:48 PM, Marius Hofert m_hof...@web.de wrote: Thanks, John, I did. Here is an update [not all problems are solved; can they be?]: Consider: library(xtable) mat - matrix(c(1,NA,3,100,10012.23423,4), ncol = 3, byrow = TRUE) print(xtable(mat, digits = 1), floating = FALSE, only.contents = TRUE, include.rownames = FALSE, include.colnames = FALSE, hline.after = NULL) With this one obtains a clean output of the rows (maybe someone knows how to suppress the % latex table generated... that is displayed). However, as you can see from the output, the symbols are not vertically aligned (that would be quite helpful in reading the table in a source file). This is even worse if you have row names of different lengths... If you used Sweave, would you still need to read the table code in a source file? Regards Liviu So my questions (2) and (3) are solved, but (1) remains. Is there any way to (maybe) first format the matrix entries to get the right alignment in xtable()? Cheers, Marius On 2010-12-30, at 21:29 , John Kane wrote: Have a look at xtable. --- On Thu, 12/30/10, Marius Hofert m_hof...@web.de wrote: From: Marius Hofert m_hof...@web.de Subject: [R] latex() etc.: How to nicely format a matrix for a LaTeX document? To: Help R r-h...@stat.math.ethz.ch Received: Thursday, December 30, 2010, 11:50 AM Dear (T)eXpeRts, I try to create a LaTeX table from an R matrix for the first time. I am not sure what the best approach is, I just read about latex() from Hmisc (toLatex() didn't work). Consider the following minimal example: library(Hmisc) mat - matrix(c(1,NA,3,100,1,4), ncol = 3, byrow = TRUE) latex(mat, file = , booktabs = TRUE, numeric.dollar = FALSE, table.env = FALSE) I am only interested in the part between \midrule and \bottomrule [I couldn't figure out how to remove the tabular environment]. It looks like this: 13\tabularnewline 10014\tabularnewline My questions/problems are: (1) if there are NA's, you can see that the output is not aligned according to the -symbols. That makes it hard to read in a LaTeX *source* file. How can I get something like: 1 3\tabularnewline 10014\tabularnewline (2) it would even be nicer to read if the output was like this: 1 3 \tabularnewline 100 1 4 \tabularnewline How can I achieve this? (3) is there another package/function to get output like this more easily? I wrote a one-liner which formats the lines separately, but it would be nice to have the columns aligned as given in (2). I believe it is most helpful to have the output in a form which is readable in a *source* file (i.e., .tex), since the headers/footers from tabular [or tabularx etc.] are often easy to put in the document. Cheers, Marius __ 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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] What is the best way to lag a time series?
On Sun, Dec 26, 2010 at 8:49 AM, Christian Schoder schoc...@newschool.edu wrote: Dear R-users, I've been using R for a while and I am very satisfied! Unfortunately, I still have not figured out an efficient and general way to construct and use lags of time series, especially when I need to work with different packages. Let me give an example. I have two time series x and y and I want to estimate a variaty of distributed lags models and run different tests (autocorrelation, etc). It is obvious that I need to be able to lag x and y in a flexible way. So far, my temporary solution was to construct the lags manually (x1,..,xn and y1,..,yn) in a spreadsheet and import it to R, which is not very satisfactory because it does not allow for much flexibility. Is there a straighforward command which allows me to easily construct a lag Perhaps ?diff. Liviu when required and which allows me to, for example, use the lm() command to fit a dynamic model and the bgtest() command to perform the breusch-godfrey test on the same model? Is it adviseable to use time series objects which consist of many time series (like a dataframe) or is it better to have it contain only one time series? I would be grateful for any hints and links. Thx! Christian __ 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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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 indexing in 'for' loop?
On Wed, Dec 22, 2010 at 2:57 AM, Phil Spector spec...@stat.berkeley.edu wrote: To make your loop work, you need to learn about the get function. I'm not going to give you the details because there are better approaches available. First, let's make some data that will give values which can be verified. (All the correlations of the data you created are exactly equal to 1.) And to make the code readable, I'll omit the ts.m prefix. set.seed(14) dmi = matrix(rnorm(20),4,5) soi = matrix(rnorm(20),4,5) pe = matrix(rnorm(20),4,5) allmats = list(dmi,soi,pe) Since cor.test won't automatically do the tests for all columns of a matrix, I'll write a little helper function: gettests = function(x)apply(x,2,function(col)cor.test(pe[,2],col) tests = lapply(allmats,gettests) Now tests is a list of length 2, with a list of the output from cor.test for the five columns of the each matrix with pe[,2] (Notice that in your program you made no provision to store the results anywhere.) Suppose you want the correlations: sapply(tests,function(x)sapply(x,function(test)test$estimate)) [,1] [,2] cor 0.12723615 0.1342751 cor 0.07067819 0.6228158 cor -0.28761533 0.6218661 cor 0.83731828 -0.9602551 cor -0.36050836 0.1170035 The probabilities for the tests can be found similarly: sapply(tests,function(x)sapply(x,function(test)test$p.value)) [,1] [,2] [1,] 0.8727638 0.86572490 [2,] 0.9293218 0.37718416 [3,] 0.7123847 0.37813388 [4,] 0.1626817 0.03974489 [5,] 0.6394916 0.88299648 Hmisc already provides a function for doing this, rcorr(). Try to compute correlations using Rcmdr for an example. Regards Liviu (Take a look at the Values section in the help file for cor.test to get the names of other quantities of interest.) The main advantage to this approach is that if you add more matrices to the allmats list, the other steps automaticall take it into account. Hope this helps. - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Tue, 21 Dec 2010, govin...@msu.edu wrote: Hi, I am having trouble with matrices. I?have 2 matrices as given below, and I am interested in using these matrices inside for loops used to calculate correlations. I am creating a list with the names of the matrices assuming this list could be indexed inside the 'for' loop to retrieve the matrix values. But, as expected the code throws out an error. Can someone suggest a better way to call these matrices inside the loops? ts.m.dmi - matrix(c(1:20), 4, 5) ts.m.soi - matrix(c(21:40), 4, 5) ts.m.pe - matrix(c(21:40), 4, 5) factors - c(ts.m.dmi, ts.m.soi) for (j in 0:1){ y - factors[j+1] for (i in 1:5){ cor.pe.y - cor(ts.m.pe[,2], y[,i]) ct.tst - cor.test(ts.m.pe[,2], y[,i]) } } Thanks for your time. -- Regards, Maha Graduate Student [[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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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 indexing in 'for' loop?
On Wed, Dec 22, 2010 at 6:39 PM, govin...@msu.edu wrote: Thank you both for your suggestions. I have another question - is there a specific way to access the individual elements of a 'list' variable? i.e. dmi = matrix(rnorm(20),4,5) soi = matrix(rnorm(20),4,5) pe = matrix(rnorm(20),4,5) y - list(dmi, soi, pe) y[[1]] gives [,1] [,2] [,3] [,4] [,5] [1,] -0.54463900 1.6732445 -0.3807847 -1.0460530 -0.8142748 [2,] -0.49654004 -0.9634258 0.9074139 -0.1576030 -1.2268558 [3,] -1.61835766 -0.4240122 0.3626670 0.7182964 0.1576446 [4,] -0.06313983 0.6743465 -1.9897107 0.8027337 -1.4372131 But, I am interested in accessing the 1st column of 'dmi' matrix here - not as dmi[,1] but in terms of 'y'. Is it possible with 'list' function or something else? Is this what you need? y[[1]] [,1][,2][,3] [,4] [,5] [1,] 0.2523449 -1.26606999 0.27594223 -0.5158524 -0.599899 [2,] -1.9155409 0.01081565 0.44497873 0.1819517 1.187899 [3,] 0.7624774 0.31296468 -0.02187076 0.9389091 0.865527 [4,] -0.8082626 -1.44330148 1.32975075 0.1788399 1.204917 y[[1]][,1] [1] 0.2523449 -1.9155409 0.7624774 -0.8082626 Liviu __ 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.