Re: [R] R-equivalent Stata command: poisson or quasipoisson?
Thanks Bill! Not asking for help with Stata at all, on the contrary: the article mentioned using Stata to fit the model described earlier, and I wasn't sure how to do the same in R (which is what I've used since college). Thanks again, I'll play around a bit glmRob, see what happens (though it's slightly worrisome that I won't be able to obtain similar results, if only for 'contrast'). Cheers, Wil On Sep 12, 2010, at 12:36 AM, bill.venab...@csiro.au bill.venab...@csiro.au wrote: In R, the glm families poisson and quasipoisson will give you the same estimates. Their standard errors will (usually) be different, though, and family = quasipoisson does not give you an AIC (since it does not maximise a true likelihood; it uses quasi-likelihood estimation). I hope you are not asking this list for help with Stata. We've never heard of it. It looks to me, though, that what you are doing below is fitting a robust poisson glm. If so, it is something different again. There is a package 'robust' which has a glmRob() fitting function in it that may do something similar, but there is so much tweaking allowed with robust fits the chance of getting the same result as with some other system (or even with R if you do it again, mostly) is effectively zero. Tip: use R and forget the others. It makes life so much easier all round. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org ] On Behalf Of Wil M Contreras Arbaje Sent: Sunday, 12 September 2010 11:27 AM To: r-help@r-project.org Subject: [R] R-equivalent Stata command: poisson or quasipoisson? Hello R-help, According to a research article that covers the topic I'm analyzing, in Stata, a Poisson pseudo-maximum-likelihood (PPML) estimation can be obtained with the command poisson depvar_ij ln(indepvar1_ij) ln(indepvar2_ij) ... ln(indepvarN_ij), robust I looked up Stata help for the command, to understand syntax and such: www.stata.com/help.cgi?poisson Which simply says that the command fits a Poisson regression of depvar on indepvars. However, in my google-searching, I noticed that pseudo- maximum-likelihood estimation is sometimes called 'quasi-maximum,' and that R has a quasipoisson family that seems to allow for overdispersion. So, am I missing something, or should I specify quasipoisson when implementing this estimation? Thanks a lot! Cheers, Wil __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] apply over parallel lists and their elements
Hello, I have a list like the following: tree-list(); tree[[1]]$node-list(); tree[[2]]$node-list(); tree[[1]]$node$values - 1:10 tree[[2]]$node$values - 1:10 After building the list I have to generate the mean of all values elements with equal indices. Until now I use something like that: for(i in seq(along=tree[[1]]$node$values)) { print(mean(tree[[1]]$node$values[i], tree[[2]]$node$values[i])); } [1] 1 [1] 2 ... [1] 10 (I don't need a sapply(tree, function(x)mean(x$node$values));) But I want to do a sapply over the values vectors. Sadly this don't work: sapply(tree[1:2]$node$values, function(x)mean(x)); Is there another solution? Kind regards, Sebastian __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] apply over parallel lists and their elements
On Sun, Sep 12, 2010 at 9:40 AM, Sebastian Gibb li...@sebastiangibb.de wrote: But I want to do a sapply over the values vectors. Try multivariate apply. For more on loops and the apply family check [1]. You might also want to check the plyr package and its documentation. Liviu [1] http://promberger.info/files/rnews-vectorvsloops2008.pdf mapply(mean, tree[[1]]$node$values, tree[[2]]$node$values) [1] 1 2 3 4 5 6 7 8 9 10 mapply(mean, tree[[1]]$node$values, tree[[2]]$node$values, SIMPLIFY=F) [[1]] [1] 1 [[2]] [1] 2 [[3]] [1] 3 [[4]] [1] 4 [[5]] [1] 5 [[6]] [1] 6 [[7]] [1] 7 [[8]] [1] 8 [[9]] [1] 9 [[10]] [1] 10 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] scalable delimiters in plotmath
Thanks everyone. I've also had a look at plotmath.c where bgroup is defined for [, {, (, . but not . It seems quite trivial to add it, at first sight, however there is a part that I don't understand in the RenderDelim routine, static BBOX RenderDelim(int which, double dist, int draw, mathContext *mc, pGEcontext gc, pGEDevDesc dd) { // [... snipped ...] case '(': top = 230; ext = 231; bot = 232; mid = 0; break; case ')': top = 246; ext = 247; bot = 248; mid = 0; break; These integer codes make no sense to me, I have no clue which ones I should use for and . As far as I understand these codes might correspond to extended ascii characters whose boundaries and positions we want to borrow. Then again, maybe it's something else entirely. Any hints? Best wishes, baptiste On 12 September 2010 03:27, David Winsemius dwinsem...@comcast.net wrote: On Sep 11, 2010, at 9:00 PM, Peter Ehlers wrote: On 2010-09-11 16:14, Dennis Murphy wrote: Hi Baptiste, You need to use the symbol(\nnn) concept, where nnn denotes the octal symbol number. For it's 074 and for it's 076. This little test seemed to work: plot(1, 1, main = expression(symbol(\074)~'x, y'~symbol(\076))) HTH, Dennis It's a matter of taste, but I would use \341 and \361. However, these are still not scalable, AFAICS. Not exactly scalable angles, but you can fake it: plot(1, 1, main = expression(symbol(\341)~scriptstyle( atop(x,y) )~symbol(\361)), cex.main=3) scriptstyle shrinks the inner atop() material, and since I tested on a Mac it should work for Baptiste. -- David. -Peter Ehlers On Sat, Sep 11, 2010 at 10:01 AM, baptiste auguie baptiste.aug...@googlemail.com wrote: What do people use to show angle brackets in R graphics? Have I missed something obvious? Thanks, baptiste On 9 September 2010 17:57, baptiste auguie baptiste.aug...@googlemail.com wrote: Dear list, I read in ?plotmath that I can use bgroup to draw scalable delimiters such as [ ] and ( ). The same technique fails with however, and I cannot find a workaround, grid.text(expression(bgroup(,atop(x,y),))) Error in bgroup(, atop(x, y),) : invalid group delimiter Regards, baptiste sessionInfo() R version 2.11.1 (2010-05-31) x86_64-apple-darwin9.8.0 David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Setting scales for ggplot2 with facets
Sorry, I was too vague in my initial question. To make it clearer I included the following example: tmp - data.frame(y=runif(10), x=gl(2,5), class=gl(2,5)) p - ggplot(data = tmp) p - p + geom_point(aes(y=y, x=x)) p - p + facet_wrap(~ class, scales = free) p - p + ylim(0, 1) p This code draws two facets each having 5 points. As explained before, I would like to control y-range of both facet plots. For clarity, say that ylim = c(0, 0.5) for the facet 1 and ylim = c(0.5, 3) for the facet 2. How should I do it? As a quick hack I could, eliminate outliers for both facets, i.e. write lines tmp - cbind(subset(tmp, class == 1 y = 0.5), subset(tmp, class == 2 y = 0.5)) before plotting but this would work only for simple geometrics. For geom_boxplot it would skew the distribution. Swen Laur [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Linux Editor
Try SciViews-K, an extension for Komodo Edit to transform it into a R editor and GUI. http://www.sciviews.org/SciViews-K/index.html On 2010-8-2 23:35, alphaace wrote: Hi Everyone, I recently have started using R again on a Linux box after spending several years on a Mac. Last I checked, the best way to use R was through EMACS using something like ESS. I remember that being serviceable but not always the most convenient. Is there anything comparable to the mac version of R with its built in console, editor, etc?? thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] create a '3D line plot'
Esteemed useRs and developeRs, I need to create a '3D line plot' (proper name?) of which an excellent example can be viewed here: http://cococubed.asu.edu/images/87a/images/unknown_pleasures.jpg I have some experience using the rgl package to create 3D PCA plots, but have no idea where to start for an image like this. I'd really appreciate suggestions help on how might achieve this using R, Karl -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam T +31 (0)10 704 3457 |F +31 (0)10 704 4743 |M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] apply over parallel lists and their elements
Hello, thanks for your answer. mapply fits to my needs. But I don't know how many items would tree have. I can't write them all by hand. How can I generate the arguments for mapply? mapply(mean, tree[[1]]$node$values, tree[[2]]$node$values, ... tree[[k]]$node$values); Kind regards, Sebastian __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 comment out entire code parts in Sweave files
Hello Werner, good question. According to this source: http://devdaily.com/blog/post/latex/multi-line-comments-in-latex-begin-123- comment-125-verbatim this can be done with \usepackage{verbatim} and \begin{comment} This is my comment. Note that it can span multiple lines. This is very useful. \end{comment}\begin{comment} On Saturday 11 September 2010 10:42:52 am Werner W. wrote: Hi, I am wondering if there is any convenient way to comment out an entire region of a Sweave file which comprises R and Latex code. Currently I'm doing it for the R and Latex parts separately or transfer the unwanted part into a different file. But both are not great solutions. (I am doing this when updating old files and debugging) Is there a way to do this with an equivalent of \iffalse \fi or is there some stop command after which Sweave just stops processing? Thanks a lot for any suggestions. Werner __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Friedrich Schuster Dompfaffenweg 6 69123 Heidelberg [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] create a '3D line plot'
On 12/09/2010 10:12 AM, Karl Brand wrote: Esteemed useRs and developeRs, I need to create a '3D line plot' (proper name?) of which an excellent example can be viewed here: http://cococubed.asu.edu/images/87a/images/unknown_pleasures.jpg I have some experience using the rgl package to create 3D PCA plots, but have no idea where to start for an image like this. I'd really appreciate suggestions help on how might achieve this using R, I wouldn't use rgl for that: it's really a flat 2D plot, without perspective, shading or anything else that 3D plots have other than foreground objects hiding background ones. You can draw it by using polygon() to hide the background then lines() to draw the lines. Here's an example using regular 2d graphics: n - 60 m - 50 x - seq(-4,4, len=m) # Make up some fake y data y - matrix(NA, n, m) for (i in 1:n) y[i,] - dnorm(x)*runif(m, 0.5,1) par(bg=black) yrange - range(c(y, y+n/20)) plot(x, x, type=n, axes=FALSE, bg=black, ylim=yrange) for (i in n:1) { y1 - c(y[i,] + i/20, 0, 0) x1 - c(x, x[m], x[1]) polygon(x1,y1,col=black) lines(x, y[i,] + i/20, col=white) } The problem with this kind of plot is that it's almost impossible to display a usable vertical scale. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to define new matrix based on an elementary row oper
I appreciate all you help. This is only for instructional purpose: A = matrix(c(0,1,1,-2,-3,1,2,-1,0,2,2,4,1,-3,-2,1,-4,-7,-1,-19), ncol=5, byrow=T) B =matrix(sample(c(0,1,1,-2,-3,1,2,-1,0,2,2,4,1,-3,-2,1,-4,-7,-1,-19),), ncol=5, byrow=T) Which print func( A, B, A+B) can print the resulting matrices A and B and A+B in the following format? [,1] [,2] [,3] [,4] [,5] [,1] [,2] [,3] [,4] [,5] [,1] [,2] [,3] [,4] [,5] [1,]011 -2 -3 [1,] 2 -102 1[1,] 2 0 1 0-2 [2,]12 -102 + [2,] 1 -42 -2-2 = [2,] 2-2 1-2 0 [3,]241 -3 -2 [3,] -31 -71-1 [3,] -1 5-6-2-3 [4,]1 -4 -7 -1 -19 [4,] -304 -19 1 [4,] -2 -4-3 -20 -18 -- View this message in context: http://r.789695.n4.nabble.com/How-to-define-new-matrix-based-on-an-elementary-row-operation-in-a-single-step-tp2341768p2536409.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] create a '3D line plot'
On Sep 12, 2010, at 10:12 AM, Karl Brand wrote: Esteemed useRs and developeRs, I need to create a '3D line plot' (proper name?) of which an excellent example can be viewed here: http://cococubed.asu.edu/images/87a/images/unknown_pleasures.jpg Set up blank plot region with proper ranges for x and ylim that could be say 0:60 with the intent of scaling your 50 individual y ranges to 0-10 Scale your y values to be within 0-10 Fill plot area black: Draw from top down using polygon with white lines at cex=2 and black fill. Then something along these lines: for(ilevel in 0:50){ polygon(x,yscaled+50-ilevel, col=black, border=white, lwd=2)} #--- tested code opar - par(bg=black) set.seed(1) Ldens - vector(mode=list, 50) for(i in 1:50) { Ldens[[i]] - density(rnorm(100), from=-3,to=3) with(Ldens[[i]], polygon(x=c(x[c(1, 1:512, 512)]), y= c(0, 50-i +20*y[1:512], 0), col=black, border=white)) } par(opar) #- Got any data? -- David. I have some experience using the rgl package to create 3D PCA plots, but have no idea where to start for an image like this. I'd really appreciate suggestions help on how might achieve this using R, Karl -- Karl Brand -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sweave: infelicities with lattice graphics
Just a follow-up on this thread, now with R 2.11.1. I was happy back then to use Deepayan's solution for this, under earlier R versions; but it now gives an error and the Sweave-generated .tex file no longer compiles. ortho-xyplot1-code, keep.source=TRUE, eval=FALSE= library(nlme) library(lattice) xyplot(distance ~ age|Sex, data=Orthodont, type='b', groups=Subject, pch=15:25, col=palette(), cex=1.3, main=Orthodont data) @ ortho-xyplot1,fig=TRUE, include=FALSE, echo=FALSE, width=6, height=6= plot(trellis.last.object()) @ Now, I get the following from Sweave: Error: chunk 46 (label=ortho-xyplot1) Error in !lattice.getStatus(current.plot.saved, prefix = prefix) : invalid argument type Did something in lattice change so that plot(trellis.last.object()) no longer works or needs to be specified differently? -Michael On 7/16/2010 1:14 AM, Deepayan Sarkar wrote: On Thu, Jul 15, 2010 at 1:51 PM, Michael Friendlyfrien...@yorku.ca wrote: In a paper I'm writing using Sweave, I make use of lattice graphics, but don't want to explicitly show (or explain) in the article text the print() wrapper I need in code chunks for the graphs to appear. I can solve this by including each chunk twice, with different options, as in ortho-xyplot1-code, keep.source=TRUE, eval=FALSE= library(nlme) library(lattice) xyplot(distance ~ age|Sex, data=Orthodont, type='b', groups=Subject, pch=15:25, col=palette(), cex=1.3, main=Orthodont data) @ ortho-xyplot1,fig=TRUE, include=FALSE, echo=FALSE, width=6, height=6= library(nlme) library(lattice) print(xyplot(distance ~ age|Sex, data=Orthodont, type='b', groups=Subject, pch=15:25, col=palette(), cex=1.3, main=Orthodont data)) @ but then, if I decide to change the plotting code, I have to make changes in two places. Is there some feature of Sweave or lattice I've missed that would simplify this? Re-use of code chunks doesn't seem to apply here. I usually use this variant of Duncan's suggestion: ortho-xyplot1-code, keep.source=TRUE, eval=FALSE= library(nlme) library(lattice) xyplot(distance ~ age|Sex, data=Orthodont, type='b', groups=Subject, pch=15:25, col=palette(), cex=1.3, main=Orthodont data) @ ortho-xyplot1,fig=TRUE, include=FALSE, echo=FALSE, width=6, height=6= plot(trellis.last.object()) @ -Deepayan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele StreetWeb: http://www.datavis.ca Toronto, ONT M3J 1P3 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.
Re: [R] Sweave: infelicities with lattice graphics
On 12/09/2010 11:41 AM, Michael Friendly wrote: Just a follow-up on this thread, now with R 2.11.1. I was happy back then to use Deepayan's solution for this, under earlier R versions; but it now gives an error and the Sweave-generated .tex file no longer compiles. ortho-xyplot1-code, keep.source=TRUE, eval=FALSE= library(nlme) library(lattice) xyplot(distance ~ age|Sex, data=Orthodont, type='b', groups=Subject, pch=15:25, col=palette(), cex=1.3, main=Orthodont data) @ ortho-xyplot1,fig=TRUE, include=FALSE, echo=FALSE, width=6, height=6= plot(trellis.last.object()) @ Now, I get the following from Sweave: Error: chunk 46 (label=ortho-xyplot1) Error in !lattice.getStatus(current.plot.saved, prefix = prefix) : invalid argument type Did something in lattice change so that plot(trellis.last.object()) no longer works or needs to be specified differently? I don't know if something in lattice has changed, but that doesn't look as though it should work: the code to do the plot was never evaluated. I think you would need eval=TRUE in the first chunk, or ortho-xyplot1-code ahead of the plot command in the second. Duncan Murdoch -Michael On 7/16/2010 1:14 AM, Deepayan Sarkar wrote: On Thu, Jul 15, 2010 at 1:51 PM, Michael Friendlyfrien...@yorku.ca wrote: In a paper I'm writing using Sweave, I make use of lattice graphics, but don't want to explicitly show (or explain) in the article text the print() wrapper I need in code chunks for the graphs to appear. I can solve this by including each chunk twice, with different options, as in ortho-xyplot1-code, keep.source=TRUE, eval=FALSE= library(nlme) library(lattice) xyplot(distance ~ age|Sex, data=Orthodont, type='b', groups=Subject, pch=15:25, col=palette(), cex=1.3, main=Orthodont data) @ ortho-xyplot1,fig=TRUE, include=FALSE, echo=FALSE, width=6, height=6= library(nlme) library(lattice) print(xyplot(distance ~ age|Sex, data=Orthodont, type='b', groups=Subject, pch=15:25, col=palette(), cex=1.3, main=Orthodont data)) @ but then, if I decide to change the plotting code, I have to make changes in two places. Is there some feature of Sweave or lattice I've missed that would simplify this? Re-use of code chunks doesn't seem to apply here. I usually use this variant of Duncan's suggestion: ortho-xyplot1-code, keep.source=TRUE, eval=FALSE= library(nlme) library(lattice) xyplot(distance ~ age|Sex, data=Orthodont, type='b', groups=Subject, pch=15:25, col=palette(), cex=1.3, main=Orthodont data) @ ortho-xyplot1,fig=TRUE, include=FALSE, echo=FALSE, width=6, height=6= plot(trellis.last.object()) @ -Deepayan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 you output a vector to a column in excel?
What happens if I want to automate this process for say 500 vectors? -- View this message in context: http://r.789695.n4.nabble.com/how-to-you-output-a-vector-to-a-column-in-excel-tp2530470p2536402.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] reshape matrix entities to columns
Greeting R helpers J I am not familiar with R but I have to use it to analyze data set that I have (30,000 20,000) I want to change the structure of the dataset and I am wondering how that might be possible in R A main data looks like this: some entities are empty AgeNo. AgeNo. AgeNo. Center15 2 8 7 Center210 7 20 9 4 10 But what I want the data to look like is Age1 2 3 4 5 6 7 8 9 10 ⦠20 Center1 2 7 Center2 10 7 9 It should read the entities one by one when j is in age column take its value and consider it as the column number for new matrix then go to next entity (j No. columns) and put that entity under the columns number identified in previous step. In other word it should get the each element in No. columns (one by one) and place them in a new matrix under the column number which are equal to entity of age columns of first matrix i have tired ncol, and cbind and things like that but I guess im on the wrong path because it is not working. I am reading this fine with read.csv and writing back the same way. do you know how I can make this work?? Is it even possible to do something like this? Thank you in advance Natasha [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] reshape matrix entities to columns
On Sep 12, 2010, at 10:45 AM, Natasha Asar wrote: Greeting R helpers J I am not familiar with R but I have to use it to analyze data set that I have (30,000 20,000) I want to change the structure of the dataset and I am wondering how that might be possible in R A main data looks like this: some entities are empty AgeNo. AgeNo. AgeNo. Center1 5 2 8 7 Center2 10 7 20 9 4 10 But what I want the data to look like is Age1 2 3 4 5 6 7 8 9 10 … 20 Center1 2 7 Center2 10 7 9 It should read the entities one by one when j is in age column take its value and consider it as the column number for new matrix then go to next entity (j No. columns) and put that entity under the columns number identified in previous step. In other word it should get the each element in No. columns (one by one) and place them in a new matrix under the column number which are equal to entity of age columns of first matrix i have tired ncol, and cbind and things like that but I guess im on the wrong path because it is not working. I am reading this fine with read.csv and writing back the same way. do you know how I can make this work?? Is it even possible to do something like this? Thank you in advance Natasha [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to you output a vector to a column in excel?
Well that depends which process you are automating, how your vectors are stored, and where you want them going. Do you want 500 Excel spreadsheets with each vector in Column A? Do you want 1 spreadsheet with each vector appended below the previous? Do you want 1 spreadsheet with each vector in the next column (like a table)? Are these vectors all stored in a list or just in the workspace? Do they have names that can be readily recreated or do their names all have to be typed out? Josh On Sun, Sep 12, 2010 at 8:14 AM, lord12 gaut...@yahoo.com wrote: What happens if I want to automate this process for say 500 vectors? -- View this message in context: http://r.789695.n4.nabble.com/how-to-you-output-a-vector-to-a-column-in-excel-tp2530470p2536402.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] create a '3D line plot'
Hi: Another approach is to use lattice: http://lmdvr.r-forge.r-project.org/figures/figures.html Go to Chapter 14 and click on Figure 14.3; the code is on the RHS of the figure. HTH, Dennis On Sun, Sep 12, 2010 at 7:12 AM, Karl Brand k.br...@erasmusmc.nl wrote: Esteemed useRs and developeRs, I need to create a '3D line plot' (proper name?) of which an excellent example can be viewed here: http://cococubed.asu.edu/images/87a/images/unknown_pleasures.jpg I have some experience using the rgl package to create 3D PCA plots, but have no idea where to start for an image like this. I'd really appreciate suggestions help on how might achieve this using R, Karl -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam T +31 (0)10 704 3457 |F +31 (0)10 704 4743 |M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to print matrices in standard format was ... Re: How to define new matrix based on an elementary row oper
On Sep 12, 2010, at 11:27 AM, Cuckovic Paik wrote: I appreciate all you help. This is only for instructional purpose: A = matrix(c(0,1,1,-2,-3,1,2,-1,0,2,2,4,1,-3,-2,1,-4,-7,-1,-19), ncol=5, byrow=T) B =matrix(sample(c(0,1,1,-2,-3,1,2,-1,0,2,2,4,1,-3,-2,1,-4,-7,-1,-19),), ncol=5, byrow=T) Which print func( A, B, A+B) can print the resulting matrices A and B and A+B in the following format? [,1] [,2] [,3] [,4] [,5] [,1] [,2] [,3] [,4] [,5] [,1] [,2] [,3] [,4] [,5] [1,]011 -2 -3 [1,] 2 -102 1[1,] 2 0 1 0-2 [2,]12 -102 + [2,] 1 -42 -2-2 = [2,] 2-2 1-2 0 [3,]241 -3 -2 [3,] -31 -71 -1 [3,] -1 5-6-2-3 [4,]1 -4 -7 -1 -19 [4,] -304 -19 1 [4,] -2 -4-3 -20 -18 for( i in 1:nrow(A) ) { cat(sprintf(%4.0f, A[i, ]), paste( ,if( i==3 ){+}else{ }, , sep=),sprintf(%4.0f,B[i, ]), paste( ,if( i==3 ){=}else{ }, , sep=), sprintf(%4.0f, (A +B)[i, ]), \n )} -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] reshape matrix entities to columns
Hi: Here's a made up example using the reshape function: Input data: df - structure(list(center = 1:3, age1 = c(6L, 7L, 5L), n1 = c(10L, 12L, 6L), age2 = c(8L, 8L, 8L), n2 = c(13L, 14L, NA), age3 = c(10L, 10L, 9L), n3 = c(9L, NA, 10L), age4 = c(12L, 11L, 11L), n4 = c(7L, 16L, 12L), age5 = c(14L, 14L, 13L), n5 = c(10L, 13L, 9L)), .Names = c(center, age1, n1, age2, n2, age3, n3, age4, n4, age5, n5), class = data.frame, row.names = c(NA, -3L)) df center age1 n1 age2 n2 age3 n3 age4 n4 age5 n5 1 16 108 13 10 9 12 7 14 10 2 27 128 14 10 NA 11 16 14 13 3 35 68 NA9 10 11 12 13 9 # To reshape more than one variable at a time, you need # to put the sets of variables into a list, as follows: df2 - reshape(df, idvar = 'center', varying = list(c(paste('age', 1:5, sep = '')), c(paste('n', 1:5, sep = ''))), v.names = c('age', 'n'), times = 1:5, direction = 'long') df2 center time age n 1.1 11 6 10 2.1 21 7 12 3.1 31 5 6 1.2 12 8 13 2.2 22 8 14 3.2 32 8 NA 1.3 13 10 9 2.3 23 10 NA 3.3 33 9 10 1.4 14 12 7 2.4 24 11 16 3.4 34 11 12 1.5 15 14 10 2.5 25 14 13 3.5 35 13 9 HTH, Dennis On Sun, Sep 12, 2010 at 7:45 AM, Natasha Asar natasha.asa...@yahoo.comwrote: Greeting R helpers J I am not familiar with R but I have to use it to analyze data set that I have (30,000 20,000) I want to change the structure of the dataset and I am wondering how that might be possible in R A main data looks like this: some entities are empty AgeNo. AgeNo. AgeNo. Center15 2 8 7 Center210 7 20 9 4 10 But what I want the data to look like is Age1 2 3 4 5 6 7 8 9 10 20 Center1 2 7 Center2 10 7 9 It should read the entities one by one when j is in age column take its value and consider it as the column number for new matrix then go to next entity (j No. columns) and put that entity under the columns number identified in previous step. In other word it should get the each element in No. columns (one by one) and place them in a new matrix under the column number which are equal to entity of age columns of first matrix i have tired ncol, and cbind and things like that but I guess im on the wrong path because it is not working. I am reading this fine with read.csv and writing back the same way. do you know how I can make this work?? Is it even possible to do something like this? Thank you in advance Natasha [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R-equivalent Stata command: poisson or quasipoisson?
Wil M Contreras Arbaje wil.contreras at gmail.com writes: Thanks Bill! Not asking for help with Stata at all, on the contrary: the article mentioned using Stata to fit the model described earlier, and I wasn't sure how to do the same in R (which is what I've used since college). Thanks again, I'll play around a bit glmRob, see what happens (though it's slightly worrisome that I won't be able to obtain similar results, if only for 'contrast'). Cheers, Wil I find it very hard to tell from Stata's help page, but my best guess would be that the previously mentioned Stata command is more or less equivalent to R's quasipoisson -- the 'robust' specification seems to apply only to the standard error calculation, not to the fitting process. What's unclear about 'robust' is that in other (least-squares fitting) contexts in Stata, it means 'Huber-White sandwich estimators', i.e. estimators that are robust to heteroscedasticity. I suppose this is more general (but also more data-hungry) than the simple expedient of scaling the standard errors by a single estimated overdispersion parameter. The best thing, of course, would be to try a test case in both systems. Or it seems that http://www.stata.com/bookstore/lrm.html (chapter 9) would be helpful. (I checked the stata list archives for 'quasipoisson' and found only a post from the author ...) Somewhat heretically, I prefer polycultures to monocultures; I like R for many reasons, but I'm glad that there are other systems out there with independent implementations and different sets of advantages and drawbacks. On Sep 12, 2010, at 12:36 AM, Bill.Venables at csiro.au Bill.Venables at csiro.au wrote: In R, the glm families poisson and quasipoisson will give you the same estimates. Their standard errors will (usually) be different, though, and family = quasipoisson does not give you an AIC (since it does not maximise a true likelihood; it uses quasi-likelihood estimation). I hope you are not asking this list for help with Stata. We've never heard of it. It looks to me, though, that what you are doing below is fitting a robust poisson glm. If so, it is something different again. There is a package 'robust' which has a glmRob() fitting function in it that may do something similar, but there is so much tweaking allowed with robust fits the chance of getting the same result as with some other system (or even with R if you do it again, mostly) is effectively zero. Tip: use R and forget the others. It makes life so much easier all round. -Original Message- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org ] On Behalf Of Wil M Contreras Arbaje Sent: Sunday, 12 September 2010 11:27 AM To: r-help at r-project.org Subject: [R] R-equivalent Stata command: poisson or quasipoisson? Hello R-help, According to a research article that covers the topic I'm analyzing, in Stata, a Poisson pseudo-maximum-likelihood (PPML) estimation can be obtained with the command poisson depvar_ij ln(indepvar1_ij) ln(indepvar2_ij) ... ln(indepvarN_ij), robust I looked up Stata help for the command, to understand syntax and such: www.stata.com/help.cgi?poisson Which simply says that the command fits a Poisson regression of depvar on indepvars. However, in my google-searching, I noticed that pseudo- maximum-likelihood estimation is sometimes called 'quasi-maximum,' and that R has a quasipoisson family that seems to allow for overdispersion. So, am I missing something, or should I specify quasipoisson when implementing this estimation? Thanks a lot! Cheers, Wil __ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sweave: infelicities with lattice graphics
On Sun, Sep 12, 2010 at 8:47 AM, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 12/09/2010 11:41 AM, Michael Friendly wrote: Just a follow-up on this thread, now with R 2.11.1. I was happy back then to use Deepayan's solution for this, under earlier R versions; but it now gives an error and the Sweave-generated .tex file no longer compiles. ortho-xyplot1-code, keep.source=TRUE, eval=FALSE= library(nlme) library(lattice) xyplot(distance ~ age|Sex, data=Orthodont, type='b', groups=Subject, pch=15:25, col=palette(), cex=1.3, main=Orthodont data) @ ortho-xyplot1,fig=TRUE, include=FALSE, echo=FALSE, width=6, height=6= plot(trellis.last.object()) @ Now, I get the following from Sweave: Error: chunk 46 (label=ortho-xyplot1) Error in !lattice.getStatus(current.plot.saved, prefix = prefix) : invalid argument type Did something in lattice change so that plot(trellis.last.object()) no longer works or needs to be specified differently? I don't know if something in lattice has changed, but that doesn't look as though it should work: the code to do the plot was never evaluated. I think you would need eval=TRUE in the first chunk, or ortho-xyplot1-code ahead of the plot command in the second. Yes. I notice that it was me who introduced the eval=FALSE (I'm not sure why). Hopefully that should fix it. However, there _has_ been a recent lattice update, where the internals have undergone some change, so there is a chance that is to blame. I won't be able to take a look before day after tomorrow. -Deepayan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] non-integer key for data.table
Hi all, Say if I have a data table which consists of 4 column: itemID, location and price, which location is a text field and itemID and location together forms the primary keys. when I tried to run setkey (DT, itemID, location), I got the following message: Error in setkey (DT, itemID, location) : All keyed columns must be storage mode integer Is there any way I could define a non-numerical field (in this case location) to be the key? Also, if I do not use the location as a key, will I still able to merge 2 data tables based on itemID and location using the merge method in data.table? Thanks a lot! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] mapping array
Worked great, thanks! On Sep 11, 2010, at 8:26 PM, bill.venab...@csiro.au bill.venab...@csiro.au wrote: Is this the kind of thing you are talking about? ### 8 cut here 8 ### A - rep(NA, 100) B - sort(runif(25)) C - sort(sample(1:100, 25)) A[C] - B B C A ### 8 cut here 8 ### (The sorting is not necessary. It's only there to make checking what happened easier.) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Gregory Ryslik Sent: Sunday, 12 September 2010 8:54 AM To: r-help@r-project.org Subject: [R] mapping array Hi, Suppose I have array A with 100 elements all filled in with N/A. Array B has 25 elements with actual values. Lastly, I have array C that provides a map of where to put the elements from array A into array B. Thus C would say put element 1 from B into element 3 from array A. I realize I can do this with a for loop. However, because I'm doing a random forest with this, I'd like to avoid a for loop because it would take significantly more time. Thanks, Greg __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] using read.table, removing extra quotation mark from a text field? (e.g. cat )
I am using read.table to import a text file within R. There are several errors in my text file. An extra quotation mark has inadvertently been included within a few text fields. e.g. for a pipe (|) delimited text file, I have something similar to this: 1|7|30| dog 2|6|25| cat 3|4|20| 4|5| 56| mouse 5|3|56| horse 6|56| In the above example| there are extra quotation marks within the fields for cat and horse. (row 2 and row 5) e.g. cat , horse One solution is to simply edit the text file and remove the extra quotation mark. Is there a good solution I can implement form within R? I am OK with just importing the extra quotation marks and having nit show up as part of the text field within R. e.g, cat horse Thanks. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R-equivalent Stata command: poisson or quasipoisson?
Thank you Ben, From the article, the purpose of the author's methodology is to better handle heteroskedasticity (due, in part, to Jensen's inequality). Either way, I'll try both, and see how they compare, as I'd like the R estimation to match the Stata one. Thanks again for your insight, Cheers, Wil On Sep 12, 2010, at 12:58 PM, Ben Bolker wrote: Wil M Contreras Arbaje wil.contreras at gmail.com writes: Thanks Bill! Not asking for help with Stata at all, on the contrary: the article mentioned using Stata to fit the model described earlier, and I wasn't sure how to do the same in R (which is what I've used since college). Thanks again, I'll play around a bit glmRob, see what happens (though it's slightly worrisome that I won't be able to obtain similar results, if only for 'contrast'). Cheers, Wil I find it very hard to tell from Stata's help page, but my best guess would be that the previously mentioned Stata command is more or less equivalent to R's quasipoisson -- the 'robust' specification seems to apply only to the standard error calculation, not to the fitting process. What's unclear about 'robust' is that in other (least-squares fitting) contexts in Stata, it means 'Huber-White sandwich estimators', i.e. estimators that are robust to heteroscedasticity. I suppose this is more general (but also more data-hungry) than the simple expedient of scaling the standard errors by a single estimated overdispersion parameter. The best thing, of course, would be to try a test case in both systems. Or it seems that http://www.stata.com/bookstore/lrm.html (chapter 9) would be helpful. (I checked the stata list archives for 'quasipoisson' and found only a post from the author ...) Somewhat heretically, I prefer polycultures to monocultures; I like R for many reasons, but I'm glad that there are other systems out there with independent implementations and different sets of advantages and drawbacks. On Sep 12, 2010, at 12:36 AM, Bill.Venables at csiro.au Bill.Venables at csiro.au wrote: In R, the glm families poisson and quasipoisson will give you the same estimates. Their standard errors will (usually) be different, though, and family = quasipoisson does not give you an AIC (since it does not maximise a true likelihood; it uses quasi-likelihood estimation). I hope you are not asking this list for help with Stata. We've never heard of it. It looks to me, though, that what you are doing below is fitting a robust poisson glm. If so, it is something different again. There is a package 'robust' which has a glmRob() fitting function in it that may do something similar, but there is so much tweaking allowed with robust fits the chance of getting the same result as with some other system (or even with R if you do it again, mostly) is effectively zero. Tip: use R and forget the others. It makes life so much easier all round. -Original Message- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org ] On Behalf Of Wil M Contreras Arbaje Sent: Sunday, 12 September 2010 11:27 AM To: r-help at r-project.org Subject: [R] R-equivalent Stata command: poisson or quasipoisson? Hello R-help, According to a research article that covers the topic I'm analyzing, in Stata, a Poisson pseudo-maximum-likelihood (PPML) estimation can be obtained with the command poisson depvar_ij ln(indepvar1_ij) ln(indepvar2_ij) ... ln(indepvarN_ij), robust I looked up Stata help for the command, to understand syntax and such: www.stata.com/help.cgi?poisson Which simply says that the command fits a Poisson regression of depvar on indepvars. However, in my google-searching, I noticed that pseudo- maximum-likelihood estimation is sometimes called 'quasi-maximum,' and that R has a quasipoisson family that seems to allow for overdispersion. So, am I missing something, or should I specify quasipoisson when implementing this estimation? Thanks a lot! Cheers, Wil __ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] reshape matrix entities to columns
I changed it so i hope it will look better now the matrix is like this: AgeNo. Age No. AgeNo. Center1 52 8 7 Center210 720 9 4 10 column name = sequence of age-no. But what I want the data to look like is this Age 1 2 3 4 5 6 7 8 9 10 ⦠20 Center1 27 Center2 10 7 9 column name= age of ppl entries = number of ppl with that age in on center thanks again Natasha [[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] replacing matrix column entities as columns name
I am sending this again as they told me that the data was unreadable, so really hope that this will work...so sorry all note: matrix contains a lot of empty entities Greeting R helpers I am not familiar with R but I have to use it to analyze data set that I have (30,000 20,000) I want to change the structure of the dataset and I am wondering how that might be possible in R Age No. Age No. AgeNo. Center15 2 8 7 Center210 7 20 9410 column name = sequence of age-no. But what I want the data to look like is this Age 12345678 910 .. 20 Center12 7 Center2 10 7 .. 9 the rest of the matrix is empty == center1(2,7) and center2(4,10,20) are full column name= age of ppl entries = number of ppl with that age in on center It should read the entities one by one when j is in age column take its value and consider it as the column number for new matrix then go to next entity (j No. columns) and put that entity under the columns number identified in previous step. In other word it should get the each element in No. columns (one by one) and place them in a new matrix under the column number which are equal to entity of age columns of first matrix i have tired ncol, and cbind and things like that but I guess im on the wrong path because it is not working. I am reading this fine with read.csv and writing back the same way. do you know how I can make this work?? Is it even possible to do something like this? Thank you in advance Natasha [[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] Efficient ways of merging data frames
Hi all, I am just wondering if there is a more efficient way of merging two large datasets based on the values of multiple columns, some of which are not numerical. The default merge function in dataframe is very inefficient and the merge function in data.table seems to be faster, but it does not seem to allow keys that are not numerical in nature. Any other suggestion? Thanks a lot! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sweave: infelicities with lattice graphics
Thanks Deepayan and Duncan. The eval=FALSE was the problem, rather than anything with lattice. Not sure why that worked earlier, but I no longer care. -Michael Deepayan Sarkar wrote: On Sun, Sep 12, 2010 at 8:47 AM, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 12/09/2010 11:41 AM, Michael Friendly wrote: Just a follow-up on this thread, now with R 2.11.1. I was happy back then to use Deepayan's solution for this, under earlier R versions; but it now gives an error and the Sweave-generated .tex file no longer compiles. ortho-xyplot1-code, keep.source=TRUE, eval=FALSE= library(nlme) library(lattice) xyplot(distance ~ age|Sex, data=Orthodont, type='b', groups=Subject, pch=15:25, col=palette(), cex=1.3, main=Orthodont data) @ ortho-xyplot1,fig=TRUE, include=FALSE, echo=FALSE, width=6, height=6= plot(trellis.last.object()) @ Now, I get the following from Sweave: Error: chunk 46 (label=ortho-xyplot1) Error in !lattice.getStatus(current.plot.saved, prefix = prefix) : invalid argument type Did something in lattice change so that plot(trellis.last.object()) no longer works or needs to be specified differently? I don't know if something in lattice has changed, but that doesn't look as though it should work: the code to do the plot was never evaluated. I think you would need eval=TRUE in the first chunk, or ortho-xyplot1-code ahead of the plot command in the second. Yes. I notice that it was me who introduced the eval=FALSE (I'm not sure why). Hopefully that should fix it. However, there _has_ been a recent lattice update, where the internals have undergone some change, so there is a chance that is to blame. I won't be able to take a look before day after tomorrow. -Deepayan -- Michael Friendly Email: frien...@yorku.ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Streethttp://datavis.ca Toronto, ONT M3J 1P3 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.
Re: [R] non-integer key for data.table
Hi: Convert the location to factor and you should be OK: x - factor(sample(LETTERS[1:3], 10, replace = TRUE)) storage.mode(x) [1] integer BTW, data.table has its own mailing list: Send datatable-help mailing list submissions to datatable-h...@lists.r-forge.r-project.org To subscribe or unsubscribe via the World Wide Web, visit https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help You need to be subscribed first before posting. HTH, Dennis On Sun, Sep 12, 2010 at 10:35 AM, Anyi Zhu anyi@gmail.com wrote: Hi all, Say if I have a data table which consists of 4 column: itemID, location and price, which location is a text field and itemID and location together forms the primary keys. when I tried to run setkey (DT, itemID, location), I got the following message: Error in setkey (DT, itemID, location) : All keyed columns must be storage mode integer Is there any way I could define a non-numerical field (in this case location) to be the key? Also, if I do not use the location as a key, will I still able to merge 2 data tables based on itemID and location using the merge method in data.table? Thanks a lot! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] reshape matrix entities to columns
Hi: Natasha said: I changed it so i hope it will look better now the matrix is like this: AgeNo. Age No. AgeNo. Center1 52 8 7 Center210 720 9 4 10 column name = sequence of age-no. But what I want the data to look like is this Age 1 2 3 4 5 6 7 8 9 10 20 Center1 27 Center2 10 7 9 column name= age of ppl entries = number of ppl with that age in on center * It's a continuation of the reshape problem, but we have to change the NAs in the reshaped data frame to zeros first: df2[is.na(df2)] - 0 xtabs(n ~ center + age, data = df2) age center 5 6 7 8 9 10 11 12 13 14 1 0 10 0 13 0 9 0 7 0 10 2 0 0 12 14 0 0 16 0 0 13 3 6 0 0 0 10 0 12 0 9 0 How's that? Dennis On Sun, Sep 12, 2010 at 9:46 AM, Dennis Murphy djmu...@gmail.com wrote: Hi: Here's a made up example using the reshape function: Input data: df - structure(list(center = 1:3, age1 = c(6L, 7L, 5L), n1 = c(10L, 12L, 6L), age2 = c(8L, 8L, 8L), n2 = c(13L, 14L, NA), age3 = c(10L, 10L, 9L), n3 = c(9L, NA, 10L), age4 = c(12L, 11L, 11L), n4 = c(7L, 16L, 12L), age5 = c(14L, 14L, 13L), n5 = c(10L, 13L, 9L)), .Names = c(center, age1, n1, age2, n2, age3, n3, age4, n4, age5, n5), class = data.frame, row.names = c(NA, -3L)) df center age1 n1 age2 n2 age3 n3 age4 n4 age5 n5 1 16 108 13 10 9 12 7 14 10 2 27 128 14 10 NA 11 16 14 13 3 35 68 NA9 10 11 12 13 9 # To reshape more than one variable at a time, you need # to put the sets of variables into a list, as follows: df2 - reshape(df, idvar = 'center', varying = list(c(paste('age', 1:5, sep = '')), c(paste('n', 1:5, sep = ''))), v.names = c('age', 'n'), times = 1:5, direction = 'long') df2 center time age n 1.1 11 6 10 2.1 21 7 12 3.1 31 5 6 1.2 12 8 13 2.2 22 8 14 3.2 32 8 NA 1.3 13 10 9 2.3 23 10 NA 3.3 33 9 10 1.4 14 12 7 2.4 24 11 16 3.4 34 11 12 1.5 15 14 10 2.5 25 14 13 3.5 35 13 9 HTH, Dennis On Sun, Sep 12, 2010 at 7:45 AM, Natasha Asar natasha.asa...@yahoo.comwrote: Greeting R helpers J I am not familiar with R but I have to use it to analyze data set that I have (30,000 20,000) I want to change the structure of the dataset and I am wondering how that might be possible in R A main data looks like this: some entities are empty AgeNo. AgeNo. AgeNo. Center15 2 8 7 Center210 7 20 9 4 10 But what I want the data to look like is Age1 2 3 4 5 6 7 8 9 10 20 Center1 2 7 Center2 10 7 9 It should read the entities one by one when j is in age column take its value and consider it as the column number for new matrix then go to next entity (j No. columns) and put that entity under the columns number identified in previous step. In other word it should get the each element in No. columns (one by one) and place them in a new matrix under the column number which are equal to entity of age columns of first matrix i have tired ncol, and cbind and things like that but I guess im on the wrong path because it is not working. I am reading this fine with read.csv and writing back the same way. do you know how I can make this work?? Is it even possible to do something like this? Thank you in advance Natasha [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Efficient ways of merging data frames
Have you tried 'pasting' the values together and then using this as the key for the join? On Sun, Sep 12, 2010 at 2:39 PM, Anyi Zhu anyi@gmail.com wrote: Hi all, I am just wondering if there is a more efficient way of merging two large datasets based on the values of multiple columns, some of which are not numerical. The default merge function in dataframe is very inefficient and the merge function in data.table seems to be faster, but it does not seem to allow keys that are not numerical in nature. Any other suggestion? Thanks a lot! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] average matrices across a list
Hi, I have a list of several hundred 2 dimensional matrices, where each matrix is n x m. What I need to do is that for each n,m I need an average over all the lists. This would collapse it down to just one nxm matrix. Any easy ways to do that? As always, I'd like to avoid a for loop to keep computational time low! Thanks again everyone! Cheers, G __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] scalable delimiters in plotmath
On Sep 12, 2010, at 6:15 AM, baptiste auguie wrote: Thanks everyone. I've also had a look at plotmath.c where bgroup is defined for [, {, (, . but not . It seems quite trivial to add it, at first sight, however there is a part that I don't understand in the RenderDelim routine, static BBOX RenderDelim(int which, double dist, int draw, mathContext *mc, pGEcontext gc, pGEDevDesc dd) { // [... snipped ...] case '(': top = 230; ext = 231; bot = 232; mid = 0; break; case ')': top = 246; ext = 247; bot = 248; mid = 0; break; These integer codes make no sense to me, I have no clue which ones I should use for and . Does this help? (I think they are using Symbol PS fonts with decimal indexing.) as.octmode(c(230, 231, 232, 246, 247, 248) ) [1] 346 347 350 366 367 370 plot(1,1, xlab= expression( symbol(\346)~# upper 1/3 of left paren symbol(\347)~# to left of center bar symbol(\350)~# lower 1/3 of left paren symbol(\366)~# upper 1/3 of right paren symbol(\367)~# to right of center bar symbol(\370) ) ) # lower 1/3 of right paren (caveat: Maybe not standard glyph-names.) I added octal annotation to the TestChars(font=5) call that the points help page offers: TestChars(font=5) for(j in 1:14) { for(i in 0:16){ text(i+0.2, j+.6, labels=as.octmode(i+(j+1)*16), cex=.5)}} I do not see a trio or pair of glyphs that would form an angle bracket. -- David. As far as I understand these codes might correspond to extended ascii characters whose boundaries and positions we want to borrow. Then again, maybe it's something else entirely. Any hints? Best wishes, baptiste On 12 September 2010 03:27, David Winsemius dwinsem...@comcast.net wrote: On Sep 11, 2010, at 9:00 PM, Peter Ehlers wrote: On 2010-09-11 16:14, Dennis Murphy wrote: Hi Baptiste, You need to use the symbol(\nnn) concept, where nnn denotes the octal symbol number. For it's 074 and for it's 076. This little test seemed to work: plot(1, 1, main = expression(symbol(\074)~'x, y'~symbol(\076))) HTH, Dennis It's a matter of taste, but I would use \341 and \361. However, these are still not scalable, AFAICS. Not exactly scalable angles, but you can fake it: plot(1, 1, main = expression(symbol(\341)~scriptstyle( atop(x,y) )~symbol(\361)), cex.main=3) scriptstyle shrinks the inner atop() material, and since I tested on a Mac it should work for Baptiste. -- David. -Peter Ehlers On Sat, Sep 11, 2010 at 10:01 AM, baptiste auguie baptiste.aug...@googlemail.com wrote: What do people use to show angle bracketsin R graphics? Have I missed something obvious? Thanks, baptiste On 9 September 2010 17:57, baptiste auguie baptiste.aug...@googlemail.com wrote: Dear list, I read in ?plotmath that I can use bgroup to draw scalable delimiters such as [ ] and ( ). The same technique fails with however, and I cannot find a workaround, grid.text(expression(bgroup(,atop(x,y),))) Error in bgroup(, atop(x, y),) : invalid group delimiter Regards, baptiste sessionInfo() R version 2.11.1 (2010-05-31) x86_64-apple-darwin9.8.0 David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] average matrices across a list
Sorry, I forgot to add that some of the entries in various matrices have NA in them. On Sep 12, 2010, at 3:40 PM, Gregory Ryslik wrote: Hi, I have a list of several hundred 2 dimensional matrices, where each matrix is n x m. What I need to do is that for each n,m I need an average over all the lists. This would collapse it down to just one nxm matrix. Any easy ways to do that? As always, I'd like to avoid a for loop to keep computational time low! Thanks again everyone! Cheers, G __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] average matrices across a list
Gregory - Suppose your list is called mymats. Then Reduce(+,mymats) does what you want. - Phil On Sun, 12 Sep 2010, Gregory Ryslik wrote: Hi, I have a list of several hundred 2 dimensional matrices, where each matrix is n x m. What I need to do is that for each n,m I need an average over all the lists. This would collapse it down to just one nxm matrix. Any easy ways to do that? As always, I'd like to avoid a for loop to keep computational time low! Thanks again everyone! Cheers, G __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] URL error when trying to use help function in R [Sec: UNOFFICIAL]
Thanks for the feedback. Peter, I have forwarded your response to our ICT division to see if there is anything they can do. One potentially silly question: what would happen if I had the help files loaded locally on my PC - would the call then work? I'm wondering about the wisdom of creating a proper directory structure, empty apart from the help files, on my local PC. Cheers Michelle -Original Message- From: Peter Dalgaard [mailto:pda...@gmail.com] Sent: Friday, 10 September 2010 6:19 p.m. To: David Winsemius Cc: Gosse, Michelle; 'R-help@r-project.org' Subject: Re: [R] URL error when trying to use help function in R [Sec: UNOFFICIAL] On 09/10/2010 01:03 AM, David Winsemius wrote: On Sep 9, 2010, at 6:34 PM, Gosse, Michelle wrote: Greetings, I am using R version 2.11.1 on a Dell computer, via a VMware connection to a remote server. My browser version is IE 8.0.6001.18702 and the OS is some corporate version of Microsoft XP. I'm trying to learn more about the tapply function , so I typed ? tapply into the command line. This opened up a browser window with url http://127.0.0.1:28138/library/base/html/tapply.html which is giving me an error message. I receive the same problem when trying for help on other commands, e.g. ?table http://127.0.0.1:28138/library/base/html/table.html and ? log http://127.0.0.1:28138/library/base/html/Log.html I did a whois on 127.0.0.1 That should always be your own computer. The browser is trying to reach a server on itself over port 28138 and either the port is blocked or you don't have the documentation at that location. The _real_ problem is likely that the server is really running on the remote computer. Substituting the remote server name for 127.0.0.1 is not unlikely to make things work. (Notwithstanding firewalls and the like). It is a generic weakness of our current dynamic HTML setup, or of current browser technology if you like. Same thing with file:// URLs -- if you try to view them in a browser and you already have a browser on your display, but running on a different machine than the one with the file, you get a file not found. So when R on machine B wants to display a help page, it sends a message to the browser to connect to R's own server on B by specifying a port on localhost (127.0.0.1), but if this request gets forwarded to a browser on machine A, then it goes looking for a server on _its_ localhost, i.e. machine A, and it isn't there... I suppose we could do somewhat better, but I don't feel too confident about the various platform issues. As far as I can see, we currently hardcode http://127.0.0.1; inside the help print method in utils:::print.help_file_with_topics(), and I suspect we could make that a user option, or try to be more intelligent about finding the machine's own IP address. A pragmatic way out is always options(help_type=text). -- Peter Dalgaard Center for Statistics, Copenhagen Business School Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com ** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses. www.clearswift.com ** __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] average matrices across a list
Hi, Doing that I get the following: Browse[2] Reduce[+,results] Error in Reduce[+, results] : object of type 'closure' is not subsettable Thanks again! Kind regards, Greg On Sep 12, 2010, at 3:49 PM, Phil Spector wrote: Gregory - Suppose your list is called mymats. Then Reduce(+,mymats) does what you want. - Phil On Sun, 12 Sep 2010, Gregory Ryslik wrote: Hi, I have a list of several hundred 2 dimensional matrices, where each matrix is n x m. What I need to do is that for each n,m I need an average over all the lists. This would collapse it down to just one nxm matrix. Any easy ways to do that? As always, I'd like to avoid a for loop to keep computational time low! Thanks again everyone! Cheers, G __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] scalable delimiters in plotmath
Oh, right I see. I was completely off then. Maybe it's not so easy to add delimiters after all, I'll have to look at the list of symbol pieces to see if these can be constructed too. Thanks, baptiste On 12 September 2010 21:42, David Winsemius dwinsem...@comcast.net wrote: On Sep 12, 2010, at 6:15 AM, baptiste auguie wrote: Thanks everyone. I've also had a look at plotmath.c where bgroup is defined for [, {, (, . but not . It seems quite trivial to add it, at first sight, however there is a part that I don't understand in the RenderDelim routine, static BBOX RenderDelim(int which, double dist, int draw, mathContext *mc, pGEcontext gc, pGEDevDesc dd) { // [... snipped ...] case '(': top = 230; ext = 231; bot = 232; mid = 0; break; case ')': top = 246; ext = 247; bot = 248; mid = 0; break; These integer codes make no sense to me, I have no clue which ones I should use for and . Does this help? (I think they are using Symbol PS fonts with decimal indexing.) as.octmode(c(230, 231, 232, 246, 247, 248) ) [1] 346 347 350 366 367 370 plot(1,1, xlab= expression( symbol(\346)~ # upper 1/3 of left paren symbol(\347)~ # to left of center bar symbol(\350)~ # lower 1/3 of left paren symbol(\366)~ # upper 1/3 of right paren symbol(\367)~ # to right of center bar symbol(\370) ) ) # lower 1/3 of right paren (caveat: Maybe not standard glyph-names.) I added octal annotation to the TestChars(font=5) call that the points help page offers: TestChars(font=5) for(j in 1:14) { for(i in 0:16){ text(i+0.2, j+.6, labels=as.octmode(i+(j+1)*16), cex=.5)}} I do not see a trio or pair of glyphs that would form an angle bracket. -- David. As far as I understand these codes might correspond to extended ascii characters whose boundaries and positions we want to borrow. Then again, maybe it's something else entirely. Any hints? Best wishes, baptiste On 12 September 2010 03:27, David Winsemius dwinsem...@comcast.net wrote: On Sep 11, 2010, at 9:00 PM, Peter Ehlers wrote: On 2010-09-11 16:14, Dennis Murphy wrote: Hi Baptiste, You need to use the symbol(\nnn) concept, where nnn denotes the octal symbol number. For it's 074 and for it's 076. This little test seemed to work: plot(1, 1, main = expression(symbol(\074)~'x, y'~symbol(\076))) HTH, Dennis It's a matter of taste, but I would use \341 and \361. However, these are still not scalable, AFAICS. Not exactly scalable angles, but you can fake it: plot(1, 1, main = expression(symbol(\341)~scriptstyle( atop(x,y) )~symbol(\361)), cex.main=3) scriptstyle shrinks the inner atop() material, and since I tested on a Mac it should work for Baptiste. -- David. -Peter Ehlers On Sat, Sep 11, 2010 at 10:01 AM, baptiste auguie baptiste.aug...@googlemail.com wrote: What do people use to show angle brackets in R graphics? Have I missed something obvious? Thanks, baptiste On 9 September 2010 17:57, baptiste auguie baptiste.aug...@googlemail.com wrote: Dear list, I read in ?plotmath that I can use bgroup to draw scalable delimiters such as [ ] and ( ). The same technique fails with however, and I cannot find a workaround, grid.text(expression(bgroup(,atop(x,y),))) Error in bgroup(, atop(x, y),) : invalid group delimiter Regards, baptiste sessionInfo() R version 2.11.1 (2010-05-31) x86_64-apple-darwin9.8.0 David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] using read.table, removing extra quotation mark from a text field? (e.g. cat )
You can use the 'gsub' command to remove the quote marks. You could readLines/writeLines the file to clean it up with gsub before using read.table on it so it can all be done within R. On Sun, Sep 12, 2010 at 1:58 PM, Eva Nordstrom eva.nordst...@yahoo.com wrote: I am using read.table to import a text file within R. There are several errors in my text file. An extra quotation mark has inadvertently been included within a few text fields. e.g. for a pipe (|) delimited text file, I have something similar to this: 1|7|30| dog 2|6|25| cat 3|4|20| 4|5| 56| mouse 5|3|56| horse 6|56| In the above example| there are extra quotation marks within the fields for cat and horse. (row 2 and row 5) e.g. cat , horse One solution is to simply edit the text file and remove the extra quotation mark. Is there a good solution I can implement form within R? I am OK with just importing the extra quotation marks and having nit show up as part of the text field within R. e.g, cat horse Thanks. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] scalable delimiters in plotmath
Hi On 13/09/2010 7:57 a.m., baptiste auguie wrote: Oh, right I see. I was completely off then. Maybe it's not so easy to add delimiters after all, I'll have to look at the list of symbol pieces to see if these can be constructed too. The plotmath stuff assumes a font with an Adobe Symbol encoding. The characters we have to play with are shown at http://www.stat.auckland.ac.nz/~paul/R/CM/AdobeSym.pdf. You can see the components of growable delimiters on the bottom two rows. Paul Thanks, baptiste On 12 September 2010 21:42, David Winsemiusdwinsem...@comcast.net wrote: On Sep 12, 2010, at 6:15 AM, baptiste auguie wrote: Thanks everyone. I've also had a look at plotmath.c where bgroup is defined for [, {, (, . but not . It seems quite trivial to add it, at first sight, however there is a part that I don't understand in the RenderDelim routine, static BBOX RenderDelim(int which, double dist, int draw, mathContext *mc, pGEcontext gc, pGEDevDesc dd) { // [... snipped ...] case '(': top = 230; ext = 231; bot = 232; mid = 0; break; case ')': top = 246; ext = 247; bot = 248; mid = 0; break; These integer codes make no sense to me, I have no clue which ones I should use for and. Does this help? (I think they are using Symbol PS fonts with decimal indexing.) as.octmode(c(230, 231, 232, 246, 247, 248) ) [1] 346 347 350 366 367 370 plot(1,1, xlab= expression( symbol(\346)~# upper 1/3 of left paren symbol(\347)~# to left of center bar symbol(\350)~# lower 1/3 of left paren symbol(\366)~# upper 1/3 of right paren symbol(\367)~# to right of center bar symbol(\370) ) ) # lower 1/3 of right paren (caveat: Maybe not standard glyph-names.) I added octal annotation to the TestChars(font=5) call that the points help page offers: TestChars(font=5) for(j in 1:14) { for(i in 0:16){ text(i+0.2, j+.6, labels=as.octmode(i+(j+1)*16), cex=.5)}} I do not see a trio or pair of glyphs that would form an angle bracket. -- David. As far as I understand these codes might correspond to extended ascii characters whose boundaries and positions we want to borrow. Then again, maybe it's something else entirely. Any hints? Best wishes, baptiste On 12 September 2010 03:27, David Winsemiusdwinsem...@comcast.net wrote: On Sep 11, 2010, at 9:00 PM, Peter Ehlers wrote: On 2010-09-11 16:14, Dennis Murphy wrote: Hi Baptiste, You need to use the symbol(\nnn) concept, where nnn denotes the octal symbol number. Forit's 074 and forit's 076. This little test seemed to work: plot(1, 1, main = expression(symbol(\074)~'x, y'~symbol(\076))) HTH, Dennis It's a matter of taste, but I would use \341 and \361. However, these are still not scalable, AFAICS. Not exactly scalable angles, but you can fake it: plot(1, 1, main = expression(symbol(\341)~scriptstyle( atop(x,y) )~symbol(\361)), cex.main=3) scriptstyle shrinks the inner atop() material, and since I tested on a Mac it should work for Baptiste. -- David. -Peter Ehlers On Sat, Sep 11, 2010 at 10:01 AM, baptiste auguie baptiste.aug...@googlemail.comwrote: What do people use to show angle bracketsin R graphics? Have I missed something obvious? Thanks, baptiste On 9 September 2010 17:57, baptiste auguie baptiste.aug...@googlemail.comwrote: Dear list, I read in ?plotmath that I can use bgroup to draw scalable delimiters such as [ ] and ( ). The same technique fails withhowever, and I cannot find a workaround, grid.text(expression(bgroup(,atop(x,y),))) Error in bgroup(, atop(x, y),) : invalid group delimiter Regards, baptiste sessionInfo() R version 2.11.1 (2010-05-31) x86_64-apple-darwin9.8.0 David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 p...@stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] URL error when trying to use help function in R [Sec: UNOFFICIAL]
On 12/09/2010 3:50 PM, Gosse, Michelle wrote: Thanks for the feedback. Peter, I have forwarded your response to our ICT division to see if there is anything they can do. One potentially silly question: what would happen if I had the help files loaded locally on my PC - would the call then work? I'm wondering about the wisdom of creating a proper directory structure, empty apart from the help files, on my local PC. R generates the help pages on demand. You can tell it what port to use, but it's not very easy to generate fixed copies of the HTML output. Duncan Murdoch Cheers Michelle -Original Message- From: Peter Dalgaard [mailto:pda...@gmail.com] Sent: Friday, 10 September 2010 6:19 p.m. To: David Winsemius Cc: Gosse, Michelle; 'R-help@r-project.org' Subject: Re: [R] URL error when trying to use help function in R [Sec: UNOFFICIAL] On 09/10/2010 01:03 AM, David Winsemius wrote: On Sep 9, 2010, at 6:34 PM, Gosse, Michelle wrote: Greetings, I am using R version 2.11.1 on a Dell computer, via a VMware connection to a remote server. My browser version is IE 8.0.6001.18702 and the OS is some corporate version of Microsoft XP. I'm trying to learn more about the tapply function , so I typed ? tapply into the command line. This opened up a browser window with url http://127.0.0.1:28138/library/base/html/tapply.html which is giving me an error message. I receive the same problem when trying for help on other commands, e.g. ?table http://127.0.0.1:28138/library/base/html/table.html and ? log http://127.0.0.1:28138/library/base/html/Log.html I did a whois on 127.0.0.1 That should always be your own computer. The browser is trying to reach a server on itself over port 28138 and either the port is blocked or you don't have the documentation at that location. The _real_ problem is likely that the server is really running on the remote computer. Substituting the remote server name for 127.0.0.1 is not unlikely to make things work. (Notwithstanding firewalls and the like). It is a generic weakness of our current dynamic HTML setup, or of current browser technology if you like. Same thing with file:// URLs -- if you try to view them in a browser and you already have a browser on your display, but running on a different machine than the one with the file, you get a file not found. So when R on machine B wants to display a help page, it sends a message to the browser to connect to R's own server on B by specifying a port on localhost (127.0.0.1), but if this request gets forwarded to a browser on machine A, then it goes looking for a server on _its_ localhost, i.e. machine A, and it isn't there... I suppose we could do somewhat better, but I don't feel too confident about the various platform issues. As far as I can see, we currently hardcode http://127.0.0.1; inside the help print method in utils:::print.help_file_with_topics(), and I suspect we could make that a user option, or try to be more intelligent about finding the machine's own IP address. A pragmatic way out is always options(help_type=text). __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] create a '3D line plot'
Cheers! All excellent, runable examples helping me progress quickly. Being more a qualitative plot, the y-axis is less important. But it did get me thinking- Coloring each of the plotted lines, say 'altitude colors' like the classic volcano example to reflect the (scaled) values the lines represent might be effective at representing individual y-axis magnitude for each line. Perhaps gray background at least. Maybe if there were examples of the lines() func. using colors dependent on the y-value? Or some one already made a function for achieving this? (Google didnt return anything obvious for me...yet). Sincere thanks for help thus far, and welcome any further pointers, Karl On 9/12/2010 4:50 PM, Duncan Murdoch wrote: On 12/09/2010 10:12 AM, Karl Brand wrote: Esteemed useRs and developeRs, I need to create a '3D line plot' (proper name?) of which an excellent example can be viewed here: http://cococubed.asu.edu/images/87a/images/unknown_pleasures.jpg I have some experience using the rgl package to create 3D PCA plots, but have no idea where to start for an image like this. I'd really appreciate suggestions help on how might achieve this using R, I wouldn't use rgl for that: it's really a flat 2D plot, without perspective, shading or anything else that 3D plots have other than foreground objects hiding background ones. You can draw it by using polygon() to hide the background then lines() to draw the lines. Here's an example using regular 2d graphics: n - 60 m - 50 x - seq(-4,4, len=m) # Make up some fake y data y - matrix(NA, n, m) for (i in 1:n) y[i,] - dnorm(x)*runif(m, 0.5,1) par(bg=black) yrange - range(c(y, y+n/20)) plot(x, x, type=n, axes=FALSE, bg=black, ylim=yrange) for (i in n:1) { y1 - c(y[i,] + i/20, 0, 0) x1 - c(x, x[m], x[1]) polygon(x1,y1,col=black) lines(x, y[i,] + i/20, col=white) } The problem with this kind of plot is that it's almost impossible to display a usable vertical scale. Duncan Murdoch -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam T +31 (0)10 704 3457 |F +31 (0)10 704 4743 |M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] scalable delimiters in plotmath
I see, thanks. Looking at this table I guess the short answer is no, these cannot be made to scale and the only ones that could have already been implemented in bgroup(). Thanks, baptiste On 12 September 2010 22:11, Paul Murrell p.murr...@auckland.ac.nz wrote: Hi On 13/09/2010 7:57 a.m., baptiste auguie wrote: Oh, right I see. I was completely off then. Maybe it's not so easy to add delimiters after all, I'll have to look at the list of symbol pieces to see if these can be constructed too. The plotmath stuff assumes a font with an Adobe Symbol encoding. The characters we have to play with are shown at http://www.stat.auckland.ac.nz/~paul/R/CM/AdobeSym.pdf. You can see the components of growable delimiters on the bottom two rows. Paul Thanks, baptiste On 12 September 2010 21:42, David Winsemiusdwinsem...@comcast.net wrote: On Sep 12, 2010, at 6:15 AM, baptiste auguie wrote: Thanks everyone. I've also had a look at plotmath.c where bgroup is defined for [, {, (, . but not . It seems quite trivial to add it, at first sight, however there is a part that I don't understand in the RenderDelim routine, static BBOX RenderDelim(int which, double dist, int draw, mathContext *mc, pGEcontext gc, pGEDevDesc dd) { // [... snipped ...] case '(': top = 230; ext = 231; bot = 232; mid = 0; break; case ')': top = 246; ext = 247; bot = 248; mid = 0; break; These integer codes make no sense to me, I have no clue which ones I should use for and. Does this help? (I think they are using Symbol PS fonts with decimal indexing.) as.octmode(c(230, 231, 232, 246, 247, 248) ) [1] 346 347 350 366 367 370 plot(1,1, xlab= expression( symbol(\346)~ # upper 1/3 of left paren symbol(\347)~ # to left of center bar symbol(\350)~ # lower 1/3 of left paren symbol(\366)~ # upper 1/3 of right paren symbol(\367)~ # to right of center bar symbol(\370) ) ) # lower 1/3 of right paren (caveat: Maybe not standard glyph-names.) I added octal annotation to the TestChars(font=5) call that the points help page offers: TestChars(font=5) for(j in 1:14) { for(i in 0:16){ text(i+0.2, j+.6, labels=as.octmode(i+(j+1)*16), cex=.5)}} I do not see a trio or pair of glyphs that would form an angle bracket. -- David. As far as I understand these codes might correspond to extended ascii characters whose boundaries and positions we want to borrow. Then again, maybe it's something else entirely. Any hints? Best wishes, baptiste On 12 September 2010 03:27, David Winsemiusdwinsem...@comcast.net wrote: On Sep 11, 2010, at 9:00 PM, Peter Ehlers wrote: On 2010-09-11 16:14, Dennis Murphy wrote: Hi Baptiste, You need to use the symbol(\nnn) concept, where nnn denotes the octal symbol number. For it's 074 and for it's 076. This little test seemed to work: plot(1, 1, main = expression(symbol(\074)~'x, y'~symbol(\076))) HTH, Dennis It's a matter of taste, but I would use \341 and \361. However, these are still not scalable, AFAICS. Not exactly scalable angles, but you can fake it: plot(1, 1, main = expression(symbol(\341)~scriptstyle( atop(x,y) )~symbol(\361)), cex.main=3) scriptstyle shrinks the inner atop() material, and since I tested on a Mac it should work for Baptiste. -- David. -Peter Ehlers On Sat, Sep 11, 2010 at 10:01 AM, baptiste auguie baptiste.aug...@googlemail.com wrote: What do people use to show angle brackets in R graphics? Have I missed something obvious? Thanks, baptiste On 9 September 2010 17:57, baptiste auguie baptiste.aug...@googlemail.com wrote: Dear list, I read in ?plotmath that I can use bgroup to draw scalable delimiters such as [ ] and ( ). The same technique fails with however, and I cannot find a workaround, grid.text(expression(bgroup(,atop(x,y),))) Error in bgroup(, atop(x, y),) : invalid group delimiter Regards, baptiste sessionInfo() R version 2.11.1 (2010-05-31) x86_64-apple-darwin9.8.0 David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 p...@stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Efficient ways of merging data frames
Hi: On Sun, Sep 12, 2010 at 11:39 AM, Anyi Zhu anyi@gmail.com wrote: Hi all, I am just wondering if there is a more efficient way of merging two large datasets based on the values of multiple columns, some of which are not numerical. As noted in your previous post, the variables comprising the key in data.table must be of *storage mode* integer, as expressed in the error message you received. This can be checked with storage.mode(obj) In a data frame/data.table, you can check the storage mode of all variables with sapply(df, storage.mode) Integers and factors are both of storage mode integer, so if you have a character variable, convert it to a factor before applying setkey(). x - LETTERS[1:3] storage.mode(x) [1] character x2 - factor(x) storage.mode(x2) [1] integer You can always overwrite x if you wish. The default merge function in dataframe is very inefficient and the merge function in data.table seems to be faster, but it does not seem to allow keys that are not numerical in nature. Merging in data.table is faster because it uses binary scans on the key variables in each data table rather than the vector scans used on the by variables in data frames. data.table also allows a wider variety of join operations than does merge(), so I would agree with you re speed. However, keys need to have an integer *storage mode* - they do not have to be integer per se, as the example above shows. Here's a toy example to illustrate the point: library(data.table) # d is character in both d1 and d2 d1 - data.frame(b = rep(1:3, each = 3), d = rep(LETTERS[1:3], 3), v1 = rpois(9, 10), stringsAsFactors = FALSE) d2 - data.frame(b = rep(1:3, each = 3), d = rep(LETTERS[1:3], 3), v2 = rpois(9, 5), stringsAsFactors = FALSE) # Try to convert d1 to a data table with d as a key variable, # where d is character t1 - data.table(d1, key = 'b, d') # Ooops... Error in setkey(value, b, d) : All keyed columns must be storage mode integer str(d1) 'data.frame': 9 obs. of 3 variables: $ b : int 1 1 1 2 2 2 3 3 3 $ d : chr A B C A ... $ v1: num 9 12 8 10 9 9 11 10 10 # Convert d to factor in both data frames and try again: d1$d - factor(d1$d) d2$d - factor(d2$d) t1 - data.table(d1, key = 'b, d') t2 - data.table(d2, key = 'b, d') tt- data.table(merge(t1, t2)) tt b d v1 v2 [1,] 1 A 9 3 [2,] 1 B 12 7 [3,] 1 C 8 2 [4,] 2 A 10 4 [5,] 2 B 9 7 [6,] 2 C 9 4 [7,] 3 A 11 2 [8,] 3 B 10 5 [9,] 3 C 10 4 HTH, Dennis Any other suggestion? Thanks a lot! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] scalable delimiters in plotmath
On Sep 12, 2010, at 4:11 PM, Paul Murrell wrote: Hi On 13/09/2010 7:57 a.m., baptiste auguie wrote: Oh, right I see. I was completely off then. Maybe it's not so easy to add delimiters after all, I'll have to look at the list of symbol pieces to see if these can be constructed too. The plotmath stuff assumes a font with an Adobe Symbol encoding. The characters we have to play with are shown at http://www.stat.auckland.ac.nz/~paul/R/CM/AdobeSym.pdf . You can see the components of growable delimiters on the bottom two rows. Hello Paul; Both Baptiste and I have looked at the plotmath.c code and it appears that only a few of those delimiters are supported. We specifically have tried to use the angle brackets: plot(1,1, xlab=expression(bgroup(symbol(0xe1),atop(x,y),symbol(0xf1 Error in bgroup(symbol(225), atop(x, y), symbol(241)) : invalid group delimiter The supported delimiters appear to each be built up from three parts that are then assembled within a bounding box and as far as I can determine are limited to |, ||, [, {, (, ), },and }. I needed to download the full source to find a copy, but I'm fairly sure a guRu of your standing needs no help finding the code that handles the bgroup display inside plotmath.c. I am not at my machine where I was looking at it, but the code that I just found in expanded form on the Internet bore your name as a copyright holder. So I guess my feature request would be: ---add option for using scalable single character delimiters such as Symbol(0xe1) and Symbol(0xe1). I'm guessing that the reason three-component delimiters were chosen is that it was easier to expand the middle section while not expanding the ends as much but that's just the guess of someone who is perusing without really being able to fully grasp the intricacies of what is being done. -- David Paul Thanks, baptiste On 12 September 2010 21:42, David Winsemiusdwinsem...@comcast.net wrote: On Sep 12, 2010, at 6:15 AM, baptiste auguie wrote: Thanks everyone. I've also had a look at plotmath.c where bgroup is defined for [, {, (, . but not . It seems quite trivial to add it, at first sight, however there is a part that I don't understand in the RenderDelim routine, static BBOX RenderDelim(int which, double dist, int draw, mathContext *mc, pGEcontext gc, pGEDevDesc dd) { // [... snipped ...] case '(': top = 230; ext = 231; bot = 232; mid = 0; break; case ')': top = 246; ext = 247; bot = 248; mid = 0; break; These integer codes make no sense to me, I have no clue which ones I should use for and. Does this help? (I think they are using Symbol PS fonts with decimal indexing.) as.octmode(c(230, 231, 232, 246, 247, 248) ) [1] 346 347 350 366 367 370 plot(1,1, xlab= expression( symbol(\346)~# upper 1/3 of left paren symbol(\347)~# to left of center bar symbol(\350)~# lower 1/3 of left paren symbol(\366)~# upper 1/3 of right paren symbol(\367)~# to right of center bar symbol(\370) ) ) # lower 1/3 of right paren (caveat: Maybe not standard glyph-names.) I added octal annotation to the TestChars(font=5) call that the points help page offers: TestChars(font=5) for(j in 1:14) { for(i in 0:16){ text(i+0.2, j+.6, labels=as.octmode(i+(j+1)*16), cex=.5)}} I do not see a trio or pair of glyphs that would form an angle bracket. -- David. As far as I understand these codes might correspond to extended ascii characters whose boundaries and positions we want to borrow. Then again, maybe it's something else entirely. Any hints? Best wishes, baptiste On 12 September 2010 03:27, David Winsemiusdwinsem...@comcast.net wrote: On Sep 11, 2010, at 9:00 PM, Peter Ehlers wrote: On 2010-09-11 16:14, Dennis Murphy wrote: Hi Baptiste, You need to use the symbol(\nnn) concept, where nnn denotes the octal symbol number. Forit's 074 and forit's 076. This little test seemed to work: plot(1, 1, main = expression(symbol(\074)~'x, y'~symbol(\076))) HTH, Dennis It's a matter of taste, but I would use \341 and \361. However, these are still not scalable, AFAICS. Not exactly scalable angles, but you can fake it: plot(1, 1, main = expression(symbol(\341)~scriptstyle( atop(x,y) )~symbol(\361)), cex.main=3) scriptstyle shrinks the inner atop() material, and since I tested on a Mac it should work for Baptiste. -- David. -Peter Ehlers On Sat, Sep 11, 2010 at 10:01 AM, baptiste auguie baptiste.aug...@googlemail.comwrote: What do people use to show angle bracketsin R graphics? Have I missed something obvious? Thanks, baptiste On 9 September 2010 17:57, baptiste auguie baptiste.aug...@googlemail.comwrote: Dear list, I read in ?plotmath that I can use bgroup to draw scalable delimiters such as [ ] and ( ). The same technique fails with however, and I cannot find a workaround,
Re: [R] reshape matrix entities to columns
On Sep 12, 2010, at 3:34 PM, Dennis Murphy wrote: Hi: Natasha said: I changed it so i hope it will look better now the matrix is like this: AgeNo. Age No. AgeNo. Center1 52 8 7 Center210 720 9 4 10 column name = sequence of age-no. But what I want the data to look like is this Age 1 2 3 4 5 6 7 8 9 10 20 Center1 27 Center2 10 7 9 column name= age of ppl entries = number of ppl with that age in on center * It's a continuation of the reshape problem, but we have to change the NAs in the reshaped data frame to zeros first: df2[is.na(df2)] - 0 xtabs(n ~ center + age, data = df2) age center 5 6 7 8 9 10 11 12 13 14 1 0 10 0 13 0 9 0 7 0 10 2 0 0 12 14 0 0 16 0 0 13 3 6 0 0 0 10 0 12 0 9 0 How's that? You've done all the hard work, but the OP wanted the full range of age values from 1:max and that pretty easy to do with one further step that adds entries fo the missing age levels: df3 - rbind(df2, data.frame(center=1,time=1, age=1:max(df2$age), n=0)) xtabs(n ~ center + age, data = df3) age center 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 0 0 0 0 0 10 0 13 0 9 0 7 0 10 2 0 0 0 0 0 0 12 14 0 0 16 0 0 13 3 0 0 0 0 6 0 0 0 10 0 12 0 9 0 -- David. Dennis On Sun, Sep 12, 2010 at 9:46 AM, Dennis Murphy djmu...@gmail.com wrote: Hi: Here's a made up example using the reshape function: Input data: df - structure(list(center = 1:3, age1 = c(6L, 7L, 5L), n1 = c(10L, 12L, 6L), age2 = c(8L, 8L, 8L), n2 = c(13L, 14L, NA), age3 = c(10L, 10L, 9L), n3 = c(9L, NA, 10L), age4 = c(12L, 11L, 11L), n4 = c(7L, 16L, 12L), age5 = c(14L, 14L, 13L), n5 = c(10L, 13L, 9L)), .Names = c(center, age1, n1, age2, n2, age3, n3, age4, n4, age5, n5), class = data.frame, row.names = c(NA, -3L)) df center age1 n1 age2 n2 age3 n3 age4 n4 age5 n5 1 16 108 13 10 9 12 7 14 10 2 27 128 14 10 NA 11 16 14 13 3 35 68 NA9 10 11 12 13 9 # To reshape more than one variable at a time, you need # to put the sets of variables into a list, as follows: df2 - reshape(df, idvar = 'center', varying = list(c(paste('age', 1:5, sep = '')), c(paste('n', 1:5, sep = ''))), v.names = c('age', 'n'), times = 1:5, direction = 'long') df2 center time age n 1.1 11 6 10 2.1 21 7 12 3.1 31 5 6 1.2 12 8 13 2.2 22 8 14 3.2 32 8 NA 1.3 13 10 9 2.3 23 10 NA 3.3 33 9 10 1.4 14 12 7 2.4 24 11 16 3.4 34 11 12 1.5 15 14 10 2.5 25 14 13 3.5 35 13 9 HTH, Dennis On Sun, Sep 12, 2010 at 7:45 AM, Natasha Asar natasha.asa...@yahoo.com wrote: Greeting R helpers J I am not familiar with R but I have to use it to analyze data set that I have (30,000 20,000) I want to change the structure of the dataset and I am wondering how that might be possible in R A main data looks like this: some entities are empty AgeNo. AgeNo. AgeNo. Center15 2 8 7 Center210 7 20 9 4 10 But what I want the data to look like is Age1 2 3 4 5 6 7 8 9 10 20 Center1 2 7 Center2 10 7 9 It should read the entities one by one when j is in age column take its value and consider it as the column number for new matrix then go to next entity (j No. columns) and put that entity under the columns number identified in previous step. In other word it should get the each element in No. columns (one by one) and place them in a new matrix under the column number which are equal to entity of age columns of first matrix i have tired ncol, and cbind and things like that but I guess im on the wrong path because it is not working. I am reading this fine with read.csv and writing back the same way. do you know how I can make this work?? Is it even possible to do something like this? Thank you in advance Natasha [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __
Re: [R] using read.table, removing extra quotation mark from a text field? (e.g. cat )
While you are looking for a solution within R, it might be simpler to open your text file in almost any free text editor (Notepad++, Textwrangler, Smultron, vim come to mind), and do Replace all ' for . On Sep 12, 2010, at 3:58 PM, jim holtman wrote: You can use the 'gsub' command to remove the quote marks. You could readLines/writeLines the file to clean it up with gsub before using read.table on it so it can all be done within R. On Sun, Sep 12, 2010 at 1:58 PM, Eva Nordstrom eva.nordst...@yahoo.com wrote: I am using read.table to import a text file within R. There are several errors in my text file. An extra quotation mark has inadvertently been included within a few text fields. e.g. for a pipe (|) delimited text file, I have something similar to this: 1|7|30| dog 2|6|25| cat 3|4|20| 4|5| 56| mouse 5|3|56| horse 6|56| In the above example| there are extra quotation marks within the fields for cat and horse. (row 2 and row 5) e.g. cat , horse One solution is to simply edit the text file and remove the extra quotation mark. Is there a good solution I can implement form within R? I am OK with just importing the extra quotation marks and having nit show up as part of the text field within R. e.g, cat horse Thanks. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] average matrices across a list
Gregory Ryslik rsaber at comcast.net writes: Browse[2] Reduce[+,results] Error in Reduce[+, results] : object of type 'closure' is not subsettable You need to use parentheses, not square brackets. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] average matrices across a list
Gregory - Please provide a reproducible example. I have no idea what results is. - Phil On Sun, 12 Sep 2010, Gregory Ryslik wrote: Hi, Doing that I get the following: Browse[2] Reduce[+,results] Error in Reduce[+, results] : object of type 'closure' is not subsettable Thanks again! Kind regards, Greg On Sep 12, 2010, at 3:49 PM, Phil Spector wrote: Gregory - Suppose your list is called mymats. Then Reduce(+,mymats) does what you want. - Phil On Sun, 12 Sep 2010, Gregory Ryslik wrote: Hi, I have a list of several hundred 2 dimensional matrices, where each matrix is n x m. What I need to do is that for each n,m I need an average over all the lists. This would collapse it down to just one nxm matrix. Any easy ways to do that? As always, I'd like to avoid a for loop to keep computational time low! Thanks again everyone! Cheers, G __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] average matrices across a list
Hi, Thanks, I was using the square brackets instead of (. The ( makes it work. However, some of my matrices have NA for some values. I need those NA's to basically not be counted. And if all the lists have NA for a specific (n,m), I want it to remain an (n,m). By using the Reduce('+', mymats), any entries with NA in at least one of the lists will give me back an NA for the sum (rather than making it NA if it at least on list has an NA for that element). Thanks again for everyone's help! Kind regards, Greg On Sep 12, 2010, at 4:54 PM, Dennis Murphy wrote: Hi: Here's a more concrete example of Phil's point. mymats - vector('list', 5) set.seed(246) # Generate a list of five 3 x 3 matrices for(i in 1:5) mymats[[i]] - matrix(sample(1:9), nrow = 3) # Sum them elementwise Reduce('+', mymats) [,1] [,2] [,3] [1,] 23 33 15 [2,] 25 36 26 [3,] 20 24 23 HTH, Dennis On Sun, Sep 12, 2010 at 12:52 PM, Gregory Ryslik rsa...@comcast.net wrote: Hi, Doing that I get the following: Browse[2] Reduce[+,results] Error in Reduce[+, results] : object of type 'closure' is not subsettable You want parentheses there, not brackets; you're asking R to subset a function, Reduce, which is an object of type closure. Hopefully the error message makes more sense now. Thanks again! Kind regards, Greg On Sep 12, 2010, at 3:49 PM, Phil Spector wrote: Gregory - Suppose your list is called mymats. Then Reduce(+,mymats) does what you want. - Phil On Sun, 12 Sep 2010, Gregory Ryslik wrote: Hi, I have a list of several hundred 2 dimensional matrices, where each matrix is n x m. What I need to do is that for each n,m I need an average over all the lists. This would collapse it down to just one nxm matrix. Any easy ways to do that? As always, I'd like to avoid a for loop to keep computational time low! Thanks again everyone! Cheers, G __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] create a '3D line plot'
Hi: Here's a fairly basic ggplot2 version with a few warts in it: # Generate means means - rpois(30, 10) # Create 30 Gaussian random samples of size 100, using means to # define the population mean for each sample (via sapply) df - data.frame(ds = rep(1:30, each = 100), x = as.vector(sapply(means, function(x) rnorm(100, means[x]))) ) library(ggplot2) # Two versions of density plot: # Version 1: no fill color, just curves h - ggplot(df2, aes(x = x, colour = ds)) h + geom_density() + facet_grid(ds ~ ., as.table = FALSE) + opts(axis.text.y = theme_blank()) # as.table = FALSE allows you to read upward from data set 1 to 30 # Version 2: add fill color g - ggplot(df2, aes(x = x, colour = ds, fill = ds)) g + geom_density() + facet_grid(ds ~ ., as.table = FALSE) + opts(axis.text.y = theme_blank()) Some problems that arose: (1) I couldn't figure out how to set a range of colors beyond the default. I tried several things with scale_colour_*, but one problem or another arose. Ideally, I'd like to be able to set the color by mean value, but that would require some thinking (OMG!) Some features of scales are still a bit beyond me... (2) I could get rid of the y-axis tick labels, but couldn't get rid of both the labels and the ticks. I was also hoping to use theme_bw() using just the horizontal grid lines, but no. I just thought of a couple ideas to play with on that front., though, so I'll continue to toy with it for a bit. All in all, for a few lines of code, it's a pretty decent plot, even though it needs some work. Thank Hadley for that... HTH, Dennis On Sun, Sep 12, 2010 at 1:17 PM, Karl Brand k.br...@erasmusmc.nl wrote: Cheers! All excellent, runable examples helping me progress quickly. Being more a qualitative plot, the y-axis is less important. But it did get me thinking- Coloring each of the plotted lines, say 'altitude colors' like the classic volcano example to reflect the (scaled) values the lines represent might be effective at representing individual y-axis magnitude for each line. Perhaps gray background at least. Maybe if there were examples of the lines() func. using colors dependent on the y-value? Or some one already made a function for achieving this? (Google didnt return anything obvious for me...yet). Sincere thanks for help thus far, and welcome any further pointers, Karl On 9/12/2010 4:50 PM, Duncan Murdoch wrote: On 12/09/2010 10:12 AM, Karl Brand wrote: Esteemed useRs and developeRs, I need to create a '3D line plot' (proper name?) of which an excellent example can be viewed here: http://cococubed.asu.edu/images/87a/images/unknown_pleasures.jpg I have some experience using the rgl package to create 3D PCA plots, but have no idea where to start for an image like this. I'd really appreciate suggestions help on how might achieve this using R, I wouldn't use rgl for that: it's really a flat 2D plot, without perspective, shading or anything else that 3D plots have other than foreground objects hiding background ones. You can draw it by using polygon() to hide the background then lines() to draw the lines. Here's an example using regular 2d graphics: n - 60 m - 50 x - seq(-4,4, len=m) # Make up some fake y data y - matrix(NA, n, m) for (i in 1:n) y[i,] - dnorm(x)*runif(m, 0.5,1) par(bg=black) yrange - range(c(y, y+n/20)) plot(x, x, type=n, axes=FALSE, bg=black, ylim=yrange) for (i in n:1) { y1 - c(y[i,] + i/20, 0, 0) x1 - c(x, x[m], x[1]) polygon(x1,y1,col=black) lines(x, y[i,] + i/20, col=white) } The problem with this kind of plot is that it's almost impossible to display a usable vertical scale. Duncan Murdoch -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam T +31 (0)10 704 3457 |F +31 (0)10 704 4743 |M +31 (0)642 777 268 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] using read.table, removing extra quotation mark from a text field? (e.g. cat )
Hi: On Sun, Sep 12, 2010 at 1:05 PM, Wil M Contreras Arbaje wil.contre...@gmail.com wrote: While you are looking for a solution within R, it might be simpler to open your text file in almost any free text editor (Notepad++, Textwrangler, Smultron, vim come to mind), and do Replace all ' for . There's one problem with that solution: if the character string at the end of the line is blank (i.e., ), then your suggestion will leave one double quote at the end of a line. Not good. What is needed is a gsub that takes two double quotes plus a wild card character and replaces it with one double quote and a wild card character. If you have an editor that can do that, let me know...seriously. I suspect emacs can do this, but none of the basic editors I know have that capability. Dennis On Sep 12, 2010, at 3:58 PM, jim holtman wrote: You can use the 'gsub' command to remove the quote marks. You could readLines/writeLines the file to clean it up with gsub before using read.table on it so it can all be done within R. On Sun, Sep 12, 2010 at 1:58 PM, Eva Nordstrom eva.nordst...@yahoo.com wrote: I am using read.table to import a text file within R. There are several errors in my text file. An extra quotation mark has inadvertently been included within a few text fields. e.g. for a pipe (|) delimited text file, I have something similar to this: 1|7|30| dog 2|6|25| cat 3|4|20| 4|5| 56| mouse 5|3|56| horse 6|56| In the above example| there are extra quotation marks within the fields for cat and horse. (row 2 and row 5) e.g. cat , horse One solution is to simply edit the text file and remove the extra quotation mark. Is there a good solution I can implement form within R? I am OK with just importing the extra quotation marks and having nit show up as part of the text field within R. e.g, cat horse Thanks. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] reshape matrix entities to columns
Thanks, David; I overlooked that part. Dennis On Sun, Sep 12, 2010 at 1:18 PM, David Winsemius dwinsem...@comcast.netwrote: On Sep 12, 2010, at 3:34 PM, Dennis Murphy wrote: Hi: Natasha said: I changed it so i hope it will look better now the matrix is like this: AgeNo. Age No. AgeNo. Center1 52 8 7 Center210 720 9 4 10 column name = sequence of age-no. But what I want the data to look like is this Age 1 2 3 4 5 6 7 8 9 10 20 Center1 27 Center2 10 7 9 column name= age of ppl entries = number of ppl with that age in on center * It's a continuation of the reshape problem, but we have to change the NAs in the reshaped data frame to zeros first: df2[is.na(df2)] - 0 xtabs(n ~ center + age, data = df2) age center 5 6 7 8 9 10 11 12 13 14 1 0 10 0 13 0 9 0 7 0 10 2 0 0 12 14 0 0 16 0 0 13 3 6 0 0 0 10 0 12 0 9 0 How's that? You've done all the hard work, but the OP wanted the full range of age values from 1:max and that pretty easy to do with one further step that adds entries fo the missing age levels: df3 - rbind(df2, data.frame(center=1,time=1, age=1:max(df2$age), n=0)) xtabs(n ~ center + age, data = df3) age center 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 0 0 0 0 0 10 0 13 0 9 0 7 0 10 2 0 0 0 0 0 0 12 14 0 0 16 0 0 13 3 0 0 0 0 6 0 0 0 10 0 12 0 9 0 -- David. Dennis On Sun, Sep 12, 2010 at 9:46 AM, Dennis Murphy djmu...@gmail.com wrote: Hi: Here's a made up example using the reshape function: Input data: df - structure(list(center = 1:3, age1 = c(6L, 7L, 5L), n1 = c(10L, 12L, 6L), age2 = c(8L, 8L, 8L), n2 = c(13L, 14L, NA), age3 = c(10L, 10L, 9L), n3 = c(9L, NA, 10L), age4 = c(12L, 11L, 11L), n4 = c(7L, 16L, 12L), age5 = c(14L, 14L, 13L), n5 = c(10L, 13L, 9L)), .Names = c(center, age1, n1, age2, n2, age3, n3, age4, n4, age5, n5), class = data.frame, row.names = c(NA, -3L)) df center age1 n1 age2 n2 age3 n3 age4 n4 age5 n5 1 16 108 13 10 9 12 7 14 10 2 27 128 14 10 NA 11 16 14 13 3 35 68 NA9 10 11 12 13 9 # To reshape more than one variable at a time, you need # to put the sets of variables into a list, as follows: df2 - reshape(df, idvar = 'center', varying = list(c(paste('age', 1:5, sep = '')), c(paste('n', 1:5, sep = ''))), v.names = c('age', 'n'), times = 1:5, direction = 'long') df2 center time age n 1.1 11 6 10 2.1 21 7 12 3.1 31 5 6 1.2 12 8 13 2.2 22 8 14 3.2 32 8 NA 1.3 13 10 9 2.3 23 10 NA 3.3 33 9 10 1.4 14 12 7 2.4 24 11 16 3.4 34 11 12 1.5 15 14 10 2.5 25 14 13 3.5 35 13 9 HTH, Dennis On Sun, Sep 12, 2010 at 7:45 AM, Natasha Asar natasha.asa...@yahoo.com wrote: Greeting R helpers J I am not familiar with R but I have to use it to analyze data set that I have (30,000 20,000) I want to change the structure of the dataset and I am wondering how that might be possible in R A main data looks like this: some entities are empty AgeNo. AgeNo. AgeNo. Center15 2 8 7 Center210 7 20 9 4 10 But what I want the data to look like is Age1 2 3 4 5 6 7 8 9 10 20 Center1 2 7 Center2 10 7 9 It should read the entities one by one when j is in age column take its value and consider it as the column number for new matrix then go to next entity (j No. columns) and put that entity under the columns number identified in previous step. In other word it should get the each element in No. columns (one by one) and place them in a new matrix under the column number which are equal to entity of age columns of first matrix i have tired ncol, and cbind and things like that but I guess im on the wrong path because it is not working. I am reading this fine with read.csv and writing back the same way. do you know how I can make this work?? Is it even possible to do something like this? Thank you in advance Natasha [[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
Re: [R] How to print matrices in standard format was ... Re: How to define new matrix based on an elementary row oper
On Sep 12, 2010, at 12:24 PM, David Winsemius wrote: On Sep 12, 2010, at 11:27 AM, Cuckovic Paik wrote: I appreciate all you help. This is only for instructional purpose: A = matrix(c(0,1,1,-2,-3,1,2,-1,0,2,2,4,1,-3,-2,1,-4,-7,-1,-19), ncol=5, byrow=T) B = matrix(sample(c(0,1,1,-2,-3,1,2,-1,0,2,2,4,1,-3,-2,1,-4,-7,-1,-19),), ncol=5, byrow=T) Which print func( A, B, A+B) can print the resulting matrices A and B and A+B in the following format? [,1] [,2] [,3] [,4] [,5] [,1] [,2] [,3] [,4] [, 5][,1] [,2] [,3] [,4] [,5] [1,]011 -2 -3 [1,] 2 -102 1[1,] 2 0 1 0-2 [2,]12 -102 + [2,] 1 -42 -2-2 =[2,] 2-2 1-2 0 [3,]241 -3 -2 [3,] -31 -71 -1[3,] -1 5-6-2-3 [4,]1 -4 -7 -1 -19 [4,] -304 -19 1[4,] -2-4-3 -20 -18 for( i in 1:nrow(A) ) { cat(sprintf(%4.0f, A[i, ]), paste( ,if( i==3 ){+}else{ }, , sep=),sprintf(%4.0f,B[i, ]), paste( ,if( i==3 ){=}else{ }, , sep=), sprintf(%4.0f, (A+B)[i, ]), \n )} for( i in 1:nrow(A) ) { cat(sprintf(%4.0f, A[i, ]), paste( ,if( i==3 ){+}else{ }, , sep=), sprintf(%4.0f,B[i, ]), paste( ,if( i==3 ){=}else{ }, , sep=), sprintf(%4.0f, (A+B)[i, ]), \n )} Even with the prettier printing it stilled seemed like a hack, so here is a grid graphics solution that gives prettier _output_: require(grid) grid.newpage() pushViewport(plotViewport(c(5,4,2,2))) # implicit limits are c(0,0,1,1) within plot area for (i in 1:nrow(A)) { for (j in 1:ncol(A)){grid.text(A[i,j], x=i/ 20, y=j/20)}} # plot mtx A for (i in 1:nrow(B)) { for (j in 1:ncol(B)){grid.text(B[i,j], x=(i +5)/20, y=j/20)}} # B for (i in 1:nrow(B)) { for (j in 1:ncol(B)){grid.text(A[i,j] +B[i,j], x=(i+10)/20, y=j/20)}} # A+B grid.text(=, x=10/20, y=2.5/20) grid.text(+, x=5/20, y=2.5/20) -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] using read.table, removing extra quotation mark from a text field? (e.g. cat )
True, I'd actually misread the problem as being ' and not . In the interest of expediency, here's one solution I can think off the top of my head: using MS-Word (dunno if it's taboo in these lists, but it's what I have at hand at the momentI believe in using all the tools available, if it will save time, which is most valuable): First, make a copy of your data and test it, to make sure Word will preserve proper formatting (when you do Save as, it gives you several options under formatting, from which to pick line breaks, etc.) First, do Replace All -- (Edit Menu -- Find -- Replace) Then, depending on whether the rows begin with | or | (that is, pipe, double quotes; or pipe, space, double quotes), you can do either: Replace All: |^p -- |^p Replace All: ^p -- ^p (note that the pipe has been replaced by a single whitespace) ^p stands for paragraph break in Word, so, it would essentially look for a single double quote followed by a Return, thereby ignoring single quotes that are followed by text. I just tested this, and it worked like a charm. Dennis: in theory, any text editor that supports regular expression should be able to do it. I'm fairly rusty on regex now (haven't used it in a while, I wish I could offer the exact command). Here are two free ones that do, if anyone wants to play around with regex: www.barebones.com/products/textwrangler/textwranglerpower.html (Textwrangler, OS X) sourceforge.net/apps/mediawiki/notepad-plus/index.php? title=Regular_Expressions (Notepad++, Windows) Cheers, hope it helps, Wil On Sep 12, 2010, at 6:27 PM, Dennis Murphy wrote: Hi: On Sun, Sep 12, 2010 at 1:05 PM, Wil M Contreras Arbaje wil.contre...@gmail.com wrote: While you are looking for a solution within R, it might be simpler to open your text file in almost any free text editor (Notepad++, Textwrangler, Smultron, vim come to mind), and do Replace all ' for . There's one problem with that solution: if the character string at the end of the line is blank (i.e., ), then your suggestion will leave one double quote at the end of a line. Not good. What is needed is a gsub that takes two double quotes plus a wild card character and replaces it with one double quote and a wild card character. If you have an editor that can do that, let me know...seriously. I suspect emacs can do this, but none of the basic editors I know have that capability. Dennis On Sep 12, 2010, at 3:58 PM, jim holtman wrote: You can use the 'gsub' command to remove the quote marks. You could readLines/writeLines the file to clean it up with gsub before using read.table on it so it can all be done within R. On Sun, Sep 12, 2010 at 1:58 PM, Eva Nordstrom eva.nordst...@yahoo.com wrote: I am using read.table to import a text file within R. There are several errors in my text file. An extra quotation mark has inadvertently been included within a few text fields. e.g. for a pipe (|) delimited text file, I have something similar to this: 1|7|30| dog 2|6|25| cat 3|4|20| 4|5| 56| mouse 5|3|56| horse 6|56| In the above example| there are extra quotation marks within the fields for cat and horse. (row 2 and row 5) e.g. cat , horse One solution is to simply edit the text file and remove the extra quotation mark. Is there a good solution I can implement form within R? I am OK with just importing the extra quotation marks and having nit show up as part of the text field within R. e.g, cat horse Thanks. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. [[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] CRAN (and crantastic) updates this week
CRAN (and crantastic) updates this week New packages * aratio (1.0) Maintainer: Daniel McMillen Author(s): Daniel McMillen http://crantastic.org/packages/aratio Tools for analyzing assessment ratios * DeducerPlugInScaling (0.0-5) Maintainer: Alberto Mirisola Author(s): Alberto Mirisola alberto.miris...@gmail.com http://crantastic.org/packages/DeducerPlugInScaling A Deducer plugin for factor analysis and reliability analysis, using psych, GPArotation and mvnormtest packages. * IMIS (0.0) Maintainer: Le Bao Author(s): Adrian Raftery, Le Bao http://crantastic.org/packages/IMIS IMIS algorithm draws samples from the posterior distribution. The user has to define the following R functions in advance: prior(x) calculates prior density of x, likelihood(x) calculates the likelihood of x, and sample.prior(n) draws n samples from the prior distribution. * OrgMassSpecR (0.2-2) Maintainer: Nathan Dodder Author(s): Nathan G. Dodder, Southern California Coastal Water Research Project (SCCWRP). Contributions from Katharine M. Mullen. http://crantastic.org/packages/OrgMassSpecR Functions related to instrument operation and data analysis. * RNiftyReg (0.2.0) Maintainer: Jon Clayden Author(s): Jon Clayden; based on original code by Marc Modat and Pankaj Daga http://crantastic.org/packages/RNiftyReg This package provides an R interface to the NiftyReg image registration tools lt;http://sourceforge.net/projects/niftyreg/gt;. * RWekajars (3.7.1-1) Maintainer: Kurt Hornik Author(s): Kurt Hornik http://crantastic.org/packages/RWekajars External jars required for package RWeka. * SE.IGE (1.0) Maintainer: Unknown Author(s): Piter Bijma http://crantastic.org/packages/SE-IGE Predicts standard errors of estimated genetic parameters for IGE Updated packages BAS (0.91), Bchron (3.1.1), Bergm (1.4), CORElearn (0.9.29), FitAR (1.86), FrF2 (1.1-5), GPseq (0.3), Hmisc (3.8-3), IBrokers (0.2-8), JM (0.7-0), JOP (1.0.5), MetabolAnalyze (1.2), Metabonomic (3.4), MuMIn (0.13.14), NCBI2R (1.3.2), NCBI2R (1.3.1), Rcpp (0.8.6), RNiftyReg (0.2.0), ROracleUI (1.2-0), RProtoBuf (0.2.0), Rsolnp (1.0-5), RWeka (0.4-2), SIS (0.6), TSAgg (0.2-1), WGCNA (0.94) This email provided as a service for the R community by http://crantastic.org. Like it? Hate it? Please let us know: crana...@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.
Re: [R] How to print matrices in standard format was ... Re: How to define new matrix based on an elementary row oper
Thanks David. grid graphic works pretty well. -- View this message in context: http://r.789695.n4.nabble.com/How-to-define-new-matrix-based-on-an-elementary-row-operation-in-a-single-step-tp2341768p2536785.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] average matrices across a list
My next suggestion (I don't have time to work out or test an example at the moment): library(abind) tmparr - abind(m1,m2,m3,...,along=3) OR tmparr - do.call(c(matlist,list(along=3))) apply(tmparr,c(1,2),mean,na.rm=TRUE) or something along those lines. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Problem with all.equal and POSIXt.
I'm getting an error when applying all.equal() to objects of class POSIXt. E.g. x - strptime(rep(2007-02-12,10),format=%Y-%m-%d) all.equal(x,x) Error in target[[i]] : subscript out of bounds The object seems to have to be of double-digit length to trigger the error. E.g. all.equal(x[1:9],x[1:9]) returns TRUE. I did a cursory search of the r-help pages and found no reference to this problem. Is this a bug, or am I missing something? cheers, Rolf Turner P. S.: sessionInfo() R version 2.11.1 (2010-05-31) x86_64-apple-darwin9.8.0 locale: [1] en_NZ.UTF-8/en_NZ.UTF-8/C/C/en_NZ.UTF-8/en_NZ.UTF-8 attached base packages: [1] datasets utils stats graphics grDevices methods base other attached packages: [1] misc_0.0-12fortunes_1.3-7 MASS_7.3-6 loaded via a namespace (and not attached): [1] tools_2.11.1 ## Attention:\ This e-mail message is privileged and confid...{{dropped:9}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] average matrices across a list
Hi Everyone, Thanks to everyone for their help. With your suggestions and some poking around, the following works for what I need. It basically adds all the matrices elementwise, and adds nothing if the element is NA. Thanks again! Code below: ** mymats - vector('list', 5) set.seed(246) # Generate a list of five 3 x 3 matrices for(i in 1:5) mymats[[i]] - matrix(sample(1:9), nrow = 3) mymats[[5]][1,1]-NA mymats[[4]][2,2]-NA mymats matrixadder-function(u,v){ na.u-is.na(u) na.v-is.na(v) ifelse(na.u na.v, NA, ifelse(na.u, 0, u)+ ifelse(na.v,0,v)) } Reduce('matrixadder',mymats) ** Cheers, Greg On Sep 12, 2010, at 8:33 PM, Ben Bolker wrote: My next suggestion (I don't have time to work out or test an example at the moment): library(abind) tmparr - abind(m1,m2,m3,...,along=3) OR tmparr - do.call(c(matlist,list(along=3))) apply(tmparr,c(1,2),mean,na.rm=TRUE) or something along those lines. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] using read.table, removing extra quotation mark from a text field? (e.g. cat )
Hi: Thanks to Jakson Aquino, who showed me how to do a proper text substitution, we have a way out. It also turns out that in the last line, the last numeric field was missing, so I inserted an NA| in the last line of the data file before calling readLines(). His (correct) code is at the bottom of the mail. The first two lines of code below are courtesy of Jakson. Afterward, I tried to shape the result into a data frame for export as a flat file. There's an interesting lesson to be (re)learned in the process, so bear with me. Input file file1.txt (revised): 1|7|30| dog 2|6|25| cat 3|4|20| 4|5| 56| mouse 5|3|56| horse 6|56|NA| x - readLines(file1.txt) y - sub('(.)', '\\1', x) d - do.call(rbind, strsplit(y, split = '\\|')) d - as.data.frame(d) d V1 V2 V3 V4 1 1 7 30dog 2 2 6 25cat 3 3 4 20 4 4 5 56 mouse 5 5 3 56 horse 6 6 56 NA str(d) 'data.frame': 6 obs. of 4 variables: $ V1: Factor w/ 6 levels 1,2,3,4,..: 1 2 3 4 5 6 $ V2: Factor w/ 6 levels 3,4,5,56,..: 6 5 2 3 1 4 $ V3: Factor w/ 6 levels 56,20,25,..: 4 3 2 1 5 6 $ V4: Factor w/ 6 levels \\, \cat\,..: 3 2 6 5 4 1 Everything is a factor, as it should be since we converted a character matrix into a data frame. Now convert the factors to numeric and character and write out to a file. d$V1 - as.numeric(d$V1) d$V2 - as.numeric(d$V2) d$V3 - as.numeric(d$V3) d$V4 - as.character(d$V4) d V1 V2 V3 V4 1 1 6 4dog 2 2 5 3cat 3 3 2 2 4 4 3 1 mouse 5 5 1 5 horse 6 6 4 6 Oopsie. We got the numeric factor codes back in V2 and V3. The FAQ 7.10 trap... # Back to the drawing board. d - do.call(rbind, strsplit(y, split = '\\|')) d - as.data.frame(d) d1 - d d1$V1 - as.numeric(as.character(d1$V1)) d1$V2 - as.numeric(as.character(d1$V2)) d1$V3 - as.numeric(as.character(d1$V3)) d1$V4 - as.character(as.character(d1$V4)) d1 V1 V2 V3 V4 1 1 7 30dog 2 2 6 25cat 3 3 4 20 4 4 5 56 mouse 5 5 3 56 horse 6 6 56 NA Much better. Let's double check that we're OK. str(d1) 'data.frame': 6 obs. of 4 variables: $ V1: num 1 2 3 4 5 6 $ V2: num 7 6 4 5 3 56 $ V3: num 30 25 20 56 56 NA $ V4: chr \dog\ \cat\ \\ \mouse\ ... # NOW write it out... write.table(d1, file = 'file3.dat', quote = FALSE) # looks good And that's why FAQ 7.10 is written the way it is. If one is happy with y (just the paired double quotes removed), then Jakson's final line is sufficient: writeLines(y, file2.txt) Dennis On Sun, Sep 12, 2010 at 5:05 PM, Jakson A. Aquino jaksonaqu...@gmail.comwrote: On Sun, Sep 12, 2010 at 7:27 PM, Dennis Murphy djmu...@gmail.com wrote: Hi: On Sun, Sep 12, 2010 at 1:05 PM, Wil M Contreras Arbaje wil.contre...@gmail.com wrote: While you are looking for a solution within R, it might be simpler to open your text file in almost any free text editor (Notepad++, Textwrangler, Smultron, vim come to mind), and do Replace all ' for . There's one problem with that solution: if the character string at the end of the line is blank (i.e., ), then your suggestion will leave one double quote at the end of a line. Not good. What is needed is a gsub that takes two double quotes plus a wild card character and replaces it with one double quote and a wild card character. If you have an editor that can do that, let me know...seriously. I suspect emacs can do this, but none of the basic editors I know have that capability. Dennis On Sep 12, 2010, at 3:58 PM, jim holtman wrote: You can use the 'gsub' command to remove the quote marks. You could readLines/writeLines the file to clean it up with gsub before using read.table on it so it can all be done within R. On Sun, Sep 12, 2010 at 1:58 PM, Eva Nordstrom eva.nordst...@yahoo.com wrote: I am using read.table to import a text file within R. There are several errors in my text file. An extra quotation mark has inadvertently been included within a few text fields. e.g. for a pipe (|) delimited text file, I have something similar to this: 1|7|30| dog 2|6|25| cat 3|4|20| 4|5| 56| mouse 5|3|56| horse 6|56| x - readLines(file1.txt) y - sub('(.)', '\\1', x) writeLines(y, file2.txt) [[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] How to do a trig regression
Hello All, I cant seem to do a trig regression in R. The equation is as follows : y = a+b*(sin((2*pi*x/360) - c))^2 a, b, c are coefs that I want. y, x are input vectors. The equation I put into R: lm(y ~ sin(2*pi*x/360)^2) This equation is missing the c and I dont get the right answer. Also, I dont know how to plot the lm over the x values instead of the indices. Any help is sincerely appreciated. Thank you all very much. -- Aaditya Nanduri aaditya.nand...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with all.equal and POSIXt.
I get the same error. On debugging, after the 10th iteration (~1,375 lines after the all.equal(x, x) call), I get: exiting from: all.equal(target[[i]], current[[i]], check.attributes = check.attributes, ...) debugging in: all.equal(target[[i]], current[[i]], check.attributes = check.attributes, ...) debug: UseMethod(all.equal) Browse[4] ls() # so it shows current and target, but... [1] current target Browse[4] current # when I try to look at it Error in current[[i]] : subscript out of bounds Browse[4] target Error in target[[i]] : subscript out of bounds Browse[4] getAnywhere(current) no object named 'current' was found Browse[4] environment() environment: 0x06037088 Browse[4] exists(current) Error in current[[i]] : subscript out of bounds In addition: Warning message: In exists(current) : restarting interrupted promise evaluation Which is utterly out of my league, but perhaps useful to others. At the least, this seems an odd error message to give if all.equal() cannot handle that type of object. My system: R version 2.11.1 (2010-05-31) x86_64-pc-mingw32 locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] grid_2.11.1 tools_2.11.1 Josh On Sun, Sep 12, 2010 at 6:28 PM, Rolf Turner r.tur...@auckland.ac.nz wrote: I'm getting an error when applying all.equal() to objects of class POSIXt. E.g. x - strptime(rep(2007-02-12,10),format=%Y-%m-%d) all.equal(x,x) Error in target[[i]] : subscript out of bounds The object seems to have to be of double-digit length to trigger the error. E.g. all.equal(x[1:9],x[1:9]) returns TRUE. I did a cursory search of the r-help pages and found no reference to this problem. Is this a bug, or am I missing something? cheers, Rolf Turner P. S.: sessionInfo() R version 2.11.1 (2010-05-31) x86_64-apple-darwin9.8.0 locale: [1] en_NZ.UTF-8/en_NZ.UTF-8/C/C/en_NZ.UTF-8/en_NZ.UTF-8 attached base packages: [1] datasets utils stats graphics grDevices methods base other attached packages: [1] misc_0.0-12 fortunes_1.3-7 MASS_7.3-6 loaded via a namespace (and not attached): [1] tools_2.11.1 ## Attention:\ This e-mail message is privileged and confid...{{dropped:9}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with all.equal and POSIXt.
On 2010-09-12 20:32, Joshua Wiley wrote: I get the same error. On debugging, after the 10th iteration (~1,375 lines after the all.equal(x, x) call), I get: exiting from: all.equal(target[[i]], current[[i]], check.attributes = check.attributes, ...) debugging in: all.equal(target[[i]], current[[i]], check.attributes = check.attributes, ...) debug: UseMethod(all.equal) Browse[4] ls() # so it shows current and target, but... [1] current target Browse[4] current # when I try to look at it Error in current[[i]] : subscript out of bounds Browse[4] target Error in target[[i]] : subscript out of bounds Browse[4] getAnywhere(current) no object named 'current' was found Browse[4] environment() environment: 0x06037088 Browse[4] exists(current) Error in current[[i]] : subscript out of bounds In addition: Warning message: In exists(current) : restarting interrupted promise evaluation Which is utterly out of my league, but perhaps useful to others. At the least, this seems an odd error message to give if all.equal() cannot handle that type of object. The 'problem' is with the structure of the POSIXlt object. Try this: x[[4]] # ok x[[9]] # ok x[[10]] # subcript out of bounds attributes(x) Note that the 'names' attribute has 9 components which are displayed by x[[i]]. all.equal(x,x) calls all.equal.list(x,x) which compares target[[i]] to current[[i]]. The problem is that it's natural to assume that target[[i]] refers to the ith element of x when in fact it refers to the ith name (e.g. weekday for i==7) for all elements of x. Since there are only 9 components in attr(x, 'name'), we run out of subscripts when we look for the 10th component. I'm not sure that I would call this a bug, but it would seem helpful to return an appropriate error message or to coerce to POSIXct. Note that all.equal(as.POSIXct(x), as.POSIXct(x)) yields TRUE, as does using as.Date(x). -Peter Ehlers My system: R version 2.11.1 (2010-05-31) x86_64-pc-mingw32 locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] grid_2.11.1 tools_2.11.1 Josh On Sun, Sep 12, 2010 at 6:28 PM, Rolf Turnerr.tur...@auckland.ac.nz wrote: I'm getting an error when applying all.equal() to objects of class POSIXt. E.g. x- strptime(rep(2007-02-12,10),format=%Y-%m-%d) all.equal(x,x) Error in target[[i]] : subscript out of bounds The object seems to have to be of double-digit length to trigger the error. E.g. all.equal(x[1:9],x[1:9]) returns TRUE. I did a cursory search of the r-help pages and found no reference to this problem. Is this a bug, or am I missing something? cheers, Rolf Turner P. S.: sessionInfo() R version 2.11.1 (2010-05-31) x86_64-apple-darwin9.8.0 locale: [1] en_NZ.UTF-8/en_NZ.UTF-8/C/C/en_NZ.UTF-8/en_NZ.UTF-8 attached base packages: [1] datasets utils stats graphics grDevices methods base other attached packages: [1] misc_0.0-12fortunes_1.3-7 MASS_7.3-6 loaded via a namespace (and not attached): [1] tools_2.11.1 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 all.equal and POSIXt.
On 13/09/2010, at 3:07 PM, Peter Ehlers wrote: SNIP I'm not sure that I would call this a bug, but it would seem helpful to return an appropriate error message or to coerce to POSIXct. Note that all.equal(as.POSIXct(x), as.POSIXct(x)) yields TRUE, as does using as.Date(x). Well, I ***would*** call it a bug. The all.equal() function is confusing the length of x as a POSIXlt object (i.e. the length of its list components) with the length of the (well hidden) list structure of x (i.e. 9). This is the wrong thing to do, so it's a bug. I notice that there is an all.equal.POSIXct() method. Maybe there should also be an as.equal.POSIXlt() method --- which would just coerce its argument to POSIXct, and then do NextMethod(). But maybe there's a Good Reason why R Core did not implement an as.equal.POSIXlt() method --- i.e. it's dangerous to apply all.equa1() to POSIXlt objects. Can't think why this should be, but. cheers, Rolf ## Attention: This e-mail message is privileged and confidential. If you are not the intended recipient please delete the message and notify the sender. Any views or opinions presented are solely those of the author. This e-mail has been scanned and cleared by MailMarshal www.marshalsoftware.com ## __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to do a trig regression
On Sep 12, 2010, at 10:23 PM, Aaditya Nanduri wrote: Hello All, I cant seem to do a trig regression in R. The equation is as follows : y = a+b*(sin((2*pi*x/360) - c))^2 a, b, c are coefs that I want. y, x are input vectors. The equation I put into R: lm(y ~ sin(2*pi*x/360)^2) This equation is missing the c and I dont get the right answer. Take a look at section 2.3 of: http://www.statoek.wiso.uni-goettingen.de/veranstaltungen/zeitreihen/sommer03/ts_r_intro.pdf Or consider using time series or nonlinear modeling. Also, I dont know how to plot the lm over the x values instead of the indices. Without an example of your data and what you tried it is difficult to intuit what problems you may be facing. -- David. Any help is sincerely appreciated. Thank you all very much. -- Aaditya Nanduri aaditya.nand...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Overlay of two graphs of different axes
Though I have read quite a bit, and tried quite a bit, I have yet to find a nice way to overlay 2 or more curves in the same plot, with different ranges. Here is simplified sample code to demonstrate the question: plot(2*(seq(1,5)), type=l, axes=FALSE) curve(2*(seq(1,5)), type=b, add=TRUE) Error in curve(2 * (seq(1, 5)), type = b, add = TRUE) : 'expr' must be a function or an expression containing 'x' axis(2) curve(x^2, 1, 5, type=b, add=TRUE) axis(4) Firstly, as an aside, I am not clear why 'curve' has a different syntax compared to 'plot'. As a still beginner, I'd for one would be happy to add curves to a plot; curves of just different parameters. Though, I guess, there must be a good reason? Mostly, however, I wonder how to plot a number of curves into an original plot, that re-defines the min/max from the most recent curve. In the example that I constructed, axis(2) does exactly the expected thing. What I want to do next, though, with the least effort, is to add another function in a manner that the added function is scaled, not according to the first function (plot), but to fit into the plotting area. (The example above overshoots the range). Plus, how can I subsequently add the axis suitable to the most recent function? That is, how can I render axis(4) to displaying the scale for the second graph, created with 'curve'? Thanks in advance, Uwe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.