Re: [R] R: R: R: how to split and handle a big R program into multiple files
May I suggest you join R-forge when your package has taken shape? It'll allow you to easily check the building of the package on all platforms and you'll be able to submit to CRAN in one click when it's good enough. baptiste On 23 Apr 2009, at 13:58, mau...@alice.it wrote: Submitting to CRAN is one of my goals. What we are implementing is not done yet either in R or MatLab. There exists some Fortran applications of the algorithms we are implementing for general use. it'll still take me some time before I get there. Maura -Messaggio originale- Da: Duncan Murdoch [mailto:murd...@stats.uwo.ca] Inviato: gio 23/04/2009 14.21 A: mau...@alice.it Cc: baptiste auguie; r-help Help Oggetto: Re: [R] R: R: how to split and handle a big R program into multiple files On 4/23/2009 7:15 AM, mau...@alice.it wrote: I read the on-line documentation. What I am still missing is how I run my program after encapsulating it in a package. I will have to load the package ... just guessing If I had a large program that I needed to run just once, e.g. an analysis or simulations for a paper, here's how I would organize it: - Identify all the general purpose functions and put them in a package. - The one-off parts of the code don't really belong as functions in a package, though there's nothing to stop you from doing that. I'd probably put them into a vignette, or just write the whole paper in Sweave, which is almost the same thing. If your general purpose functions do something new that would be useful to others, you might want to polish up the package and send it to CRAN (and perhaps submit it with a supporting paper to JSS). But that's not necessary: a package is a good way to organize code for your own use too. Duncan Murdoch Thank you maura -Messaggio originale- Da: baptiste auguie [mailto:ba...@exeter.ac.uk] Inviato: gio 23/04/2009 12.17 A: mau...@alice.it Cc: r-help Help Oggetto: Re: R: [R] how to split and handle a big R program into multiple files It is an R command (package utils), see ?package.skeleton baptiste On 23 Apr 2009, at 10:51, mau...@alice.it wrote: Is that an R command ? I browswd for the on-line hlp about such a command but could not find it. Thank you. maura -Messaggio originale- Da: baptiste auguie [mailto:ba...@exeter.ac.uk] Inviato: gio 23/04/2009 11.48 A: mau...@alice.it Cc: r-help Help Oggetto: Re: [R] how to split and handle a big R program into multiple files If most of the functions are quite stable (you don't change them too often), you could also consider creating a R package with package.skeleton. baptiste On 23 Apr 2009, at 10:39, jgar...@ija.csic.es wrote: source() and the use of functions ... Javier --- I am working on a program totally written in R which is now getting bigger and bigger so that editling the only file that contains all the functions is becoming more and more unmanageable. I wonder whether it is possible to spread the R code, making up the same program, in a number of smaller files and then call them all, in the right order, through a list of something like the C language include directive. Any other suggestion how to organize, handle, and maintain a big R program is welcome. Thank you in advance, Maura tutti i telefonini TIM! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ Alice Messenger ;-) chatti anche con gli amici di Windows Live Messenger e tutti i telefonini TIM! er _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ tutti i telefonini TIM! [[alternative HTML version deleted]] __ R-help@r-project.org
Re: [R] plot() - thicker points when pair exist more than 1 time?
on suitable devices, you could consider transparency, plot(f,col=alpha(grey,0.8),pch=19) baptiste On 24 Apr 2009, at 14:09, Knut Krueger wrote: f- data.frame(x=c(1,3,5,6,1),y=c(1,2,3,4,1)) plot(f) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Conditional plot labels
Hi, Have you considered using high-level plotting functions provided by the ggplot2 or lattice package? Here's a dummy example, x - seq(0, 10, length=100) y1 - sin(x) y2 - cos(x) y3 - x^2/100 y4 - 1/x d - data.frame(x, y1, y2, y3, y4) library(reshape) dm - melt(d, id=x) dm$type1 - rep(LETTERS[1:2], each=2*length(x)) # dummy factors dm$type2 - rep(letters[1:2], each=length(x)) library(ggplot2) p1 - qplot(x, value, data=dm, geom=line, facets=type1~type2) p1 # you can customise the appearance if the default doesn't please you library(lattice) p2 - xyplot(value~x|type1*type2, data=dm, t=l) # here the strips are on top of each other by default library(latticeExtra) useOuterStrips(p2) # this makes the layout more like you want Alternatively, you can also use raw Grid commands and define your own layout where to place the different graphical objects, but it's more work. Hope this helps, baptiste On 26 Apr 2009, at 01:31, Christian Bustamante wrote: Hi all, I'm trying to do multiple graphs in a window like this: ___ ___ ___ ylab |__| |__| |__| ___ ___ ___ ylab |__| |__| |__| ___ ___ ___ ylab |__| |__| |__| xl xl xl If I try to put the labels manually, some graphs become smaller than other and the output is really ugly. In the thread title I put the word conditional because I'm trying to do a function, and in that function I want to print ylabels if the plot positions is at first column of the graph matrix, and xlab if the position is at last row of matrix. How can i achive this two things? Thanks for your help -- CdeB __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Scatterplot of two groups side-by-side?
Hi, You could do this very easily using ggplot2, #install.packages(ggplot2, dep=TRUE) library(ggplot2) c - ggplot(mtcars, aes(y=wt, x=mpg)) + facet_grid(. ~ cyl) c + stat_smooth(method=lm) + geom_point() See more examples on Hadley's website: http://had.co.nz/ggplot2/ Hope this helps, baptiste On 26 Apr 2009, at 10:29, nonu...@yahoo.de wrote: Dear all I'm realy new to R, so I hope you can help me, as I didn't find any solution in the common books. Since some days I'm trying to create the following plot: A scatterplott showning two different groups side-by-side with according regression lines. Both datasets only have the same five factors, so the scatters will form a kind of column at each factor. When I use scatterplot (package car), then I can plot two groups in the same graph by using the command groups, but the scatters of both groups are then plotted on top of eachother using different symbols and they can hardly be distingushed. How can I plot them side by side, so that the groups do not overlap? And how can I give different colours to the groups and the according regression line? (This is, what I got so far: http://img7.imageshack.us/img7/227/almostgood.jpg) I tried to use the commands used in boxplot, to solve this problem. In this commant, it's possible to plot different datasets side-by-side by defining the position of the bars (example: at = 1:5 - 0.4). A second boxplot-chart can then be added by adding the command add=TRUE to the line and defining another position. Both commands don't function within the scatterplot-command. By the way: It's realy necessary to plott the data as scatters and not as boxplots. With the command plot, I can not plot the data by groups (I tried it with the commands subset and groups, but obviously, there is no way to do so). I'm greatful for every (simple) solution Thanks in advance Karin Schneeberger MSc-student University of Berne Switzerland [[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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] comparing matrices
I'm not sure I'm following you but have you tried, identical(matrix(c(1,1,1,1),ncol=2), matrix(c(1,1,1,1),ncol=2)) ?all.equal ?isTRUE ?identical and possibly the compare package, compare(matrix(c(1,1,1,1),ncol=2),matrix(c(1,1,1,1),ncol=2)) HTH, baptiste On 26 Apr 2009, at 18:02, Esmail wrote: I'm trying to compare two matrices made up of bits. doing a simple comparison of matA == matB yields this sort of output. [,1] [,2] [,3] [,4] [,5] [,6] [1,] FALSE TRUE FALSE TRUE TRUE FALSE [2,] TRUE TRUE TRUE TRUE TRUE TRUE [3,] FALSE TRUE FALSE FALSE FALSE TRUE [4,] FALSE TRUE TRUE FALSE FALSE FALSE [5,] TRUE TRUE TRUE TRUE FALSE FALSE [6,] TRUE TRUE TRUE TRUE FALSE FALSE I really would like just one comprehensive value to say TRUE or FALSE. This is the hack (rather ugly I think) I put together that works, but there has to be a nicer way, no? res=pop[1:ROWS,] == keep[1:ROWS,] if ((ROWS*COL) == sum(res)) { cat('they are equal\n') }else cat('they are NOT equal\n') Thanks! Esmail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Formatting numbers
sprintf(%04.f, 2) sapply(sample(1:1000,4), function(ii) sprintf(%04.f,ii)) ?sprintf HTH, baptiste On 27 Apr 2009, at 11:35, Mario dos Reis wrote: I've been trough the R documentation for about half an hour and it's not clear to me how to do this: I need to format to character a series of integers from 1 to 1000, and I like them to look like 0001 0002, 0059, 0123 and so on. Padded with zeroes to have four digits. Cheers! Mario. r-help-requ...@r-project.org wrote: Send R-help mailing list submissions to r-help@r-project.org To subscribe or unsubscribe via the World Wide Web, visit https://stat.ethz.ch/mailman/listinfo/r-help or, via email, send a message with subject or body 'help' to r-help-requ...@r-project.org You can reach the person managing the list at r-help-ow...@r-project.org When replying, please edit your Subject line so it is more specific than Re: Contents of R-help digest... Today's Topics: 1. Re: Changing gird marks in ggplot2 (ONKELINX, Thierry) 2. Re: argument 'exclude' in function xtabs (Matthieu Lesnoff) 3. Question of Quantile Regression for Longitudinal Data (Helen Chen) 4. Conditional plot labels (Christian Bustamante) 5. simulate arima model (Rebecca1117) 6. THE EQUIVALENT OF SQL INNER TABLE JOIN IN R (Nigel Birney) 7. Scatterplot of two groups side-by-side? (nonu...@yahoo.de) 8. Re: Nomogram with stratified cph in Design package (reneepark) 9. Stochastic Gradient Ascent for logistic regression (Tim LIU) 10. Re: Question of Quantile Regression for Longitudinal Data (Tirthankar Chakravarty) 11. Re: THE EQUIVALENT OF SQL INNER TABLE JOIN IN R (Gabor Grothendieck) 12. Re: THE EQUIVALENT OF SQL INNER TABLE JOIN IN R (Peter Dalgaard) 13. Re: 3 questions regarding matrix copy/shuffle/compares (Esmail) 14. Re: Conditional plot labels (baptiste auguie) 15. Re: Scatterplot of two groups side-by-side? (baptiste auguie) 16. Help to select the raw in a data.frame with the max value (Alessandro) 17. re moving entries from one vector that are in another (onyourmark) 18. Is their any function can generate orthogonal tables(e.g. L_8(2^7) (dzuswxbylw) 19. Re: dotplot: labeling coordinates for each point (Qifei Zhu) 20. Re: Help to select the raw in a data.frame with the max value (Jorge Ivan Velez) 21. Re: Nomogram with stratified cph in Design package (Frank E Harrell Jr) 22. Problem installing packages (Jarek Jasiewicz) 23. Re: 3 questions regarding matrix copy/shuffle/compares (David Winsemius) 24. Re: issue building my own package... moving from Apple OS to Windows (Uwe Ligges) 25. Re: Scatterplot of two groups side-by-side? (Stefan Grosse) 26. Re: 3 questions regarding matrix copy/shuffle/compares (Esmail) 27. R: constrained optimization (mau...@alice.it) 28. Re: Help to select the raw in a data.frame with the max value (David Winsemius) 29. Re: Scatterplot of two groups side-by-side? (John Fox) 30. Re: Problem installing packages (Uwe Ligges) 31. Re: fclustindex, e1071 package (Uwe Ligges) 32. Re: Overlapping parameters k in different functions in ipred (Uwe Ligges) 33. Re: How to get rid of loop? (Uwe Ligges) 34. Re: help with plotting results of lda (Uwe Ligges) 35. Re: Problem installing packages (Jarek Jasiewicz) 36. Re: 3 questions regarding matrix copy/shuffle/compares (David Winsemius) 37. Re: Problem installing packages (Jarek Jasiewicz) 38. Memory issues in R (Neotropical bat risk assessments) 39. Re: 3 questions regarding matrix copy/shuffle/compares (hadley wickham) 40. Re: 3 questions regarding matrix copy/shuffle/compares (David Winsemius) 41. Re: 3 questions regarding matrix copy/shuffle/compares (Esmail) 42. Re: 3 questions regarding matrix copy/shuffle/compares (hadley wickham) 43. Re: 3 questions regarding matrix copy/shuffle/compares (Esmail) 44. Re: 3 questions regarding matrix copy/shuffle/compares (Esmail) 45. Re: Stochastic Gradient Ascent for logistic regression (Ravi Varadhan) 46. Re: Problem installing packages (Uwe Ligges) 47. Re: Memory issues in R (David Winsemius) 48. Re: Memory issues in R (Stefan Grosse) 49. Matching in R (dirk...@gmx.de) 50. Re: help with plotting results of lda (Prof Brian Ripley) 51. Install packages not working in latest version? (Neotropical bat risk assessments) 52. Re: Install packages not working in latest version? (Uwe Ligges) 53. comparing matrices (Esmail) 54. doubt in vglm output (priyabrata panigrahi) 55. figure layout (hesicaia) 56. Re: ANOVA/statistics question (drmh) 57. Re: comparing matrices (ONKELINX, Thierry) 58. Problem with create a tree (Grze?) 59. Re: THE EQUIVALENT OF SQL INNER TABLE JOIN IN R (Wacek Kusnierczyk) 60. Re: Memory issues in R (David Winsemius) 61. Re: comparing matrices (baptiste auguie) 62. Re: Problem installing packages (Jarek Jasiewicz) 63. Re: comparing matrices (David Winsemius) 64. Re
Re: [R] plyr package: passing further arguments fail
Thanks Hadley, for some reason I didn't see your email until now. It works fine with the development version, library(plyr) df - data.frame(a=1:10 , b=1:10) foo1 - function(a, b, cc=0, d=0){ a + b + cc + d } mdply(data. = df, foo1, cc=1, d=2) I think using . prefixes is a safer option (and possibly more consistent with R customs), although that means the current code using plyr will have to be modified. Congratulations on the new ggplot2 release too! Thanks, baptiste On 5 Oct 2008, at 14:39, hadley wickham wrote: On Sun, Oct 5, 2008 at 8:02 AM, Auguie, Baptiste [EMAIL PROTECTED] wrote: Dear list and Hadley, The new plyr package seems to provide a clean and consistent way to apply a function on several arguments. However, I don't understand why the following example does not work like the standard mapply, library(plyr) df - data.frame(a=1:10 , b=1:10) foo1 - function(a, b, cc=0, d=0){ a + b + cc + d } mdply(df, foo1, cc=1) # fine mdply(df, foo1, d=1) # fails mdply(df, foo1, cc=1, d=2) # fails Unfortunately this bug is R's partial name matching: d = 2 - data. = 2. You should be able to fix this by manually specifying mdply(data. = df, foo1, cc=1, d=2) but there are some bugs in the current version that prevent this from happening. I've fixed this in the development version, available from http://github.com/hadley/plyr (click the download link) However, the whole point of plyr is that you should have to think about this kind of thing, so I'll revisit my naming scheme - probably to use . prefixes instead of suffixes. Hadley -- http://had.co.nz/ _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] panel.groups: use group.number to define colors
Dear list, I've been trying this for a few hours and I just don't understand how lattice works with groups and subscripts. Consider the following example, xx - seq(1, 10, length=100) x - rep(xx, 4) y - c(cos(xx), sin(xx), xx, xx^2/10) fact - factor(rep(c(cos, sin, id, square), each=100)) fact2 - factor(rep(c(periodic, not periodic), each=100)) my.df - data.frame(x=x, y=y, fact = fact, fact2 = fact2) head(my.df) myColors - c(2, 4) xyplot(y ~ x | fact, data = my.df, groups = fact2, panel = panel.superpose, panel.groups = function(..., group.number) { panel.xyplot(...) #panel.xyplot( ..., col=myColors[group.number]) # error }) My aim is to assign a custom color to each group, but for some reason the col parameter is already given to panel.xyplot and I can't find where it gets the values from. Many thanks, baptiste _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] panel.groups: use group.number to define colors
Hi, and thanks for your email, I realise my example was not very good. The actual dataset I'm trying to plot is rather big and this oversimplified example did not make much sense. I actually do need to color different subsets of the data differently in each panel, that's why I thought of using panel.groups. Here's a more realistic example: x - seq(1, 2*pi, length=100) numberOfCurves - 20 y1 - sapply(seq(0, pi/2, length=numberOfCurves), function(phi) sin(x +phi)) y2 - sapply(seq(0, pi/2, length=numberOfCurves), function(phi) cos(x +phi)) y - cbind(y1, y2) fact - factor(rep(c(cos, sin), each=numberOfCurves*100)) fact2 - factor(rep(seq(0, pi, length=numberOfCurves), each=100, length=2*numberOfCurves*100)) my.df - data.frame(x=rep(x, length=800), y=as.vector(y), fact = fact, fact2 = fact2) head(my.df) myColors - c(grey, grey, red, rep(grey, ncol(y)-3)) xyplot(y ~ x | fact, data = my.df, groups = fact2, type=l, par.settings=list(superpose.line=list(col=myColors, lwd=2)), panel = panel.superpose, panel.groups = function(..., group.number) { panel.xyplot(...) }) Two things I don't like about my approach: - I'd rather select the colors in the panel function than set a specific palette in par.settings, as it's not obvious to me what the order of the plotting will be. This is where I fail to use group.number correctly - the purpose of the red line is make this particular curve stand out from the mess of grey curves. However, they partially cover it and I don't really know how to change the plotting order (or replot the red one only on top if it's any easier) Hope this is a bit clearer, Best regards, baptiste On 7 Oct 2008, at 18:25, Bert Gunter wrote: Not exactly sure what you want to do, but ... In your example, you do not need groups, since the color doesn't change within the levels of the conditioning variable (fact). Hence you can use the panel.number() function to choose the plotting color of each panel, like this: ## .. continuing with your example myColors - rep(c(2,4),2) xyplot(y ~ x | fact, data = my.df, panel = function(...){ panel.xyplot(...,col=myColors[panel.number()]) } ) If you actually **need** groups (to color different subsets of the data within a panel differently). it does get a bit more complicated. Incidentally, note that col is already a formal argument of panel.superpose and was therefore picked up in the ... argument of the panel.groups function -- that's why you got the error you did when you repeated col explicitly in the panel.xyplot call. By default, it's values are those of trellis.par.get(superpose.symbol) I believe. Also, group.number appears to be undefined in your code. HTH Cheers, Bert Gunter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] panel.groups: use group.number to define colors
Many thanks, I think I got the spirit of 'capturing and overriding' the arguments which was the bit i was missing. It's much clearer now with a working example. Thanks again, baptiste On 7 Oct 2008, at 21:19, Deepayan Sarkar wrote: On Tue, Oct 7, 2008 at 8:54 AM, baptiste auguie [EMAIL PROTECTED] wrote: Dear list, I've been trying this for a few hours and I just don't understand how lattice works with groups and subscripts. Consider the following example, xx - seq(1, 10, length=100) x - rep(xx, 4) y - c(cos(xx), sin(xx), xx, xx^2/10) fact - factor(rep(c(cos, sin, id, square), each=100)) fact2 - factor(rep(c(periodic, not periodic), each=100)) my.df - data.frame(x=x, y=y, fact = fact, fact2 = fact2) head(my.df) myColors - c(2, 4) xyplot(y ~ x | fact, data = my.df, groups = fact2, panel = panel.superpose, panel.groups = function(..., group.number) { panel.xyplot(...) #panel.xyplot( ..., col=myColors[group.number]) # error }) My aim is to assign a custom color to each group, but for some reason the col parameter is already given to panel.xyplot and I can't find where it gets the values from. It get's the values from the 'panel.superpose' function, of which 'panel.groups' is an argument. Both the documentation and source code for 'panel.superpose' should make this clear. From what I understand, what you want should be as simple as (with a small correction to your example): xx - seq(1, 10, length=100) x - rep(xx, 4) y - c(cos(xx), sin(xx), xx, xx^2/10) fact - factor(rep(c(cos, sin, id, square), each=100)) fact2 - factor(rep(c(periodic, not periodic), each=200)) my.df - data.frame(x=x, y=y, fact = fact, fact2 = fact2) myColors - c(2, 4) xyplot(y ~ x | fact, data = my.df, groups = fact2, col = myColors, type = l) The use of 'par.settings' is not compulsory, but would help if you needed to add a legend; e.g., xyplot(y ~ x | fact, data = my.df, groups = fact2, type = l, par.settings = simpleTheme(col = myColors), auto.key = list(lines = TRUE, points = FALSE)) If you insist on writing your own panel function, what you need is xyplot(y ~ x | fact, data = my.df, groups = fact2, panel = panel.superpose, panel.groups = function(..., col.line, type, group.number) { panel.xyplot(..., type = l, col.line = myColors[group.number]) }) As Bert pointed out, you are responsible for ensuring that argument names are not repeated by capturing and overriding them. All of this applies to your second, more complicated, example as well. As for the order in which the groups are plotted, it is the order of levels(fact2), which seemed to me the most obvious (or at least the least surprising) choice. You are free to specify the order when you create the factor; see ?factor to learn how. -Deepayan _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] nls, lattice, and conversion over to ggplot
It worked for me, do you have the latest version of ggplot2 released a few days ago (ggplot2_0.7) ? Baptiste On 9 Oct 2008, at 20:55, stephen sefick wrote: Error in `[.data.frame`(df, , var) : undefined columns selected I got this error in a fresh R session after rerunning all of the commands On Thu, Oct 9, 2008 at 3:45 PM, hadley wickham [EMAIL PROTECTED] wrote: On Thu, Oct 9, 2008 at 2:29 PM, stephen sefick [EMAIL PROTECTED] wrote: I am trying to figure out how to use ggplot2. I would like to do the below with ggplot, but I can not figure out how. The data provided is a subset of a much larger data set, but these data are the data necessary to make the plot. I think I would rather have the colors become symbols, and I do know how to do that in lattice, but here is a quick and dirty version. thanks Here's one way: pred - data.frame(GPP = f, TSS = y) qplot(TSS, GPP, data=r, colour=RiverMile) + geom_line(data=pred, colour =black) * ggplot2 works with data frames, so the key is to create one from your model predictions. Naming the variables to match the names of the model inputs makes sense, and saves some typing. * You no longer need to specify xlim because ggplot2 knows about everything you are plotting and can calculate the limits appropriately. * You have have to manually set the colour in geom_line to override the default mapping that you created between colour and RiverMile. Hadley -- http://had.co.nz/ -- Stephen Sefick Research Scientist Southeastern Natural Sciences Academy Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plotCI
Hi it might be as simple as adding type = b in your call, however if you need more help you'll have to provide a reproducible example and explain what package you used (I think several packages define a plotCI function). Hope this helps, Baptiste On 10 Oct 2008, at 22:15, Caio Azevedo wrote: Hi all, I am using the function plotCI with the following command: plotCI(m.residuos.p.2 [1:41],li=m.residuos.p.3 [1:41],ui=m.residuos.p.4 [1:41],lty=1,ylab=) This generates exactly what I want except for the fact that I wanna drawn a line linking the points (m.residuos). How could I do that? Thanks a lot in advance, Caio [[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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] lattice panel question
Hi, I believe you want to look at ?strip.custom someStuff - data.frame(area = rep(c(SOUTH, NORTH, EAST, WEST), each = 25), group = rep(c(A,B,C,D), each = 5), mytime = rep(1:4), val1 = sample(1:100, size=100, replace=TRUE), val2 = sample(1:100, size=100, replace=TRUE) ) xyplot(val1+val2 ~ mytime | area * group, data = someStuff, type = c(a,p, g), strip=strip.custom(factor.levels=letters[1:4])) Hope this helps, baptiste On 14 Oct 2008, at 00:43, Ferry wrote: Dear R users, How to change lattice panel label/text from the automatically generated label (based on the conditioning) to our own set of label? for example: someStuff - data.frame(area = rep(c(SOUTH, NORTH, EAST, WEST), each = 25), group = rep(c(A,B,C,D), each = 5), mytime = rep(1:4), val1 = sample(1:100, size=100, replace=TRUE), val2 = sample(1:100, size=100, replace=TRUE) ) xyplot(val1+val2 ~ mytime | area * group, data = someStuff, type = c(a, p, g)) I want to change each panel label/text from for example D/East or D/ North ... into Deriv/From East, Deriv/From North ... I know I could change from the data, but is there a way to change it from lattice ? thanks beforehand. [[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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] What editors can I get R in Mac OS X to talk to?
Hi, I use Textmate, but every now and then I like to try out aquamacs. I've just downloaded it from http://aquamacs.org/ , where ESS is part of the package. It runs flawlessly for me, out of the box. I just opened a r file, clicked the big R icon, then simply highlighted part of the code and Cc-Cr to evaluate it. For some reason the default graphics device turned out to be x11() but that's a minor detail to configure. Baptiste (R7.2, MBP, Leopard) On 23 Oct 2008, at 09:36, Mike Williamson wrote: All, Apologies if this was already answered... I couldn't find an answer that specifically addressed Mac OS instead of either windows or linux. I use aquamacs emacs as my text editor. It is essentially Xemacs with a GUI that looks closer to standard Mac GUIs, as far as I can tell. I installed the GUI-friendly Mac version of R. I can have R choose the aquamacs as the editor of choice, but I cannot seem to figure out how to do any script executions. E.g., highlighting part of the script and then hitting CTRL-R or something similar to get just a portion of the script to run. I would install ESS, since I know that is supposed to help emacs talk to R, but I have no confidence that it either (a) works for the Mac (if so, do I install the unix version? if I do that, can I only run it on my Mac via the unix command calls?), or (b) works with the aquamacs editor. I don't care about the editor so much, I could find a less fancy text editor. But I don't really know how to install ESS properly on a mac. Thanks in advance! Mike [[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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Filling symbols in xyplot
Hi, I feel that your example isn't exactly minimal so I may be completely overlooking your question. Would the following do? library(lattice) mdf - data.frame(x - seq(0, pi, l=100), y=sin(x)) xyplot(y~x, data=mdf, type=b, par.settings=list(plot.symbol=list(pch=21, col=red, fill=blue), plot.line=list(col=blue))) baptiste On 25 Oct 2008, at 15:39, John Poulsen wrote: Hello, I am using xyplot and am happy with my graph, *except* that I cannot get the symbols to be filled. I tried using bg=c(red3,red,black,lightgrey)) in both the key and the xyplot function, that that was obviously not the answer. I would like the sybols to be filled with the same colors as the lines. Does anybody have an answer? In case you want to see the graph so far, I have included a ridiculously large dataframe for an example. It should work by copying and pasting everything below. Thanks, John ## Data for dataframe Per = c (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3 , 3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4) Effect=c(NA,NA,NA, 0.2376395534,0.274667,0.4498834499,0.0070370370,0.00,0.00,0.1510180755 , 0.1939983165,0.3705749806,0.0003326279,0.00,0.00,0.0607577973,0.3087870370,0.2044472934 ,NA,NA, NA,0.1575877193,0.362289,0.3349059829,NA,NA,NA, 0.1529505582,0.2393737374,0.3928671329, 0.0036094276,0.00,0.00,0.0798121567,0.1404797980,0.3064283864,0.0016199430,0.00,0.00,0.0334615010 , 0.234639,0.1558945869,NA,NA,NA, 0.1445175439,0.308933,0.2867008547,NA,NA, NA, 0.1410287081,0.2057979798,0.3950738151,0.00,0.3050398860,0.0862091150,0.0673657629,0.1273569024,0.3064128464 , 0.0109369149,0.3582849003,0.0224585137,0.0322641326,0.2232962963,0.1731766382 ,NA,NA,NA,0.1255701754, 0.292311,0.2842905983,NA,NA,NA, 0.1369736842,0.170378,0.338667,0.0042262922,0.3632792023, 0.1664267677,0.0594074074,0.101667,0.2522079772,0.00,0.4042621083,0.0241041366,0.0275009747,0.1971481481,0.1156780627 , NA,NA,NA,0.1309649123,0.271533,0.2804786325) Spp = c (BOM ,ING ,Mal ,MGZ ,NGA ,TIA ,BOM ,ING ,Mal ,MGZ ,NGA ,TIA ,BOM ,ING ,Mal ,MGZ ,NGA ,TIA ,BOM ,ING ,Mal ,MGZ ,NGA ,TIA,BOM,ING,Mal,MGZ,NGA,TIA,BOM,ING,Mal,MGZ, NGA ,TIA ,BOM ,ING ,Mal ,MGZ ,NGA ,TIA ,BOM ,ING ,Mal ,MGZ ,NGA ,TIA ,BOM ,ING ,Mal ,MGZ ,NGA ,TIA ,BOM ,ING ,Mal ,MGZ,NGA,TIA,BOM,ING,Mal,MGZ,NGA,TIA,BOM,ING, Mal ,MGZ ,NGA ,TIA ,BOM ,ING ,Mal ,MGZ ,NGA ,TIA ,BOM ,ING ,Mal ,MGZ ,NGA ,TIA ,BOM ,ING,Mal,MGZ,NGA,TIA,BOM,ING,Mal,MGZ,NGA,TIA) Treat = c (CL ,CL ,CL ,CL ,CL ,CL ,UL ,UL ,UL ,UL ,UL ,UL ,UU ,UU ,UU ,UU ,UU ,UU ,CU ,CU ,CU ,CU ,CU ,CU ,CL ,CL ,CL ,CL ,CL ,CL ,UL ,UL ,UL,UL,UL,UL,UU,UU,UU,UU,UU,UU,CU,CU,CU, CU ,CU ,CU ,CL ,CL ,CL ,CL ,CL ,CL ,UL ,UL ,UL ,UL ,UL ,UL ,UU ,UU ,UU ,UU ,UU ,UU ,CU ,CU ,CU ,CU ,CU ,CU ,CL ,CL ,CL ,CL ,CL ,CL,UL,UL,UL,UL,UL,UL,UU,UU,UU,UU,UU,UU, CU,CU,CU,CU,CU,CU) splabel=c(A,B,C,D,E,F) resmat=data.frame(Effect, Per, Spp, Treat) ## Graphing functions library(lattice) key.aug - list(corner=c(0,0.93), text = list(levels(resmat$Treat)), points = list(pch = c(21,2,21,2), cex=c(1.2,1,1.2,1), col = c(red3,red,black,lightgrey)), lwd=2, cex=0.8) xyplot(Effect~Per|Spp, resmat, groups=Treat, type=b, lwd=2, pch=c(21,2,21,2), cex=c(1.2,1,1.2,1), col=c(red3,red,black,lightgrey),xlab=c(Months), strip=strip.custom(style=1, bg=lightgrey, factor.levels=c(splabel)), ylab=expression(Treatment-Control/Augmentation), par.strip.text=list(cex=1, lines=1.25, lwd=2), scales=list(x=list(at=c(1,2,3,4), labels=c(3,6,9,12)), y=list(ylim=list(c(0,1),c(0,1),c(0,1), c(0,1),c(0,1),c(0,1, key=key.aug) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] orthographic projection of ellipsoids
Dear list, I've generated a list of 3D coordinates representing ellipsoids in arbitrary orientations. I'm now trying to obtain a 2D projection of the scene, that is to draw the silhouette of each object on a plane (x,y). The only way I could think of is to compute the convex hull of the (x,y) coordinates of each object and use this as the outline of the object. This is clearly not very efficient or satisfying. I think I'm on the wrong track from the start. Is there an obvious analytical parametrisation of such projections? Any comments are welcome. Many thanks, baptiste rotM3d - function(theta=0, phi=0, psi=0){ # 3D rotation matrix a11 - cos(psi)*cos(phi) - cos(theta)*sin(phi)*sin(psi) a12 - cos(psi)*sin(phi) + cos(theta)*cos(phi)*sin(psi) a13 - sin(psi)*sin(theta) a21 - -sin(psi)*cos(phi) - cos(theta)*sin(phi)*cos(psi) a22 - -sin(psi)*sin(phi) + cos(theta)*cos(phi)*cos(psi) a23 - cos(psi)*sin(theta) a31 - sin(theta)*sin(phi) a32 - -sin(theta)*cos(phi) a33 - cos(theta) matrix(c(a11, a12, a13, a21, a22, a23, a31, a32, a33), ncol=3) } rotM3d() # I ellipsoid - # idea borrowed from a post in the R-mailing list (John Fox i think) function(x=0, y=0, z=0, radius=1, shape=diag(c(10, 2, 2)),theta=0, phi=0, psi=0, segments=11) { angles - (0:segments)*2*pi/segments ecoord2 - function(p) { c(cos(p[1])*sin(p[2]), sin(p[1])*sin(p[2]), cos(p[2])) } unit.sphere - t(apply(expand.grid(angles, angles), 1, ecoord2)) xyz - t(c(x, y, z) + radius * rotM3d(theta, phi, psi)%* %t(unit.sphere %*% chol(shape))) chull(x=xyz[, 1], y=xyz[, 2])-points mdf - data.frame(x=xyz[points, 1], y=xyz[points, 2]) polygon(mdf, col=hcl(h = 0, c = 35, l = 85, 0.5)) invisible(xyz) } xx - seq(-5, 5, len=10) xy - expand.grid(xx, xx) xy.jit - apply(xy, 2, jitter, amount=0.4) par(mar=c(0, 0, 0, 0)) plot(xy.jit, t=n, axes=F, xlab=, ylab=) x - xy.jit[, 1] y - xy.jit[, 2] twist - pi*y/max(abs(y)) * rep(1, length(y)) tilt - pi*x/max(abs(x)) * rep(1, length(x)) b.quiet - mapply(ellipsoid, theta=twist, psi=tilt,x=x, y=y, SIMPLIFY=F, radius=0.15) _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] replace a few strings in a text file
Dear all, I wrote a wrapper to a FORTRAN program using R. The main program uses a text file (~200 lines) as an input describing the simulation to be run. I typically generate the file once with the right parameters using a combination of file(), paste(), cat(). This is fine, and it works well, however I then need to update only a few values in the file many times (~200 times, typically). I've used Ruby for this task in the past, and I wonder whether there is a simple and efficient way to achieve this in R. Here's a minimal example, myFile - test.txt writeHeader - function (out=myFile, N=5, wavelength=0.1) { output - file(paste(out), w) headerString - c(Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Variables, wavelength, N, - wavelength - ind_refMed Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. ) cat(paste(headerString), file = output, sep = \n) close(output) } writeHeader(out=myFile) system(paste(cat, myFile)) system.time(sapply(1:200, writeHeader) - b.quiet) Now for the ruby replacement solution: #!/usr/bin/ruby -w lambda = 0.1 N = 5 input_file=IO.readlines('test.txt') # replace wavelength input_file[6]= lambda.to_f input_file[7]= N.to_f f=File.new(test2.txt,w) f.puts input_file f.close I think (unverified) that this approach is more efficient than calling the writeHeader() each time. Please do let me know if I'm wrong on this. The drawback of using this Ruby script is that I need to know the numbers of the lines to be replaced (also, I don't know much in Ruby). I'm not sure how I can find this other than manually, as there is no regular pattern to look for. Ideally the generating script writeHeader() would return these line numbers, I'm not sure how to achieve this. Any comments are welcome. Best regards, baptiste (R7.2, MacOS 10.5) _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] replace a few strings in a text file
First of all, let me apologize for the 200 files that would result from running my minimal example. I've just realised this on my Desktop; it seems i overlooked the arguments passed to sapply(). Thank you for your reply Duncan, I realize now my approach was quite silly. It is indeed much more natural to create and manipulate all the strings in R and write the new file every time in a single step. Thanks, baptiste On 27 Oct 2008, at 10:47, Duncan Murdoch wrote: baptiste auguie wrote: Dear all, I wrote a wrapper to a FORTRAN program using R. The main program uses a text file (~200 lines) as an input describing the simulation to be run. I typically generate the file once with the right parameters using a combination of file(), paste(), cat(). This is fine, and it works well, however I then need to update only a few values in the file many times (~200 times, typically). I've used Ruby for this task in the past, and I wonder whether there is a simple and efficient way to achieve this in R. Here's a minimal example, myFile - test.txt writeHeader - function (out=myFile, N=5, wavelength=0.1) { output - file(paste(out), w) headerString - c(Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Variables, wavelength, N, - wavelength - ind_refMed Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. ) cat(paste(headerString), file = output, sep = \n) close(output) } writeHeader(out=myFile) system(paste(cat, myFile)) system.time(sapply(1:200, writeHeader) - b.quiet) Now for the ruby replacement solution: #!/usr/bin/ruby -w lambda = 0.1 N = 5 input_file=IO.readlines('test.txt') # replace wavelength input_file[6]= lambda.to_f input_file[7]= N.to_f f=File.new(test2.txt,w) f.puts input_file f.close I think (unverified) that this approach is more efficient than calling the writeHeader() each time. Please do let me know if I'm wrong on this. The drawback of using this Ruby script is that I need to know the numbers of the lines to be replaced (also, I don't know much in Ruby). I'm not sure how I can find this other than manually, as there is no regular pattern to look for. Ideally the generating script writeHeader() would return these line numbers, I'm not sure how to achieve this. Any comments are welcome. If there are only 200 lines, why not put them into a character vector, and edit them there? That's more or less what your Ruby code does. In R, it would be written input_file - readLines(test.txt) input_file[6] - sprintf(%f, lambda) input_file[7] - sprintf(%f, N) writeLines(test2.txt, input_file) but if everything is in R, you don't need the first line. 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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Arrays of Trellis plots
Hi, You could use the grid package to place treillis objects in any custom layout you want, for example (inspired by Paul Murrell's R graphics book http://www.stat.auckland.ac.nz/~paul/RGraphics/rgraphics.html fig 5.22), library(grid) library(lattice) df - data.frame(x=rnorm(100), y=rnorm(100)) df2 - data.frame(x - rnorm(100), y=runif(x)) p - xyplot(y~x, data=df) p2 - xyplot(y~x, data=df2) pushViewport(viewport(x=0.25, width = 0.5, height = 0.8, angle = 0, name = leftvp)) grid.rect(gp = gpar(col = rgb(43/255, 140/255, 190/255))) print(p, newpage=F) upViewport() pushViewport(viewport(x=0.75, width = 0.5, height = 0.8, angle = 0, name = rightvp)) grid.rect(gp = gpar(col = rgb(43/255, 140/255, 190/255))) print(p2, newpage=F) upViewport() Hope this helps, baptiste On 27 Oct 2008, at 18:13, erwann rogard wrote: hello, the example below does not work. (i know it's not supposed, but it makes it clear what i'm trying to achieve) par(mfrow=c(2,1)) xyplot(y~x2|x1,data=dataframe1,pch=20) xyplot(y~x2|x1,data=dataframe2,pch=20) i know i could probably merge the two datasets and do something like xyplot(y~x2|x1+dataset,data=merged) any other suggestion? 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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plot: Howto get parameters befor plotting anything?
Hi, I believe you could use plot.window(xlim,ylim,...), followed by par(). In any case, the code of plot.default should inspire you (note that it's calling plot.new(), for instance). Baptiste On 30 Oct 2008, at 09:32, Johannes Graumann wrote: Hello, Is it possible to get all par content calculated for plot without actually plotting anything? I'm missing an option plot=FALSE ... type=n will still open a device and draw the axes ... Thanks, Joh __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Splitting device for ggplots?
Hi, I believe you can apply the same procedure as described in Paul Murrell's R graphics book for arranging lattice plots. library(grid) library(ggplot2) ?grid.layout df - data.frame(x=rnorm(100), y=rnorm(100)) df2 - data.frame(x - rnorm(100), y=runif(x)) p - qplot(x,y, data=df) p2 - qplot(x,y, data=df2) pushViewport(viewport(x=0.25, width = 0.5, height = 0.8, angle = 0, name = leftvp)) grid.rect(gp = gpar(col = rgb(43/255, 140/255, 190/255))) print(p, newpage=F) upViewport() pushViewport(viewport(x=0.75, width = 0.5, height = 0.8, angle = 0, name = rightvp)) grid.rect(gp = gpar(col = rgb(43/255, 140/255, 190/255))) print(p2, newpage=F) upViewport() Hope this helps, baptiste On 1 Nov 2008, at 09:35, Vitalie Spinu wrote: Dear UseRs, For various reasons I need to plot multiple ggplots on one device (preferably pdf). Is there a way to achieve that? par(mfrow), split.screen() and layout() seem not to do the job. Thanks, Vitalie. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 make a multiple plot
perhaps you could also look into ggplot2 or lattice package to display several plots on the same page. They take care of important but annoying details such as scaling, layout, limits, legend, ... Admittedly, there is a learning curve when you're used to base graphics, but in the long term it is a more efficient, robust and elegant approach. Baptiste On 6 Nov 2008, at 07:15, Dieter Menne wrote: amy rheanita amee_86 at yahoo.com writes: I'm a student. now, I'm studying Nelson-Siegel Extended, a term structure model. I can analyze - estimate parameters and make aplot - manually, from data bond in a day. I can analyze bond data in a month, like make multiple plot for different bont date and make a multiple plot to compare parameters in different date. Try par(mfrow=c(2,2)) before creating the plot. Dieter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Applying a function to a list of arguments ...
perhaps something like, func - function(f, ...) { do.call(f, ...) } func(rnorm, list(n=3, mean=2, sd=3)) baptiste On 7 Nov 2008, at 10:21, [EMAIL PROTECTED] wrote: How can I apply function f, that I get as an argument as in func - function(f, ...) { . . . } to a list of arguments list(a, b, c) (eg the ... argument of func above) in order to obtain f(a, b, c) Thanks a lot, Roberto [[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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [Rd] Re Bessel functions of complex argument
Dear all, I'm writing a code that requires Bessel functions with complex argument. Searching the list, I found the continuation of a thread I initiated a few months ago: http://tolstoy.newcastle.edu.au/R/e4/devel/08/03/0746.html As I understand, the most promising option would be to use the fortran or C implementation of Amos, http://portal.acm.org/citation.cfm?id=214331dl=GUIDEcoll=GUIDECFID=9717168CFTOKEN=75957024 Sadly, my limited programming skills don't include any knowledge of fortran, and I have never managed to link external code to R functions (i'm missing a simple example based tutorial, R-ext overwhelms me with information). A few questions for anyone interested: - Does the aforementioned fortran code lends itself to an easy interfacing with R? (in other words, do I stand a chance in less than 10 years?) - Is anyone willing to help me with this? The package is hosted on R-forge and i could take care of the documentation, etc. - Is there a package I've missed that already implements this? (one can dream) Many thanks, baptiste _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ [[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] Outer, kronecker, etc.
you may want to look into Hadley's new package plyr for this kind of operation. baptiste On 12 Nov 2008, at 17:51, Stavros Macrakis wrote: By-the-way^2: is there some Xapply function that maps a function over all the elements of a structure (vector, matrix, list, ...) and preserves the original structure? For example, I'd want Xapply(matrix(1:4^2,2,2),sqrt) == sqrt(matrix(1:4^2,2,2)). In this case, I'd use Xapply(as.character,mm), because as.character returns a vector. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 code to generate Sweave input ? Sweave squared ?
Hi, Your idea reminds me of an example in the documentation of the brew package, featuring the generation of a template. You might want to check it out. baptiste On Wed, Nov 12, 2008 at 2:01 PM, Kem Phillips [EMAIL PROTECTED]wrote: Dirk, I came upon your message below in searching for a different Sweave topic. Have you pursued this? I'm new to R (9 months). Recently have been doing data analysis in R and have started pondering the same question, but don't have any ideas yet. I did do something related to this in SAS, the main purpose of which was to build a standardized file of statistical results to be transferred to Word tables. Thanks. Kem Phillips _ For some recurrent tasks, I would like to programmatically generate input for Sweave. While I could do that with many languages, in particular some starting with the letter P, I wouldn't mind advancing two more positions in the alphabet and use R itself to generate input for Sweave. In other words I want to write R code that can write Rnw input files which will be turned into R code ... that ends up as dvi/pdf output. Has anybody done this before? Are there any frameworks to (re-)use ? Regards, Dirk -- Hell, there are no rules here - we're trying to accomplish something. -- Thomas A. Edison [[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. -- _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ [[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] Lattice: groups and no groups with panel.superpose
Hi, I think the following code should do what you want, xyplot(yvar~year|week,data=df,layout = c(4, 5), type='p', groups = temp , panel = function(x, y, ...) { panel.superpose(x, y, ...) panel.abline(lm(y~x)) }, panel.groups = function(x, y, ..., lty) { panel.xyplot(x, y, ..., lty = lty) panel.abline(lm(y~x), lty=3, ...) }) Hope this helps, baptiste On 15 Nov 2008, at 14:25, Robert Buitenwerf wrote: Dear R listers, I am trying to create a lattice plot with independent regression lines per group for each panel, plus one overall regression line per panel. I succeed in having the separate regression lines for each group per panel, but I can't figure out how to add the overall regression line over all groups. I have learnt a lot from the list, but I can't find an example for what I want to do... with the following example data (from another post): years-2000:2006 weeks-1:20 yr-rep(years,rep(length(weeks)*6,length(years))) wk-rep(weeks,rep(6,length(weeks))) temp-rep(4:9,length(years)*length(weeks)) yvar-round(rnorm(length(years)*length(weeks)*6,mean=30,sd=4),0) xvar-(rnorm(length(years)*length(weeks)*6)+5)/10 df-data.frame(year=yr,week=wk,temp=temp, yvar=yvar, xvar=xvar) I get the regression lines per group for each panel using: xyplot(yvar~year|week,data=df,layout = c(4, 5), type='p', groups = temp , panel = panel.superpose, panel.groups = function(x, y, ..., lty) { panel.xyplot(x, y, ..., lty = lty) panel.abline(lm(y~x), lty=3, ...) }) And obviously the overall regression lines with: xyplot(yvar~year|week,data=df,layout = c(4, 5), type='p', panel = function(x, y, ...) { panel.xyplot(x, y, ...) panel.abline(lm(y~x)) }) Any advice on how to merge the output from the two above graphs would be greatly appreciated! Kind regards, Robert Buitenwerf Ecologist SAEON South Africa _ [[elided Hotmail spam]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] pdf device: rasterize portions of the plot to reduce file size
Dear list, My favorite output format is usually pdf. I can include the graphics in pdflatex documents and benefit from the scalable nature of vector graphic formats. However, I recently had to generate high-res 2D levelplot graphics as in the example below, N - 100 # N - 1000 # slow to diplay xy - expand.grid(x=seq(0, 10, length=N), y=seq(0, 10, length=N)) xy - within(xy, z - x^2*cos(x*y)) library(lattice) p - levelplot(z~x*y, data=xy, panel=function(...) {panel.levelplot(...); ltext(5, 5, text)}) pdf(plot.pdf) print(p) dev.off() png(plot.png) print(p) dev.off() With N=1000, this approach produces a hefty pdf file of ~29MB, while the png file with default resolution is only 72kB. It is clear that I don't want to include the pdf figure in a manuscript, as most pdf readers (let alone the printer) will painfully stall when scrolling down the document. The png file has a good enough resolution (this could be tuned anyway) as far as the levelplot is concerned, however the text and labels are evidently converted to bitmap. I would like to ask whether there are some alternative ways to combine the best of both worlds in R, that is to create a pdf file with part of the output being an embedded bitmap (the levelplot in this case). Xfig, as I recall, has a way to produce two separate files for this kind of purpose: one containing the graphical information stripped of annotations, the other the labels and axes to be processed by TeX. On a side note, I noticed that Acrobat Professional can substantially reduce the file size (3.4MB), but it does not seem to help some pdf readers (Preview on Leopard, for one). I'm open to suggestions of auxiliary tools that might help. Best regards, baptiste sessionInfo() R version 2.7.2 Patched (2008-08-25 r46438) i386-apple-darwin9.4.0 locale: en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8 attached base packages: [1] stats graphics grDevices utils methods base other attached packages: [1] latticeExtra_0.5-1 lattice_0.17-13baptMisc_1.0 RColorBrewer_1.0-2 loaded via a namespace (and not attached): [1] grid_2.7.2 _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] pdf device: rasterize portions of the plot to reduce file size
Thanks for your comment. I would typically follow this approach too, but I'm wondering whether one could find a more sophisticated solution. Ideally, I'd like to be able to select the text that is annotating the figure. There are very few cases where I can see a real need for raster text, therefore I like to avoid resorting to it. Using the versatile grid system, I can envisage two ways to implement this, i) generate a bitmap of the graph without any annotation (removing a custom list of grob), and include the resulting image in a pdf file containing only the annotations on top. I think grid could manage perfectly accurate positioning between the image and its annotations. ii) generate a sub-sampled version of the image part of the graph before creating the pdf file (I'm thinking of the adimpro package, for instance). However, I don't think this approach would work for a graph that contains very many lines or other high-level grobs. I'm probably missing some important points to consider as I have no familiarity with the internals of R graphics engine / devices. baptiste On 20 Nov 2008, at 11:41, Stefan Evert wrote: With N=1000, this approach produces a hefty pdf file of ~29MB, while the png file with default resolution is only 72kB. It is clear that I don't want to include the pdf figure in a manuscript, as most pdf readers (let alone the printer) will painfully stall when scrolling down the document. The png file has a good enough resolution (this could be tuned anyway) as far as the levelplot is concerned, however the text and labels are evidently converted to bitmap. I would like to ask whether there are some alternative ways to combine the best of both worlds in R, that is to create a pdf file with part of the output being an embedded bitmap (the levelplot in this case). Xfig, as I recall, has a way to produce two separate files for this kind of purpose: one containing the graphical information stripped of annotations, the other the labels and axes to be processed by TeX. What I usually do in this situation is to produce very high-resolution bitmaps (2000 x 2000 pixels and possibly even more). The .png files for these will still be much smaller than your 30MB .pdf, and if you don't need best quality, you can probably also convert them to .jpg format. Most viewers should be able to display large bitmap images fast and in good quality. This seems to be the only way to include plots reliably in Microsoft Word documents ... I'm not sure about the anti-aliasing options of R's png() driver, but you could always generate an even higher-resolution bitmap and then scale down with standard image processing software (ImageMagick, GIMP, xv, ...). My favourite solution is to generate a .pdf or .eps file, even if this is very large, and then convert to a hi-res bitmap image with pstoimg from the latex2html package. Useful command-line options are: pstoimg -type png -depth 24 -antialias -scale 2 plot.eps Use the -scale option to generate the desired bitmap size. Best regards, Stefan Evert [ [EMAIL PROTECTED] | http://purl.org/stefan.evert ] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error with lapply
Hi, you are feeding lapply i as an optional argument, which is passed to fn() and causes an error. Just use lapply(1:4, fn), or better yet, sapply, fn - function(i) return(i^2) sapply(1:4, fn) [1] 1 4 9 16 Hope this helps, baptiste On 20 Nov 2008, at 16:31, megh wrote: I have written following codes, with intention to get a list with values 1,2,9,16 : fn - function(i) return(i^2) lapply(1:4, fn, i) However I got following error : Error in FUN(1:4[[1L]], ...) : unused argument(s) (1) Can anyone please tell me what will be the correct code here? Regards, -- View this message in context: http://www.nabble.com/Error-with-lapply-tp20605066p20605066.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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] align two lattice plots using grid
Dear list, I'm trying to get two lattice plots aligned on a page. They should share a common x axis, hence the need for perfect alignment, but the data is taken from unrelated, separate sources (it is therefore inappropriate to combine them and use facetting to get an automatic layout: the legend and y axis need to be different). I can get the panels to be of the same size, but they have an horizontal offset due to a differing size of the legend / ylabel. Here's an example of what I've tried, library(grid) library(lattice) x - seq(0, 10, length=100) y - sin(x) f - rep(c(1, 2), each=50) p1 - xyplot(y~x,groups=f, ylab=BIG LABEL, auto.key=list(space=right)) p2 - xyplot(y~x, ylab=a) pushViewport(viewport(layout=grid.layout(nrow = 2, ncol = 1 , widths=unit(6, inches), heights=unit(c(3, 2), inches pushViewport(viewport(layout.pos.col=1, layout.pos.row=1, just=center, name = top)) print(p1, newpage=F, panel.width=list(4, inches), panel.height=list(2.5, inches)) upViewport() pushViewport(viewport(layout.pos.col=1, layout.pos.row=2, just=center, name = bottom)) print(p2, newpage=F, panel.width=list(4, inches), panel.height=list(1.5, inches)) upViewport() I'm sure there is a clever trick to get the panels to be aligned as opposed to the whole plots, but I can't see it. Many thanks, baptiste _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fitting a sine wave using solver
Just a thought on this topic, I found Harminv quite powerful for this sort of task. I wonder whether it could be wrapped into a R package (it's GPL). http://ab-initio.mit.edu/wiki/index.php/Harminv On 20 Nov 2008, at 22:46, Prof Brian Ripley wrote: See e.g. http://finzi.psych.upenn.edu/R/Rhelp02a/archive/131024.html RSiteSearch() produced this and similar relevant past postings. On Thu, 20 Nov 2008, Ben Zuckerberg wrote: Greetings, I have several sets of oscillation data and would like to estimate the parameters of a sine function to each set (and hopefully automate this). A colleague provided an excel sheet that uses solver to minimize the RSS after fitting the sine function to each data set, but this cumbersome and difficult to automate. Is there a method in R for fitting a given sine function to a supplied data using maximum likelihood estimation (or minimizing the RSS). Thanks in advance. -- Benjamin Zuckerberg, Ph.D. Post-doctoral Associate Spatial Ecologist, Citizen Science Cornell Laboratory of Ornithology 159 Sapsucker Woods Road Ithaca, NY 14850 Tele: 607-254-2174 Fax: 607-254-2111 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [Rd] Re Bessel functions of complex argument
I thought I'd share a few workaround routes I've considered (my attempt at using Amos' Fortran routines failed miserably -- if anyone is interested i can explain what I tried), - Ryacas seems to provide a very simple way to evaluate bessel functions with complex argument, yacas(N(BesselJ(2, 1+I))) Complex(0.415798869439e-1,0.247397641513); Not sure yet how fast this is, and how to get data in/out in R format but it looks promising. - Similarly, I get the idea that Sage could provide an interface to Maxima or Pari and return the desired value. There doesn't seem to be much of a documentation centred on the use of Sage with R, though. - Octave has implemented the Amos code (so has Matlab). This should make it possible to call Octave and get the result back in R (Roctave package I believe), or better yet, get inspiration to properly use the underlying Fortran code. Baptiste On 9 Nov 2008, at 12:22, baptiste auguie wrote: Dear all, I'm writing a code that requires Bessel functions with complex argument. Searching the list, I found the continuation of a thread I initiated a few months ago: http://tolstoy.newcastle.edu.au/R/e4/devel/08/03/0746.html As I understand, the most promising option would be to use the fortran or C implementation of Amos, http://portal.acm.org/citation.cfm?id=214331dl=GUIDEcoll=GUIDECFID=9717168CFTOKEN=75957024 Sadly, my limited programming skills don't include any knowledge of fortran, and I have never managed to link external code to R functions (i'm missing a simple example based tutorial, R-ext overwhelms me with information). A few questions for anyone interested: - Does the aforementioned fortran code lends itself to an easy interfacing with R? (in other words, do I stand a chance in less than 10 years?) - Is anyone willing to help me with this? The package is hosted on R- forge and i could take care of the documentation, etc. - Is there a package I've missed that already implements this? (one can dream) Many thanks, baptiste _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ [[alternative HTML version deleted]] ATT1.txt _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Multiple lattice plots on a page: aligning x-axes vertically
Have you tried c() from the latticeExtra package? It worked for me (see below) library(grid) library(lattice) x - seq(0, 10, length=100) y - sin(x) y2 - 10*sin(x) f - rep(c(1, 2), each=50) p1 - xyplot(y~x,groups=f, ylab=BIG LABEL, # auto.key=list(space=right), par.settings = list(layout.width = list(panel=1, ylab = 2, axis.left =1.0, left.padding=1, ylab.axis.padding=1, axis.panel=1))) p2 - xyplot(y2~x, ylab=a, par.settings = list(layout.width = list(panel=1, ylab = 2, axis.left =1.0, left.padding=1, ylab.axis.padding=1, axis.panel=1))) library(latticeExtra) update(c(p2, p1, x.same = TRUE), layout = c(1, 2), ylab = list(c(a, BIG LABEL), y = c(1/6, 2/3)), par.settings = list(layout.heights = list(panel = c(1, 2 Hope this helps, baptiste On 25 Jan 2009, at 09:54, Daniel Myall wrote: Dear R-help, I am creating a two lattice plots (a densityplot() and xyplot()) that have the same x-axes and then 'printing' them onto the same page, one above the other (see end of email for an example to generate the graph). With different labels on the y-axis for each plot the left spacing is different, and the x-axes don't align vertically. Although I can manually modify the print region of the plots on the page to align the x-axes, this is not very robust; as can be expected changing the size of the plot device scales the x-axes differently in both plots. Additionally, changing devices also causes issues (i.e., the plots are aligned in quartz(width=12,height=6) but then slightly off with pdf(width=12,height=6)). As I'm using this inside Sweave to generate numerous plots of this form, I am after some robust way to vertically align the x-axes of the plots. With the approach I'm taking is there a way with lattice or grid to vertically align the x-axes? By somehow setting the internal plot width to be the same in both plots I think this would solve the issue (possibly by setting the right parameters in str(trellis.par.get(layout.widths)))? Alternatively, would another approach be better (i.e., is it possible to create a new panel function that does a panel.xyplot and panel.densityplot on slightly different data?). Thanks. Daniel ## BEGIN Example #OS: Mac OS X 10.5.5; R: 2.8.1; lattice 0.17-20 library(reshape) library(lattice) plotdensitymeans - function(data,measure,factors=c('subject_group','task'), xlab=,xlim=NULL, ...) { # Create means by subject x.melted - melt(data, id.var = append(factors,'subject_ID'), measure.var=measure,na.rm=T) formula.bysubject.cast - paste(factors[1],+,factors[2],+ subject_ID ~ .) x.cast.subject - data.frame(cast(x.melted,formula.bysubject.cast, mean)) # Plot means by subject text.formula - paste(factors[1],:,factors[2],~ X.all.) text.group - paste(factors[1],:,factors[2]) formula.xyplot - as.formula(text.formula) formula.group - as.expression(formula.xyplot) environment(formula.xyplot) - environment() plot.subject.means - xyplot(formula.xyplot, group=eval(formula.group), xlim=xlim, pch=16, alpha=0.6,data = x.cast.subject,xlab=xlab,ylab=) # Plot distributions formula.densityplot - as.formula(paste( ~,measure[1])) environment(formula.densityplot) - environment() plot.density - densityplot(formula.densityplot,group=eval(formula.group),data=data, xlim=xlim,n=200,auto.key=list(columns = 4,line=TRUE),plot.points=F,xlab=,lty=1, scales=list(y=list(draw=FALSE),x=list(draw=FALSE))) # Plot both plots on a single page print(plot.subject.means, position = c(0,0,1,0.35)) print(plot.density, position = c(0.0988,0.22,0.98,1), newpage = FALSE) } example.data - data.frame(subject_ID = c('A01','B01','A02','B02'), subject_group = c('pop1','pop2'), task= c(rep('task1',32),rep('task2',32)),dependent_measure=rnorm(64)) plotdensitymeans(example.data, measure=c('dependent_measure'), xlab=dependent measure (units), xlim=c(-3,3)) ##END Example --- Daniel Myall PhD Student Department of Medicine University of Otago, Christchurch Van der Veer Institute for Parkinson's and Brain Research 66 Stewart St Christchurch New Zealand daniel.my...@vanderveer.org.nz http://www.vanderveer.org.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] retrieving variables values from a function
I guess by workspace you mean global environment. I believe this is generally considered a bad practice, but see ?assign and ?- baptiste On 27 Jan 2009, at 13:54, diego Diego wrote: Hello experts! Is there a way to send an internal variable from a function to the workspace, besides the function output, of course Thanks!! D. [[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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plot Ticks
Try this: plot(1:20) axis(3, at=seq(0,20), label=FALSE) A better description of your plot would be useful if ?axis is not enough to help you out. hope this helps, baptiste On 27 Jan 2009, at 14:13, mau...@alice.it wrote: Is there a way to force the number of ticks along an axis ? I read the on-line documentation and tried many combinations of all available parameters from functions par(), axTicks(), axis(), plot() ... but no luck ! Thank you very much, Maura tutti i telefonini TIM! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plot dagger symbol in R
Hi, If all else fails, you could consider using LaTeX itself with psfrag, or perhaps a similar idea involving eps2pgf. http://biostat.mc.vanderbilt.edu/twiki/bin/view/Main/PsFrag Hope this helps, baptiste On 29 Jan 2009, at 11:24, Rau, Roland wrote: Dear all, I would like to plot the dagger symbol in R (like LaTeX's \dagger). However, I was unable to do so. First, I thought maybe dagger actually exists just like the degree symbol: plot(0:1,0:1, type=n) text(x=0.5, y=0.5, labels=expression(degree)) plot(0:1,0:1, type=n) text(x=0.5, y=0.5, labels=expression(dagger)) However, this was not very successful. New hope emerged that I will succeed when I read the help page (as so often) for ?plotmath. There I discovered the 'symbol' thing and read that the Adobe Symbol font encodings are used. The closest thing I could fine, though, was: plot(0:1,0:1, type=n) text(x=0.5, y=0.5, labels=expression(symbol(\247))) But this is obviously not a dagger and it seems the Adobe Symbol font does not have a dagger. We also know this :-D library(fortunes) fortune(Yoda) So maybe someone can give me some advice? Thanks in advance, Roland -- This mail has been sent through the MPI for Demographic Research. Should you receive a mail that is apparently from a MPI user without this text displayed, then the address has most likely been faked. If you are uncertain about the validity of this message, please check the mail header or ask your system administrator for assistance. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Odp: Matrix
Hi, Perhaps this can help if you don't want to manually specify the permutation of indices, A=matrix(10,ncol=2,nrow=2) B - 2*A C - rbind(A, B) C[ as.vector(t(matrix(seq(1,nrow(C)),ncol=2))), ] # trick to create the vector of permutations [,1] [,2] [1,] 10 10 [2,] 20 20 [3,] 10 10 [4,] 20 20 The transpose operation might slow down the process on very large matrices, I'm not sure how to improve this. Hope this helps, baptiste On 2 Feb 2009, at 17:02, Paul Smith wrote: On Mon, Feb 2, 2009 at 4:05 PM, Petr PIKAL petr.pi...@precheza.cz wrote: Hi r-help-boun...@r-project.org napsal dne 02.02.2009 16:52:06: Hi, I have a very basic question on merging two matrices by alternating the rows. For illustration, assume two matrices - A looks like: 10 10 10 10 B looks like: 20 20 20 20 How do I combine them such that I get alternating rows from A and B? My final result should be C which looks like: 10 10 20 20 10 10 20 20 I would rbind both matrices and then indexed the resulting matrix. x-rep(10,4) y-rep(20,4) dim(x)-c(2,2) dim(y)-c(2,2) z-rbind(x,y) z [,1] [,2] [1,] 10 10 [2,] 10 10 [3,] 20 20 [4,] 20 20 ind-c(seq(1,4,2), seq(2,4,2)) z[ind,] z[ind,] [,1] [,2] [1,] 10 10 [2,] 20 20 [3,] 10 10 [4,] 20 20 Another solution: m1 - matrix(10,4,2) m2 - matrix(20,2,2) m1[seq(2,4,2),] - m2 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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] overlaying plots from a list of data frames
Another option, library(ggplot2) qplot(year, value, data=melt(foo), color= L1) which can also be achieved by hand, test- do.call(rbind,foo) # combines all data.sets test$name - do.call(rep, list(x=names(foo), times = unlist(lapply(foo,nrow # append the name of the original dataset library(lattice) # or ggplot2, but there seem to be a problem with the line geom in this case xyplot (data ~year,data=test,groups=name,type=b,auto.key=list(space=right)) Hope this helps, baptiste On 4 Feb 2009, at 08:59, Gabor Grothendieck wrote: Create a zoo object z and plot it: library(zoo) f - function(x) zoo(x$data, levels(x$year)[x$year]) z - do.call(merge, lapply(foo, f)) plot(z, screen = 1, col = 1:6, pch = 1:6, type = o, ylab = data, xlab = year) legend(topright, legend = 1:6, lty = 1, pch = 1:6, col = 1:6) See ?plot.zoo and the 3 zoo vignettes (pdf documents) in zoo package. On Tue, Feb 3, 2009 at 4:54 PM, Timothy W. Hilton twh...@psu.edu wrote: Hello R list, I have a list of data frames, in the form (dump output for an example list follows message): $site1 yeardata 1 2000 0.03685042 2 2001 0.02583885 6 2005 0.02480015 7 2006 0.03458745 $site2 year data 1 2002 4.071134e-03 2 2003 -4.513524e-08 3 2004 8.336272e-08 4 2005 2.270803e-08 5 2006 1.263597e-02 6 2007 NaN I would like to plot each site's data on a single plot, using a different color and marker for each site. I can't figure out an elegant way to do this; right now I am calling plot on site1, then points on site2 ... siteN. This leads to recycling the list of plot parameters (color, pch, etc.). The following code allows me to use do.call(FUN, lapply(list.of.sites, etc. if (dev.cur() 1) FUN - points else FUN - plot Now I would like to include several panels in one figure (there are actually several columns of data in the data frame). I set up the window with the panels, but that messes up the dev.cur() test I am doing. I would be most grateful for any suggestions of a more elegant setup, or for a different condition to decide whether points or plot should be called. Something like axis.already.exists(), but I can't figure out what that test should be. Many, many thanks. -Tim -- Timothy W. Hilton PhD Candidate, Department of Meteorology and Atmospheric Science The Pennsylvania State University 415 Walker Building, University Park, PA 16802 hil...@meteo.psu.edu example list of data frames: foo - structure(list(site1 = structure(list(year = structure(1:8, .Label = c(2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007), class = c(ordered, factor)), data = c(0.0368504167319695, 0.0258388514332078, 0.0432316303304793, 0.0104757403348321, -0.00942333944266443, 0.0248001501763526, 0.03458745330367, NaN)), .Names = c(year, data), class = data.frame, row.names = c(NA, -8L)), site2 = structure(list( year = structure(1:6, .Label = c(2002, 2003, 2004, 2005, 2006, 2007), class = c(ordered, factor)), data = c(0.00407113433104158, -4.51352402858745e-08, 8.33627186959167e-08, 2.27080257687498e-08, 0.0126359731744113, NaN)), .Names = c(year, data), class = data.frame, row.names = c(NA, -6L)), site3 = structure(list( year = structure(1:7, .Label = c(2000, 2001, 2002, 2003, 2004, 2005, 2006), class = c(ordered, factor )), data = c(0.0297773868339168, 0.0212836833675155, 0.030149087973, 0.000944393402486824, -2.70247618264114e-09, -2.84624718656657e-07, NaN)), .Names = c(year, data), class = data.frame, row.names = c(NA, -7L)), site4 = structure(list(year = structure(1:5, .Label = c(2000, 2001, 2002, 2003, 2004), class = c(ordered, factor )), data = c(0.000418478048104973, 0.00530609034999336, 0.020077837088374, 0.0326921217142046, NaN)), .Names = c(year, data), class = data.frame, row.names = c(NA, -5L)), site5 = structure(list(year = structure(1:5, .Label = c(2000, 2001, 2003, 2004, 2005), class = c(ordered, factor )), data = c(0.00618165243153993, 0.00303216804813299, -5.51581146266983e-08, 1.44109415817357e-09, 0.0336487468345765)), .Names = c(year, data), class = data.frame, row.names = c(NA, -5L)), site6 = structure(list( year = structure(1:6, .Label = c(2001, 2002, 2003, 2004, 2005, 2006), class = c(ordered, factor)), data = c(-6.33889022834333e-10, 1.34668283090261e-08, 4.17885398551684e-08, 0.00202872966966414, -3.82189201782033e-09, NaN)), .Names = c(year, data), class = data.frame, row.names = c(NA, -6L))), .Names = c(site1, site2, site3, site4, site5, site6)) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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,
Re: [R] maptools: Test if point is in polygon
I don't know about the maptools package but one general way to do this would be to compute the convex hull (?chull) of the augmented set of points and test if the point belongs to it. Hope this helps, baptiste On 5 Feb 2009, at 13:21, Aleksandr Andreev wrote: In R's maptools package, is there a built-in function to test if a given point is inside a given polygon on the map? The map was loaded from an ESRI Shapefile. The point's latitude and longitude are known. Thank you! Aleks -- Aleksandr Andreev Fulbright Fellow Graduate School of Management St Petersburg State University __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] seq(along= surprise
Perhaps this is what was intended? sims - list(length=100) do.call(seq, sims) seq by itself does not expect a list, but do.call() can create the appropriate call if a list is what you want to pass to the function. Hope this helps, baptiste On 5 Feb 2009, at 19:46, Uwe Ligges wrote: Uwe Ligges wrote: Kjetil Halvorsen wrote: This surprised me: reps - 100 sims - list(length=reps) sims $length [1] 100 for(i in seq(along=sims))print(i) [1] 1 This is R 2.8.1. What is surprising? sims is now a list that contains 1 element called length with a numeric value of 100. Then seq(along=sims) is exactly 1, because sims has length 1. Hence i is printed once (1 iteration of the loop) and is 1 in the first (and only) iteration. Uwe I should have added that you probably want sims - vector(mode=list, length=100) Uwe Kjetil [[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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] recursive derivative a list of polynomials
Dear list, This is quite a specific question requiring the package orthopolynom. This package provides a nice implementation of the Legendre polynomials, however I need the associated Legendre polynomial which can be readily expressed in terms of the mth order derivative of the corresponding Legendre polynomial. (For the curious, I'm trying to calculate spherical harmonics [*]). Because legendre.polynomials(l) returns a list of Legendre polynomials of degree 0 to l, I'd like to make use of the whole list of them at a time rather than wasting this information. For a given degree l I therefore have a list of l+1 polynomials. For each of these I want to compute l+1 derivatives, from m= 0 to m=l. The last step is to evaluate all of these polynomials with a vector argument and return a list of data.frames. I've come up with the following hack but it's really ugly, require(orthopolynom) md - function(.p, m=2){ test - list() if(.p==0) pl.list - rep(as.polylist(.p), m+1) else { pl.list - as.polylist(.p) for(n in seq(1, m+1)){ pl.list[[n+1]] - deriv(pl.list[[n]]) } } rev(pl.list) # ascending order } l - 3 # example theta - seq(0, pi, length= 10) # the variable to evaluate the polynomials at Pl - as.polylist(legendre.polynomials(l)) Plm - lapply(seq_along(Pl), function(ind) md(Pl[[ind]], ind-1)) Plm.theta - lapply(seq_along(Plm), function(ind) # treat each order l sapply(seq_along(Plm[[ind]]), function(ind2) # treat each order m (-1)^ind2 *(1-cos(theta)^2)^(ind2/2) * as.function(Plm[[ind]] [[ind2]])( cos(theta)) )) # evaluate the expression in theta I tried (unsuccessfully) to get inspiration from Recall() but since I want to store the intermediate derivatives it doesn't seem very suitable anyway. Any advice is welcome! [*] http://en.wikipedia.org/wiki/Spherical_harmonic _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fast fourier transformation
A powerful scheme for harmonic inversion of time signals known as filter diagonalization method is available from MIT: http://ab-initio.mit.edu/wiki/index.php/Harminv I don't know of any R interface, but it might be a good option for your problem. Cheers, baptiste On 10 Feb 2009, at 13:40, Dieter Menne wrote: botto b.otto at uke.uni-hamburg.de writes: here is a practical problem we would like to solve. In a pneumatic post the acceleration of the capsule is measured and plotted over time. From the graph achieved we would like to derive some kind of statistic value that describes the stress the capsule, or what is in it, is exhibited to. .. 1) Apply a fourier transformation to the acceleration profile to 2) get a number of harmonic waves describing my graph 3) and use the amplitudes of my waves in a weighted fashion to calculate some statistical value. What I tried to do is: A) construct an artificial profile fg for testing purpose like a. f1 - function(x) 0.5*sin(3*x + pi) X) in my test example I can define the amount of harmonic components, because here I know that number. Of course afterwards in my natural profiles I won't know. Y) I have to transform the values I get out of the fft and fourier functions to estimate the frequency, amplitude and phase of my harmonics. Check function spectrum in stats which also has some methods to provide smoothed plots. There is also package signal which I have not tried. And don't expect too much of phase plots, I have seen generations of students jumping on these to explain the universum, the EEG and US politics because it sound so mysterious, and never seen a working method coming out of it. It would have been good if you had provided a real example series because then it would have been possible to tell you if you could find a reasonable estimate of the true frequency and acceleration. In general, when you have only very few oscillations, you get a seemingly lousy estimate, which is only the consequence of how fft is defined as a rather broad-minded model. If you are sure that there is a single frequency with harmonics, other methods such as cyclic gams or even cyclic nlme (see the oestrus example in that package) might provide better results. Dieter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] general inverse solver?
In a different perspective the sage project might also be an option, it seems to interface to Maxima and R among other things. I haven't tested it myself though. http://www.sagemath.org/index.html Best wishes, baptiste PS: sagemath.org is a well-thought website, perhaps a good inspiration for the new design discussed recently? On 11 Feb 2009, at 07:56, Hans W. Borchers wrote: Gabor Grothendieck ggrothendieck at gmail.com writes: I am not sure what the point of all this is. The point of all this is: 1. Some users of R here on the list apparently would like to have more powerful CAS functionalities than Yacas can provide. 2. Many of the solution hints to Ryacas on this list were simply not solving the resp. problem, so the 80/20 statement of yours may be downright wrong. 3. Maxima does incorporate a socket server and can be integrated into other systems, see EULER (do you never listen?). What are you mourning about? Of course, it was great that you made available Yacas for R. But others have the right to discuss their wishes here w/o being 'slammed' every time with questionable hints to Ryacas. I agree arguments have been exchanged and we should stop here. After this discussion, I wish someone would think about an Rmaxima package (along the lines of EULER, e.g.), I cant do it, unfortunately. Hans Werner Borchers This is an R list, not a CAS list. The recommendation to use yacas is based on the fact that there is an interface between R and yacas. There is no interface between R and Maxima so Maxima is not in the running. Anyone who has used Maxima knows that is an impressive piece of software but that's not the point. Regarding, why there is no interface to Maxima, its because its harder to interface to Maxima than yacas. There are two problems here: 1. Maxima does not incorporate a socket server as far as I know. You would have to write it and that may or may not need an in depth understanding of Maxima to do so but in any case represents work. With yacas you don't have to write a server since yacas itself already contains a server. Just run: yacas --server .,. and the server side is done. (In the case of yacas it would also be possible to use its C interface for an in-process interface or presumably the java interface of the new java version of yacas. With Maxima it would be more problematic since its written in Lisp.) 2. Once you have created some sort of communications channel then what? If you want more than a crude interface that passes an unprocessed character string to the CAS and then passes one back then you will want to translate between R and the CAS. With yacas, OpenMath facilitates this greatly. The end result is that its more work to meaningfullly interface with Maxima than with yacas yet yacas satisfies the majority of needs of a CAS. There is the minority who need more powerful algorithms but I think it was a reasonable step to handle the 80% that can be accommodated most easily first by using yacas. The remaining 20%, which is what the other respondents to this thread are discussing will in part be addressed in the future possibly, in part, by the second project I am working on now. Perhaps some would quibble with the 80/20 and if you are in the 20 it probably seems like 100 but we will never settle that question definitively. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 in R
A somewhat twisted approach that has not been mentioned is to consider everything a comment unless it is enclosed in special tags, as done in the brew package, for example, brew(textConnection( You won't see this R output, but it will run. % foo - 'bar' % Now foo is %=foo% and today is %=format(Sys.time(),'%B %d, %Y') %. ) ) gives, You won't see this R output, but it will run. Now foo is bar and today is February 11, 2009. I'd love to see an editor with a brew mode that acts as a notebook: you type in your text in whatever language without worrying about the syntax (R syntax, i mean!), and when you want to do a calculation you just enclose it in such tags that behave like an inverted block comment. Just a thought, baptiste On 11 Feb 2009, at 12:17, Gabor Grothendieck wrote: I think you need to revisit the suggestion of how to use Tinn-R to ensure you are doing it properly. If its R code then if(FALSE) has already been mentioned as an alternative and another possibility is just enclose it in double quotes (or if there are double quotes in the passage then in single quotes): f - function(x) { here are some comments of mine x+1 } On Wed, Feb 11, 2009 at 3:32 AM, mihai.mira...@bafin.de wrote: Hi everybody, I use for the moment # at the begining of each line for comments. Is there any possibility to comment more than one line, like something which shows the beggingng and the end of the comment? Or is there a possibility to comment only a part of a line? Thanks, Mihai [[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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 in R
On 11 Feb 2009, at 13:41, Gustaf Rydevik wrote: On Wed, Feb 11, 2009 at 2:15 PM, baptiste auguie ba...@exeter.ac.uk wrote: A somewhat twisted approach that has not been mentioned is to consider everything a comment unless it is enclosed in special tags, as done in the brew package, for example, brew(textConnection( You won't see this R output, but it will run. % foo - 'bar' % Now foo is %=foo% and today is %=format(Sys.time(),'%B %d, %Y') %. ) ) gives, You won't see this R output, but it will run. Now foo is bar and today is February 11, 2009. I'd love to see an editor with a brew mode that acts as a notebook: you type in your text in whatever language without worrying about the syntax (R syntax, i mean!), and when you want to do a calculation you just enclose it in such tags that behave like an inverted block comment. Just a thought, baptiste Isn't this almost exactly what ?Sweave does? (and odfWeave). Granted, you have to deal with latex code to get nice output, but latex is a GoodThing (tm). LaTeX is indeed very good for some situations, but considering valid latex code to be a convenient format for mere code comments would be quite a stretch if you ask me. I like the light and flexible approach of brew(), it can in fact output latex code if if you feel like it. Or html. Or markdown. Or ... baptiste /Gustaf -- Gustaf Rydevik, M.Sci. tel: +46(0)703 051 451 address:Essingetorget 40,112 66 Stockholm, SE skype:gustaf_rydevik _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] two scatter plots in one
lattice and ggplot2 also offer a general way of doing this, # first create a data.frame in the long format containing the two data sets x1 - seq(-10, 10) x2 - seq(-8, 12) y1 - sin(x1/3) y2 - cos(x2/2) d1 - data.frame(x=x1, y=y1, var=1) d2 - data.frame(x=x2, y=y2, var=2) library(reshape) d - melt(merge(d1, d2, all=T), id=c(x, var)) # here goes the plotting in a high-level perspective library(ggplot2) qplot(x, value, data=d, geom=c(line,point), colour=var) or, library(lattice) xyplot(value ~ x, data=d, type=b, groups = var) On 12 Feb 2009, at 09:09, Jim Lemon wrote: liujb wrote: Dear R users, I need to compare two scatter plots, plot(x1, y1) plot(x2, y2) and would like to plot them in the same figure. How do I do it? Hi liujb, How about this: plot(x1,y1,xlim=range(c(x1,x2)),ylim=range(c(y1,y2)),col=red) points(x2,y2,col=blue) Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Multiple merge, better solution?
Hi, I think Reduce could help you. DF1 - data.frame(var1 = letters[1:5], a = rnorm(5)) DF2 - data.frame(var1 = letters[3:7], b = rnorm(5)) DF3 - data.frame(var1 = letters[6:10], c = rnorm(5)) DF4 - data.frame(var1 = letters[8:12], d = rnorm(5)) g - merge(DF1, DF2, by.x=var1, by.y=var1, all=T) g - merge(g, DF3, by.x=var1, by.y=var1, all=T) g - merge(g, DF4, by.x=var1, by.y=var1, all=T) test - Reduce(function(x, y) merge(x, y, all=T,by.x=var1, by.y=var1), list(DF1, DF2, DF3, DF4), accumulate=F) all.equal(test, g) # TRUE As a warning, it's the first time I've ever used it myself... Hope this helps, baptiste On 19 Feb 2009, at 10:21, Lauri Nikkinen wrote: Hello, My problem is that I would like to merge multiple files with a common column but merge accepts only two data.frames to merge. In the real situation, I have 26 different data.frames with a common column. I can of course use merge many times (see below) but what would be more sophisticated solution? For loop? Any ideas? DF1 - data.frame(var1 = letters[1:5], a = rnorm(5)) DF2 - data.frame(var1 = letters[3:7], b = rnorm(5)) DF3 - data.frame(var1 = letters[6:10], c = rnorm(5)) DF4 - data.frame(var1 = letters[8:12], d = rnorm(5)) g - merge(DF1, DF2, by.x=var1, by.y=var1, all=T) g - merge(g, DF3, by.x=var1, by.y=var1, all=T) merge(g, DF4, by.x=var1, by.y=var1, all=T) Thanks in advance. -Lauri __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Multiple merge, better solution?
Another option using Recall, merge.rec - function(.list, ...){ if(length(.list)==1) return(.list[[1]]) Recall(c(list(merge(.list[[1]], .list[[2]], ...)), .list[-(1:2)]), ...) } my.list - list(DF1, DF2, DF3, DF4) test2 - merge.rec(my.list, by.x=var1, by.y=var1, all=T) all.equal(test2, g) Note that your second example does not work because in the last step there are no common names between g and DF4 (I think). Using suffixes=c(, ) seems to do the trick but I'm not sure it's giving the result you want/expect. Hope this helps, baptiste On 19 Feb 2009, at 10:21, Lauri Nikkinen wrote: Hello, My problem is that I would like to merge multiple files with a common column but merge accepts only two data.frames to merge. In the real situation, I have 26 different data.frames with a common column. I can of course use merge many times (see below) but what would be more sophisticated solution? For loop? Any ideas? DF1 - data.frame(var1 = letters[1:5], a = rnorm(5)) DF2 - data.frame(var1 = letters[3:7], b = rnorm(5)) DF3 - data.frame(var1 = letters[6:10], c = rnorm(5)) DF4 - data.frame(var1 = letters[8:12], d = rnorm(5)) g - merge(DF1, DF2, by.x=var1, by.y=var1, all=T) g - merge(g, DF3, by.x=var1, by.y=var1, all=T) merge(g, DF4, by.x=var1, by.y=var1, all=T) Thanks in advance. -Lauri __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Multiple merge, better solution?
If you don't mind I've added this example to the R wiki, http://wiki.r-project.org/rwiki/doku.php?id=tips:data-frames:merge It would be very nice if a R guru could check that the information I put is not complete fantasy. Feel free to remove as appropriate. Best wishes, baptiste On 19 Feb 2009, at 11:00, Lauri Nikkinen wrote: Thanks, both solutions work fine. I tried these solutions to my real data, and I got an error Error in match.names(clabs, names(xi)) : names do not match previous names I refined this example data to look more like my real data, this also produces the same error. Any ideas how to prevent this error? DF1 - data.frame(var1 = letters[1:5], a = rnorm(5), b = rnorm(5), c = rnorm(5)) DF2 - data.frame(var1 = letters[3:7], a = rnorm(5), b = rnorm(5), c = rnorm(5)) DF3 - data.frame(var1 = letters[6:10], a = rnorm(5), b = rnorm(5), c = rnorm(5)) DF4 - data.frame(var1 = letters[8:12], a = rnorm(5), b = rnorm(5), c = rnorm(5)) g - merge(DF1, DF2, by.x=var1, by.y=var1, all=T) g - merge(g, DF3, by.x=var1, by.y=var1, all=T) merge(g, DF4, by.x=var1, by.y=var1, all=T) Error in match.names(clabs, names(xi)) : names do not match previous names DF - DF1 for ( .df in list(DF2,DF3,DF4) ) { + DF -merge(DF,.df,by.x=var1, by.y=var1, all=T) + } Error in match.names(clabs, names(xi)) : names do not match previous names Reduce(function(x, y) merge(x, y, all=T,by.x=var1, by.y=var1), list(DF1, DF2, DF3, DF4), accumulate=F) Error in match.names(clabs, names(xi)) : names do not match previous names - Lauri 2009/2/19 baptiste auguie ba...@exeter.ac.uk: Hi, I think Reduce could help you. DF1 - data.frame(var1 = letters[1:5], a = rnorm(5)) DF2 - data.frame(var1 = letters[3:7], b = rnorm(5)) DF3 - data.frame(var1 = letters[6:10], c = rnorm(5)) DF4 - data.frame(var1 = letters[8:12], d = rnorm(5)) g - merge(DF1, DF2, by.x=var1, by.y=var1, all=T) g - merge(g, DF3, by.x=var1, by.y=var1, all=T) g - merge(g, DF4, by.x=var1, by.y=var1, all=T) test - Reduce(function(x, y) merge(x, y, all=T,by.x=var1, by.y=var1), list(DF1, DF2, DF3, DF4), accumulate=F) all.equal(test, g) # TRUE As a warning, it's the first time I've ever used it myself... Hope this helps, baptiste On 19 Feb 2009, at 10:21, Lauri Nikkinen wrote: Hello, My problem is that I would like to merge multiple files with a common column but merge accepts only two data.frames to merge. In the real situation, I have 26 different data.frames with a common column. I can of course use merge many times (see below) but what would be more sophisticated solution? For loop? Any ideas? DF1 - data.frame(var1 = letters[1:5], a = rnorm(5)) DF2 - data.frame(var1 = letters[3:7], b = rnorm(5)) DF3 - data.frame(var1 = letters[6:10], c = rnorm(5)) DF4 - data.frame(var1 = letters[8:12], d = rnorm(5)) g - merge(DF1, DF2, by.x=var1, by.y=var1, all=T) g - merge(g, DF3, by.x=var1, by.y=var1, all=T) merge(g, DF4, by.x=var1, by.y=var1, all=T) Thanks in advance. -Lauri __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Insert value in a Vector Alternately
Perhaps you can try this, d - c(0.00377467, 0.00377467, 0.00377467, 0.00380083, 0.00380083, 0.00380083, 0.00380959, 0.00380959, 0.00380959, 0.00380083, 0.00380083, 0.00380083) c( t( cbind(matrix(d, ncol=3, byrow=T), 0))) I don't know how to avoid the transpose operation that might slow things down in large cases. Hope this helps, baptiste On 19 Feb 2009, at 12:47, jim holtman wrote: How about this: dat- c (0.00377467,0.00377467,0.00377467,0.00380083,0.00380083,0.00380083,0.00380959 , + 0.00380959,0.00380959,0.00380083,0.00380083,0.00380083) dat[seq(1, by=3, to=length(dat))] - 0 dat [1] 0. 0.00377467 0.00377467 0. 0.00380083 0.00380083 0. 0.00380959 0.00380959 0. 0.00380083 [12] 0.00380083 On Thu, Feb 19, 2009 at 1:47 AM, Gundala Viswanath gunda...@gmail.com wrote: Hi, I have a vector that look like this: dat V1 V2 V3 V4 V5 V6 0.00377467 0.00377467 0.00377467 0.00380083 0.00380083 0.00380083 V7 V8 V9V10V11V12 0.00380959 0.00380959 0.00380959 0.00380083 0.00380083 0.00380083 what I want to do is to insert 0 (zero) for every 3 position yielding: V1 V2 V3V4 V5V6 V7 V8 0 0.00377467 0.00377467 0.00377467 0 0.00380083 0.00380083 0.00380083 V9 V10 V11V12 V13V14 V15 V16 0 0.00380959 0.00380959 0.00380959 0 .00380083 0.00380083 0.00380083 Is there a quick way to do it in R? - Gundala Viswanath Jakarta - Indonesia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Insert value in a Vector Alternately
thanks all for the correction, funny how it's often the complicated solution that comes to mind first. baptiste On 19 Feb 2009, at 13:41, Eik Vettorazzi wrote: actually c(rbind(0,matrix(d, nrow=3))) which has the bonus of giving the desired result ;) baptiste auguie schrieb: Perhaps you can try this, d - c(0.00377467, 0.00377467, 0.00377467, 0.00380083, 0.00380083, 0.00380083, 0.00380959, 0.00380959, 0.00380959, 0.00380083, 0.00380083, 0.00380083) c( t( cbind(matrix(d, ncol=3, byrow=T), 0))) I don't know how to avoid the transpose operation that might slow things down in large cases. Hope this helps, baptiste On 19 Feb 2009, at 12:47, jim holtman wrote: How about this: dat- c (0.00377467,0.00377467,0.00377467,0.00380083,0.00380083,0.00380083,0.00380959 , + 0.00380959,0.00380959,0.00380083,0.00380083,0.00380083) dat[seq(1, by=3, to=length(dat))] - 0 dat [1] 0. 0.00377467 0.00377467 0. 0.00380083 0.00380083 0. 0.00380959 0.00380959 0. 0.00380083 [12] 0.00380083 On Thu, Feb 19, 2009 at 1:47 AM, Gundala Viswanath gunda...@gmail.com wrote: Hi, I have a vector that look like this: dat V1 V2 V3 V4 V5 V6 0.00377467 0.00377467 0.00377467 0.00380083 0.00380083 0.00380083 V7 V8 V9V10V11V12 0.00380959 0.00380959 0.00380959 0.00380083 0.00380083 0.00380083 what I want to do is to insert 0 (zero) for every 3 position yielding: V1 V2 V3V4 V5V6 V7 V8 0 0.00377467 0.00377467 0.00377467 0 0.00380083 0.00380083 0.00380083 V9 V10 V11V12 V13V14 V15 V16 0 0.00380959 0.00380959 0.00380959 0 .00380083 0.00380083 0.00380083 Is there a quick way to do it in R? - Gundala Viswanath Jakarta - Indonesia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Eik Vettorazzi Institut für Medizinische Biometrie und Epidemiologie Universitätsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/42803-8243 F ++49/40/42803-7790 _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] adding a reference line to an xyplot
Another approach using latticeExtra, more ggplot2-like: p - xyplot(matter~year|plot,type=l) p + latticeExtra::layer(panel.abline(v=1995)) On 20 Feb 2009, at 09:34, Chris Bennett wrote: Hi, I want to add a dashed vertical line to a number of xyplots. Here is a simple script of the type of plot I have but then I want to add a reference line to 1995 on each of the panels. I have tried panel.abline and other suggestions on the forum but can't get it to work. plot-rep(letters[1:3],each=10) year-rep(1991:2000,times=3) matter-rep(seq(2,6.5,0.5),times=3) xyplot(matter~year|plot,type=l) Cheers, Chris -- View this message in context: http://www.nabble.com/adding-a-reference-line-to-an-xyplot-tp22117545p22117545.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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] adding a reference line to an xyplot
Hi, try this: p - xyplot(matter~year|plot,type=l) update(p, panel=function(...){ panel.xyplot(...) panel.abline(v=1995) } ) On 20 Feb 2009, at 09:34, Chris Bennett wrote: Hi, I want to add a dashed vertical line to a number of xyplots. Here is a simple script of the type of plot I have but then I want to add a reference line to 1995 on each of the panels. I have tried panel.abline and other suggestions on the forum but can't get it to work. plot-rep(letters[1:3],each=10) year-rep(1991:2000,times=3) matter-rep(seq(2,6.5,0.5),times=3) xyplot(matter~year|plot,type=l) Cheers, Chris -- View this message in context: http://www.nabble.com/adding-a-reference-line-to-an-xyplot-tp22117545p22117545.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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 transfer a list of space delimited character elements into a char vector?
Hi, something like this perhaps, create_string - function(.s){ result - read.table(textConnection(.s)) sapply(result, as.character) } (test - create_string(ab cd ef)) hope this helps baptiste On 20 Feb 2009, at 16:38, Sean Zhang wrote: My dear R-helpers: I am a novice in R and have the following text string manipulation question. Is there a function that performs the job described below? Say, wanted_output - c(ab, cd, ef) #the function_wanted can generate c(ab, cd, ef) using ab cd ef as the single input argument wanted_output - function_wanted(ab cd ef) Motivation: I have a very long list of character elements (like, ab cd ef gg ww kwfl ..), I try to avoid typing , between two adjacent elements, typing in front of the first element, and typing right after the last element. when using them to generate a character vector. Many Thanks in advance. -Sean [[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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] line joining graphs
Paul Murrell's book provides such an example using Grid (figure 5.22). A short example is available on his website: http://www.stat.auckland.ac.nz/~paul/grid/doc/moveline.pdf It may be possible to use this in conjunction with gridBase. baptiste On 22 Feb 2009, at 20:43, Eik Vettorazzi wrote: hi, you can use par(xpd=TRUE) and draw the joining line in every sub graph - don't know if there is another way with simple graphs eg: par(mfcol=c(1,2)) plot(1,1,xlim=c(0,5),main=1st) op-par(xpd=TRUE) abline(h=1) plot(1,1,xlim=c(0,5),main=2nd) abline(h=1) hth. rajesh j schrieb: hi, I need to draw a line joining graphs,but abline stops within a graph.What do i do to cover portions between two graphs __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Modifying Names from (x,y] into x
Hi, I got this problem once, and Prof. Ripley kindly added an example in the help page of ?cut, aaa - c(1,2,3,4,5,2,3,4,5,6,7) ## one way to extract the breakpoints labs - levels(cut(aaa, 3)) cbind(lower = as.numeric( sub(\\((.+),.*, \\1, labs) ), upper = as.numeric( sub([^,]*,([^]]*)\\], \\1, labs) )) lower upper [1,] 0.994 3.00 [2,] 3.000 5.00 [3,] 5.000 7.01 Hope this helps, baptiste On 26 Feb 2009, at 02:55, Gundala Viswanath wrote: Hi, I have the following data that looks like this: names(dat) [1] (-2329,-2319] (-1399,-1389] (-669.4,-659.4] How can I modify those names into just this? [1] -2329 -1399 -669.4 - Gundala Viswanath Jakarta - Indonesia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ [[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] accessing and preserving list names in lapply
Hi, Perhaps Hadley's plyr package can help, library(plyr) temp - list(x=2,y=3,x=4) llply(temp, function(x) x^2 ) $x [1] 4 $y [1] 9 $x [1] 16 baptiste On 27 Feb 2009, at 03:07, Alexy Khrabrov wrote: Sometimes I'm iterating over a list where names are keys into another data structure, e.g. a related list. Then I can't use lapply as it does [[]] and loses the name. Then I do something like this: do.one - function(ldf) { # list-dataframe item key - names(ldf) meat - ldf[[1]] mydf - some.df[[key]] # related data structure r.df - cbind(meat,new.column=computed) r - list(xxx=r.df) names(r) - key r } then if I operate on the list L of those ldf's not as lapply(L,...), but res - lapply(1:length(L),do.one) Can this procedure be simplified so that names are preserved? Specifically, can the xxx=..., xxx - key part be eliminated -- how can we have a variable on the left-hand side of list(lhs=value)? Cheers, Alexy __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] rounding problem
Hi, you probably want to use ?all.equal instead of == I couldn't run your example, though Hope this helps, baptiste On 27 Feb 2009, at 10:32, Peterko wrote: hi i am creating some variables from same data, but somewhere is different rouding. look: P = abs(fft(d.zlato)/480)^2 hladane= sort(P,decreasing=T)[1:10]/480 pozicia=c(0,0,0,0,0) for (j in 1:5){ for (i in 2:239){ if (P[i]/480==hladane[2*j-1]){pozicia[j]=i-1}}} period=479/pozicia P[2]/334 [1] 0.0001279107 hladane[1] [1] 0.0001279107 P[2]/334==hladane[1] [1] FALSE abs(P[2]/334 - hladane[1]) 0.001 [1] TRUE It is possible to avoid it ? I know in this exam i can use 2x if to eliminate this rouding, but i need to fix it in general. -- View this message in context: http://www.nabble.com/rounding-problem-tp22243179p22243179.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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 a for loop with variable as vectors
Hi, you could do one of the following, 1) combine a, b, c, d, e in a list and use ?lapply my.list - list(a,b,c,d,e) lapply(my.list, foo) where foo() is a function to be applied to each individual element 2) alternatively, see ?get to retrieve the value of a variable from its name. Your loop would read, for ( r in c(a, b)) { t.test (y , get(r)) } (untested) Hope this helps, baptiste On 27 Feb 2009, at 20:12, Laura Lucia Prieto Godino wrote: Dear R users, I am completelly lost with the following: I have the following vectors a, b ,c, d and e + a [1] 279.3413 268.0450 266.3062 433.8438 305.4650 317.4712 288.3413 374.6950 b [1] 170.4500 254.5675 219.5762 232.3425 200.2738 238.2637 210.6062 262.4825 345.2387 269.3763 [11] 190.1225 259.7750 241.1350 265.8775 175.4162 206.4238 202.1738 151.1550 213.9900 225.5825 c [1] 278.6150 356.7738 426.5113 444.9538 335.2850 354.1463 526.6487 476.7912 503.7763 614.5300 [11] 504.4400 367.5537 485.6862 497.9550 d [1] 476.6212 525.3800 405.4200 372.8800 e [1] 428.4762 383.6587 184.6238 343.4737 306.7475 364.2300 441.0150 428.0275 389.0713 285.2125 [11] 396.0612 403.4787 375.4900 416.3575 543.3388 454.2475 430.1313 and I want to compare them in pair for significance with a t-test, so I wrote 2 for loops one inside the other, so that the variable of the for loop each of the for loop would be one of my vectors at a time, I wrote it like this #Test for normality shapiro.test(y) #Get the variables accessible. shapiro.test(y)-out attach(out) p.value #Perform a normal T-test if data is normal and a non-parametric one when the data are not normaly distributed for (r in expression(a,b,c,d,e)) { { if (p.value0.05) { print(y) print(T-Test_normal) print(paste(Today is, date())) print(t.test(y,r,alternative=greater)) } else { print(T-Test_wilcoxon) print(paste(Today is, date())) print(wilcox.test(y,r,alternative=greater)) } } } } But somehow it doesnt work,because it considers a,b,c,d,e as strings and not as the vectors I have defined, and I have no idea how to make a for loop in which it loops takes a variable. Can anyone help me? I am lost Thank you! Lucia [[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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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
If you have many such repetitions it can be annoying to type the rbind(cbind ... sequence. Perhaps this would help, m - read.table(textConnection( IndividualsValue A3 B4 C5 D2), head=T) data.frame(groups= rep(c(group1, group2, group3), each=nrow(m)), Ind=m[, 1], val=m[, 2]) You could also try Hadley's plyr package, rdply(3,m) # you might want to rename the column name and make(.n) a factor with adequate levels baptiste On 3 Mar 2009, at 14:28, David Winsemius wrote: Your data objects could not be matrices with that composition of values. Let's use the correct data type: df - data.frame(Ind = letters[1:4], val = sample(1:4, 4)) df Ind val 1 a 4 2 b 2 3 c 3 4 d 1 rbind(cbind(df,GruppeEin),cbind(df,GruppeZwei)) #v ariable recycling Ind val y 1 a 4 GruppeEin 2 b 2 GruppeEin 3 c 3 GruppeEin 4 d 1 GruppeEin 5 a 4 GruppeZwei 6 b 2 GruppeZwei 7 c 3 GruppeZwei 8 d 1 GruppeZwei is.data.frame(rbind(cbind(df,GruppeEin),cbind(df,GruppeZwei))) [1] TRUE -- David Winsemius On Mar 3, 2009, at 8:53 AM, Usuario R wrote: Hi all, I would like to transform to long format a matrix which has only information about individuals and a value for each individual. I would like to have it in ling format with more information related to groups, so ell values and individuals are repeated for each group. Let me show the example: matrix in wide format: IndividualsValue A3 B4 C5 D2 And long format would be like: IndividualsValueGroup A3Group1 B4Group1 C5Group1 D2Group1 A3Group2 B4Group2 C5Group2 D2Group2 My case is of course very large so i thought this could be possible with reshape function by adding a vector with the names of the groups or something like that. Thanks in advance. [[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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ggplot2: annotated horizontal lines
What's wrong with geom_text? my.value = 0.65 qplot(1,1)+geom_hline(v=0)+ geom_text(mapping=aes(x=1,y=0),label=paste(my.value),vjust=-1) baptiste On 3 Mar 2009, at 18:10, Dave Murray-Rust wrote: Hello, I'm using geom_hline to add a minimum line to my plot (representing the best solution found so far by a search algorithm). I'd like to annotate this line with it's numerical value to save trying to read it off the graph, but I can't see a clear way to do this - any ideas? (Alternatively, if this is against the spirit of the grammar of graphics, is there a better way to represent the information?) Cheers, dave -- The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ggplot2: annotated horizontal lines
I see your problem (although label should be outside the mapping in your case, i think). A possible workaround is to provide some dummy data, as the default NULL doesn't seem to work, qplot( wt, mpg, data=mtcars ) + geom_text(data=data.frame(x=0,y=0),mapping=aes(x=1,y=0),label=test) I'm sure Hadley will come up with a better explanation. Best, baptiste On 3 Mar 2009, at 19:51, Dave Murray-Rust wrote: On 3 Mar 2009, at 18:41, baptiste auguie wrote: What's wrong with geom_text? my.value = 0.65 qplot(1,1)+geom_hline(v=0)+ geom_text(mapping=aes(x=1,y=0),label=paste(my.value),vjust=-1) Well, firstly I hadn't thought to use it. Ooops. Secondly, I can't make it just do a single value - it seems to want a value for every point in the dataset, e.g.: qplot( wt, mpg, data=mtcars ) + geom_text(mapping=aes(x=1,y=0,label=paste(0.5),vjust=-1)) Error in data.frame(..., check.names = FALSE) : arguments imply differing number of rows: 1, 32 Cheers, dave baptiste On 3 Mar 2009, at 18:10, Dave Murray-Rust wrote: Hello, I'm using geom_hline to add a minimum line to my plot (representing the best solution found so far by a search algorithm). I'd like to annotate this line with it's numerical value to save trying to read it off the graph, but I can't see a clear way to do this - any ideas? (Alternatively, if this is against the spirit of the grammar of graphics, is there a better way to represent the information?) Cheers, dave -- The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ -- The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] advice on using this C code in R
Dear list, I'd like to ask for some advice in creating a wrapper function for this C code, http://www.fourmilab.ch/documents/specrend/ http://www.fourmilab.ch/documents/specrend/specrend.c I could probably port it in R, but I've been hoping to use compiled code for a while and this looks like a good test case. Unfortunately, the only success I've had so far is with the too simple factorial(int *n) function, http://math.acadiau.ca/ACMMaC/howtos/C_R.html Here, however, the code has several functions, some of which use structures as input variables and return several values. I've created a shared library with, R CMD SHLIB specrend.c and then ran, dyn.load('specrend.so') .C('spectrum_to_xyz', spec_intens=as.numeric(1), wavelength=as.numeric(1), x=numeric(1), y=numeric(1), z=numeric(1)) which obviously resulted in a nice crash, *** caught illegal operation *** address 0x942776, cause 'illegal opcode' Traceback: 1: .C(spectrum_to_xyz, spec_intens = as.numeric(1), wavelength = as.numeric(1), x = numeric(1), y = numeric(1), z = numeric(1)) Possible actions: 1: abort (with core dump, if enabled) 2: normal R exit 3: exit R without saving workspace 4: exit R saving workspace Selection: Looking at the C code I want to use, could you direct me to a beginner's tutorial for similar problems? Specifically: - how to deal with a function that returns several values (e.g xy_to_upvp here) - how to deal with structures (perhaps i needn't worry about this, I'm not sure) Many thanks, baptiste sessionInfo() R version 2.8.0 (2008-10-20) i386-apple-darwin8.11.1 locale: en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8 _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] fill the space between to lines
Hi, Try: polygon(c(x1, rev(x2)), c(y1, rev(y2)), col=grey) In general you might need to make sure the data is well ordered. Hope this helps, baptiste On 8 Mar 2009, at 16:52, Martin Batholdy wrote: hi, the code below produces me two curved lines. Now I want to fill the space between these curves with a color and I don't have any idea how to do that with R. I tried it with the polygon() function but it didn't worked out. Can someone her give me a hint on that? thanks! x1 - c(0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4, 1.5,1.6,1.7,1.8,1.9,2.0,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9, 3.0,3.1,3.2,3.3,3.4,3.5,3.6,3.7,3.8,3.9,4.0) x2 - c(0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4, 1.5,1.6,1.7,1.8,1.9,2.0,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9, 3.0,3.1,3.2,3.3,3.4,3.5,3.6,3.7,3.8,3.9,4.0) y1 - c(-0.04720997,0.04621043,0.13917323,0.23157407,0.32327960, 0.41411949,0.50387776,0.59228513,0.67901664,0.76370180, 0.84595616,0.92543926,1.00192864,1.07538026,1.14594154, 1.21390906,1.27965609,1.34356488,1.40598321,1.46720566, 1.52747146,1.58697039,1.64585138,1.70423095,1.76220039, 1.81983159,1.87718151,1.93429563,1.99121055,2.04795595, 2.10455610,2.16103096,2.21739711,2.27366841,2.32985649, 2.38597121,2.44202094,2.49801286,2.55395316,2.60984716, 2.66569949) y2 - c(0.5071367,0.5653217,0.6239643,0.6831689,0.7430687,0.8038342, 0.8656814,0.9288794,0.9937533,1.0606735,1.1300245,1.2021468, 1.2772628,1.3554166,1.4364607,1.5200986,1.6059570,1.6936536, 1.7828406,1.8732236,1.9645632,2.0566696,2.1493940,2.2426199, 2.3362558,2.4302300,2.5244855,2.6189767,2.7136672,2.8085272, 2.9035325,2.9986630,3.0939022,3.1892363,3.2846536,3.3801443, 3.4757000,3.5713134,3.6669785,3.7626899,3.8584430) plot(c(),c(),ylim=c(0,4),xlim=c(0,4)) lines(x1,y1,col=gray80,lwd=1.5) lines(x2,y2,col=gray80,lwd=1.5) [[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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Summary of data.frame according to colnames and grouping factor
Hi, You could use the reshape package: d$e - e recast(d, variable~e, fun=sum) The doBy package is another option. baptiste On 8 Mar 2009, at 17:14, soeren.vo...@eawag.ch wrote: A dataframe holds 3 vars, each checked true or false (1, 0). Another var holds the grouping, r and s: ### start:example set.seed(20) d - data.frame(sample(c(0, 1), 20, replace=T), sample(c(0, 1), 20, replace=T), sample(c(0, 1), 20, replace=T)) names(d) - c(A, B, C) e - rep(c(r, s), 10) ### end:example How do I get the count of 1's (or any other function) applied over each var according to the grouping? That is: Desired output table: A B C r count count count s......... or likewise transposed. I'd like to use the table for textual display and/or barplot creation. Thx, Sören -- Sören Vogel, PhD-Student, Eawag, Dept. SIAM http://www.eawag.ch, http://sozmod.eawag.ch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Merge 10 data frames with 3 id columns that are common to all data frames
Hi, Try this: DF1 - data.frame(var1 = letters[1:5], x = rnorm(5), y =2) DF2 - data.frame(var1 = letters[3:7], x = rnorm(5), y=3) DF3 - data.frame(var1 = letters[6:10], x = rnorm(5), y=0) # ... DF10 if you wish ( result - merge_all(list(DF1, DF2, DF3) )) save( result, file =merged.rda) I didn't know of this function, thanks. Similar solutions using base functions were proposed recently on http://wiki.r-project.org/rwiki/doku.php?id=tips:data-frames:merge and i've now added this for reference. baptiste On 8 Mar 2009, at 20:23, Pele wrote: Hi R users, Can anyone share some example code using merge_all (from the reshape package) to merge 10 data frames into 1 file. Thanks in advance for any help! -- View this message in context: http://www.nabble.com/Merge-10-data-frames-with-3-id-columns-that-are-common-to-all-data-frames-tp22402493p22402493.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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Merge 10 data frames with 3 id columns that are common to all data frames
The function expects a list of data.frames as a first argument but you provided a data.frame instead, the others are interpreted as optional arguments to merge_recurse(). Try this instead, merge_recurse(list(DF1,DF2,DF3,DF4)) var1x yt u d ef o 1a 1.39679 2 -1.18377 2 -0.041194 31 -1.05526 11 2b -0.20453 2 0.22777 2 -0.543270 31 1.45777 11 3c -0.91446 2 -0.97843 2 -1.279132 31 1.88759 11 4d -1.18069 2 -0.23963 2 -0.064799 31 -0.85747 11 5e -1.24802 2 1.43072 2 0.183317 31 2.50352 11 HTH, baptiste On 8 Mar 2009, at 23:40, Pele wrote: I tried using merge_all as shown below but I am getting an error ... can anyone tell me what I am doing wrong? The result table below is what I am looking for. DF1 - data.frame(var1 = letters[1:5], x = rnorm(5), y =2) DF2 - data.frame(var1 = letters[1:5], t = rnorm(5), u =2) DF3 - data.frame(var1 = letters[1:5], d = rnorm(5), e =31) DF4 - data.frame(var1 = letters[1:5], f = rnorm(5), o =11) DF_all - merge_all(DF1, DF2, DF3, DF4, by=var1 ) Error in fix.by(by.x, x) : 'by' must specify column(s) as numbers, names or logical Results I would like var1x y d e t u x a -1.725155 2 -0.4809731 0.0329682 -1.725155 b 0.7999832 2.32965 31 -0.385364 2 0.799983 c -1.387224 2 0.61761 31 0.9774042 -1.387224 d 0.6459462 0.46152 31 1.3345912 0.645946 e 0.0587832 -0.2531231 0.6316762 0.058783 baptiste auguie-2 wrote: Hi, Try this: DF1 - data.frame(var1 = letters[1:5], x = rnorm(5), y =2) DF2 - data.frame(var1 = letters[3:7], x = rnorm(5), y=3) DF3 - data.frame(var1 = letters[6:10], x = rnorm(5), y=0) # ... DF10 if you wish ( result - merge_all(list(DF1, DF2, DF3) )) save( result, file =merged.rda) I didn't know of this function, thanks. Similar solutions using base functions were proposed recently on http://wiki.r-project.org/rwiki/doku.php?id=tips:data-frames:merge and i've now added this for reference. baptiste On 8 Mar 2009, at 20:23, Pele wrote: Hi R users, Can anyone share some example code using merge_all (from the reshape package) to merge 10 data frames into 1 file. Thanks in advance for any help! -- View this message in context: http://www.nabble.com/Merge-10-data-frames-with-3-id-columns-that-are-common-to-all-data-frames-tp22402493p22402493.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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/Merge-10-data-frames-with-3-id-columns-that-are-common-to-all-data-frames-tp22402493p22404595.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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 write a function that accepts unlimited number of input arguments?
Hi, On 9 Mar 2009, at 15:32, Sean Zhang wrote: Dear R-helpers: I am an R newbie and have a question related to writing functions that accept unlimited number of input arguments. it's usually through the ... argument, e.g in paste(...). (I tried to peek into functions such as paste and cbind, but failed, I cannot see their codes..) simply type their name in the R prompt paste function (..., sep = , collapse = NULL) .Internal(paste(list(...), sep, collapse)) environment: namespace:base etc... but that's not very useful here. Can someone kindly show me through a summation example? Say, we have input scalar, 1 2 3 4 5 then the ideal function, say sum.test, can do (1+2+3+4+5)==sum.test(1,2,3,4,5) see ?Reduce for one way to do this: add - function(x) Reduce(+, x) add(list(1, 2, 3)) Also sum.test can work as the number of input scalar changes. Many thanks in advance! -sean [[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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to write a function that accepts unlimited number of input arguments?
On 9 Mar 2009, at 16:04, Sean Zhang wrote: Dear Baptiste: Many thanks for your help! Using the Reduce way, it works almost perfectly. I ran into this problem when thinking of appending vectors. Is it possible to not use list() within add() so add(vec1,vec2,vec3) below can work? add - function(...) Reduce(+, list(...)) add(1, 2, 3) Also, do you have some quick hints on using '...'? Many Thanks in advance. I'm not sure of a good reference for this. I'd strongly suggest you read the Introduction to R manual ( also check the R project webpage for many other resources). Also, it'd be better if you could Cc R-help next time you ask for further information. Hope this helps, baptiste vec1-c(0,1) vec2-c(2,3) vec3-c(4,5) add - function(x) Reduce(append, x) add(list(vec1, vec2)) #add(vec1,vec2) does not work at the moment -sean On Mon, Mar 9, 2009 at 11:50 AM, baptiste auguie ba...@exeter.ac.uk wrote: Hi, On 9 Mar 2009, at 15:32, Sean Zhang wrote: Dear R-helpers: I am an R newbie and have a question related to writing functions that accept unlimited number of input arguments. it's usually through the ... argument, e.g in paste(...). (I tried to peek into functions such as paste and cbind, but failed, I cannot see their codes..) simply type their name in the R prompt paste function (..., sep = , collapse = NULL) .Internal(paste(list(...), sep, collapse)) environment: namespace:base etc... but that's not very useful here. Can someone kindly show me through a summation example? Say, we have input scalar, 1 2 3 4 5 then the ideal function, say sum.test, can do (1+2+3+4+5)==sum.test(1,2,3,4,5) see ?Reduce for one way to do this: add - function(x) Reduce(+, x) add(list(1, 2, 3)) Also sum.test can work as the number of input scalar changes. Many thanks in advance! -sean [[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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ [[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] system() not accepting strings from cat()
try ?paste baptiste On 10 Mar 2009, at 20:01, ig2ar-s...@yahoo.co.uk wrote: Hi again R-ists, How do you construct a string that you can pass to system()? For instance. Say I do system(echo Hello!) Hello! That works. Now the alternative: I need to construct the string like this a - echo b - Hello! c - \n cat(a, b, c) echo Hello! Looks nice... but see what happens when I try to use it system(cat(a, b, c)) echo Hello! Error in system(command, intern) : non-empty character argument expected I have googled extensively in and out of r-lists but I can't find a solution. Can anybody help? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] lattice contourplot background covers inward-facing ticks
I believe you can simply modify the panel function to replot the axes on top with panel.axis(), library(lattice) model - function(a,b,c,d,e, f, X1,X2) # provide model function # for contour plot {J - a + (b*X1) + (c*X2) + (d*X1*X2) + e*(X1^2) + f*(X2^2) pp - exp(J)/(1+exp(J)) return(pp)} g - expand.grid(X1= seq(0.3,0.9,0.01), X2 = seq(0.3,1, 0.01)) g$z - model(-29, -14, 52, 80, -3, -56, g$X1, g$X2) # Create # variable z using gridded data, model, and variables contourplot(z ~ X1 * X2,panel=function(...){panel.levelplot(...); panel.axis(bottom, half = FALSE,labels=F) panel.axis(left, half = FALSE,labels=F) }, data = g, region = TRUE, # Adds color to background cuts = 10, # Number of contour intervals...(and color # intervals!) scales = list(tck = c(-1,-1)) # ticks go inward ) ### END Hope this helps, baptiste On 24 Nov 2008, at 16:35, Seth W Bigelow wrote: I wish to have inward-pointing ticks on my contourplot graph, but the colored background produced by the region=TRUE statement covers the ticks up, is there any way around this? Sample code below. --Seth library(lattice) model - function(a,b,c,d,e, f, X1,X2) # provide model function for contour plot {J - a + (b*X1) + (c*X2) + (d*X1*X2) + e*(X1^2) + f*(X2^2) pp - exp(J)/(1+exp(J)) return(pp)} g - expand.grid(X1= seq(0.3,0.9,0.001), X2 = seq(0.3,1, 0.001)) g$z - model(-29, -14, 52, 80, -3, -56, g$X1, g$X2) # Create variable z using gridded data, model, and variables contourplot(z ~ X1 * X2, data = g, region = TRUE, # Adds color to background cuts = 10, # Number of contour intervals...(and color intervals!) scales = list(tck = c(-1,-1)) # ticks go inward ) ### END [[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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] align two lattice plots with grid
Dear list, I need to align two plots on top of each other for comparison (they only have the x-axis in common). When the y-labels have a different extent, I cannot find a way to align the x-axes, as illustrated below, library(grid) library(lattice) x - seq(0, 10, length=100) y - sin(x) y2 - 10*sin(x) f - rep(c(1, 2), each=50) p1 - xyplot(y~x,groups=f, ylab=BIG LABEL, # auto.key=list(space=right), par.settings = list(layout.width = list(panel=1, ylab = 2, axis.left =1.0, left.padding=1, ylab.axis.padding=1, axis.panel=1))) p2 - xyplot(y2~x, ylab=a, par.settings = list(layout.width = list(panel=1, ylab = 2, axis.left =1.0, left.padding=1, ylab.axis.padding=1, axis.panel=1))) pushViewport(viewport(layout=grid.layout(nrow = 2, ncol = 1 , widths=unit(6, inches), heights=unit(c(3, 2), inches pushViewport(viewport(layout.pos.col=1, layout.pos.row=1, just=center, name = top)) print(p1, newpage=F, panel.width=list(4, inches), panel.height=list(2.5, inches)) upViewport() pushViewport(viewport(layout.pos.col=1, layout.pos.row=2, just=center, name = bottom)) print(p2, newpage=F, panel.width=list(4, inches), panel.height=list(1.5, inches)) upViewport() Any help would be greatly appreciated! baptiste _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help with lattice graphics
Hi, The main difference I saw between your two graphs was the stacking, which you can obtain by stack=TRUE in lattice. I'm not sure what cosmetic issues you had in mind. Perhaps you can try this, barchart(y~dfb|dfyr,dataf,layout=c(3,1),stack=T,ylim=c(0, 2.7), groups=dfa, strip = strip.custom(var.name=year, strip.names = c(TRUE, TRUE)), scales=list(x=list(rot=0), y=list(axs=i, at=seq(0, 2.5, by=0.5))), par.settings=list(axis.text=list(font=2,cex=0.75), par.ylab.text=list(font=2,cex=1.0), par.xlab.text=list(font=2,cex=1.0), par.main.text=list(font=2,cex=1.0)), xlab=b, ylab=y,auto.key = list(space=top, columns=length(levels(dataf$dfa))), main=A test lattice plot) Baptiste On 1 Dec 2008, at 18:30, ravi wrote: Hi, I like the formatting and the appearance of lattice plots. But I have not succeeded in gettting the right format in my plots with the lattice package in one of my applications. In the code shown below, I start by constructing a general data frame and show my attempts with the lattice package commands. After that, I use the graphics package and show the kind of plot that I want to get. I would like to know how the lattice commands can be modified to get the final plot that I have obtained with the graphics package. Any explanatory comments to understand better the modifications are most welcome. Here is my code : ## rm(list=ls()) # make up a test data frame with 4 columns # factors in first 3 cols and a numeric in the 4th vec_a-paste(A,1:4,sep=(''));na-length(vec_a) vec_b-paste(B,1:5,sep=(''));nb-length(vec_b) yr-c(2007,2008,2009);ny-length(yr) fac_a-factor(vec_a);fac_b-factor(vec_b);fac_yr-factor(yr) n-na*nb*ny # y is the response variable y-runif(n);y-round(y,digits=1) dfa-rep(fac_a,times=nb*ny) dfb-rep(fac_b,each=na,times=ny) dfyr-rep(fac_yr,each=na*nb) dataf-data.frame(dfa=dfa,dfb=dfb,dfyr=dfyr,y=y);head(dataf) # dataf is the test data frame # First test with the lattice package library(lattice) barchart(y~dfb|dfyr,dataf,layout=c(3,1),beside=FALSE, groups=dfa, scales=list(x=list(rot=90)), par.settings=list(axis.text=list(font=2,cex=0.75), par.ylab.text=list(font=2,cex=1.0), par.xlab.text=list(font=2,cex=1.0), par.main.text=list(font=2,cex=1.0)), xlab=b, ylab=y, main=A test lattice plot) ## lattice code doesn't give the desired plot ## Next try with the graphics package ## Seems to be easier to get the desired plot ##First, some preprocessing of data df2007-dataf[dfyr==2007,];df2008-dataf[dfyr==2008,];df2009- dataf[dfyr==2009,]; y2007-matrix(df2007$y,ncol=nb,nrow=na) y2008-matrix(df2008$y,ncol=nb,nrow=na) y2009-matrix(df2009$y,ncol=nb,nrow=na) colnames(y2007)-vec_b;colnames(y2008)-vec_b;colnames(y2009)-vec_b; rownames(y2007)-vec_a;rownames(y2008)-vec_a;rownames(y2009)-vec_a; ysmax-ceiling(max(colSums(y2007),colSums(y2008),colSums(y2009)))+1 ## Now, let's plot the combination of plots desired as a lattice plot col_choice=c(blue, brown,lightgreen, mistyrose) par(mfrow=c(1,3),mar=c(5,5,5,2)) barplot(y2007,col = col_choice, beside=F,xlab=fac_b,ylab=y,main=year 2007, font.axis=2,font.lab=2,cex.lab=1.5,cex.axis=1.2,ylim=c(0,ysmax)) legend(x=1,y=ysmax,legend=vec_a,fill = col_choice) barplot(y2008,col = col_choice, beside=F,xlab=fac_b,main=year 2008, font.axis=2,font.lab=2,cex.lab=1.5,cex.axis=1.2,ylim=c(0,ysmax)) barplot(y2009,col =col_choice, beside=F,xlab=fac_b,main=year 2009, font.axis=2,font.lab=2,cex.lab=1.5,cex.axis=1.2,ylim=c(0,ysmax)) par(mfrow=c(1,1)) ## Can we get the same plot with the lattice package? ## I would like to have the legend on the top in one row ## Thanking You, Ravi __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] align two lattice plots with grid
Many thanks, this tool from latticeExtra does exactly what I was trying to achieve! Best wishes, Baptiste On 1 Dec 2008, at 20:06, Deepayan Sarkar wrote: In general, the latticeExtra package has some tools to combine arbitrary trellis objects (thanks to Felix Andrews): library(latticeExtra) update(c(p2, p1, x.same = TRUE), layout = c(1, 2), ylab = list(c(a, BIG LABEL), y = c(1/6, 2/3)), par.settings = list(layout.heights = list(panel = c(1, 2 -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] legend idea for latticeExtra
Dear list, I've written a small utility function to add arbitrary legend(s) to a lattice graph (or a combination of them), much like the legend function of base graphics. I though perhaps it could be useful to someone else, or improved by suggestions. I understand this goes against the lattice paradigm somewhat, in that you short-cut the link between group variables and the appearance of the legend. There are some cases where I was missing this kind of raw command, though, and the custom legend dendrogram of the lattice book is intimidating if not a bit overkill. llegend - function(x=0.5, y=0.5, loc=FALSE, text=c(a, b), unit=npc, pch=1, lty=NULL, col=seq_along(text), cex=0.6, cex.title=0.8, ...){ if(loc) { ll - grid.locator(unit) print(ll) x - as.numeric(ll$x) y - as.numeric(ll$y) } lines - !is.null(lty) points - !is.null(pch) keyGrob - draw.key(key=simpleKey(text, lines=lines, points = points,cex=cex, cex.title=cex.title, ...), vp=viewport(x=unit(x, unit), y=unit(y, unit)), draw=F) grid.draw(keyGrob) invisible(keyGrob) } # example (locator used for the second legend) xyplot(1~1) llegend() llegend(loc=T, title=Here goes another) # click wherever on the viewport. Best wishes, baptiste _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] French IRC channel and mailing list ?
A few personal thoughts on this: I recently joined a newly created R user group on google http://groups.google.co.uk/group/gur-ugr that started with a similar impulse. In my personal opinion, I see little overall benefit from such an approach. For one thing, a major strength of the R mailing list is the large number of very knowledgeable persons. A mailing list with only a few 10s of users will never provide as good a support as you can find in the main list. The advice you get could very easily be biased or even plain wrong without much of a peer-review, so to say. Another thing to consider is whether people who can help and understand french actually want to answer a question in french, thereby limiting their advice to a much narrower audience (people facing a similar problem subsequently may be unable to get help from an answer in this language). Perhaps even more likely is the opposite situation where the question has been solved many times in the main mailing list: it can be quite tempting to just send the link and say, well, here is the solution, let me know what you don't understand rather than doing a translator's job. Solving an R problem and translating somebody's text have very unequal appeal. I don't know what the exact policy is for this mailing list (a search for english in the posting guide didn't return anything). Perhaps it is OK to send the occasional question in french, or franglais. I know I don't mind seeing a few of these and answering them if I can, while I would not join a new list for the reasons stated above. This would have the advantage of keeping the knowledge together. Maybe a special tag could be used so that people not interested can filter out all questions posted in non-english languages. Best wishes, Baptiste On 8 Dec 2008, at 21:10, Julien Barnier wrote: Dear all, For some time now, R is becomming more and more popular in more and more countries. France is for sure one of them, but french people being french one of the obstacle they might tackle is the lack of documentation and support in their native language. To offer this support in french an IRC channel (#Rfr on irc.freenode.net) was created some months ago, beside the official english channel #R. We (me (~juba) and Pierre-Yves Chibon (~pingou)) have to recognize that it has a very low activity right now but it's related to our lack of promotion about it. Another tool that could be useful to bring support in french (and other languages) would be dedicated mailing-lists. I've searched the archives to see if similar requests have already been made but couldn't manage to find one. So I would like to ask here the question, has there been any thought on the creation of dedicated R-help mailing-lists for the major languages such as Spanish, French, Chinese and others ? We had some thought about it and we actually think that it would be something useful for users to be able to receive some help (especially when their english is not really fluent). Thanks in advance for your answers, Sincerely, Pierre-Yves Chibon Julien Barnier __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Multpile (45x8) graphs of the same page / device: titles crammed
Hi, font should be an integer as described in ?par. I think you want to play with cex.main (possibly cex in combination, depending on what your are plotting) x - seq(0, 10) pdf(width=8, height=20) par(mfrow=c(45, 8), mai=c(0,0.1,0.1,0)) sapply(1:(45*8), function(ii) { plot(x, rnorm(x)) title(paste(test, ii), cex.main=0.5) }) - b.quiet dev.off() Hope this helps, baptiste On 10 Dec 2008, at 13:42, tsunhin wong wrote: Dear R users, I'm trying to plot 45x8 graphs on the same pdf / device for the sake of visual comparison. par(mfcol=c(45,8)) par(mai=c(0,0,0,0)) In ?title, I can see there are cex and font settings: I set cex = 0.01 and font = 1: it is still very large, and then I tried setting font 1, e.g. font = 0.5, Then I get an error: Error in title(paste(Ppercent, % , t30v2msa1.data, sep=), cex = 0.1, : invalid value specified for graphical parameter font Is there a work around so that I can see all the title? At the moment, if I set the title to font=1, the upper halves of the fonts / letters of all the title will be cut, so I can't see the Ppercent... Thanks! Regards, John __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] tapply within a data.frame: a simpler alternative?
Dear list, I have a data.frame with x, y values and a 3-level factor group, say. I want to create a new column in this data.frame with the values of y scaled to 1 by group. Perhaps the example below describes it best: x - seq(0, 10, len=100) my.df - data.frame(x = rep(x, 3), y=c(3*sin(x), 2*cos(x), cos(2*x)), # note how the y values have a different maximum depending on the group group = factor(rep(c(sin, cos, cos2), each=100))) library(reshape) df.melt - melt(my.df, id=c(x,group)) # make a long format df.melt - df.melt[ order(df.melt$group) ,] # order the data.frame by the group factor df.melt$norm - do.call(c, tapply(df.melt$value, df.melt$group, function(.v) {.v / max(.v)})) # calculate the normalised value per group and assign it to a new column library(lattice) xyplot(norm + value ~ x,groups=group, data=df.melt, auto.key=T) # check that it worked This procedure works, but it feels like I'm reinventing the wheel using hammer and saw. I tried to use aggregate, by, ddply (plyr package), but I coudn't find anything straight-forward. I'll appreciate any input, Baptiste _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] tapply within a data.frame: a simpler alternative?
Excellent! I completely forgot its name and existence. Perhaps ave should be mentioned on the help page of either by, tapply, split. Many thanks, baptiste On 10 Dec 2008, at 17:20, Chuck Cleland wrote: On 12/10/2008 12:02 PM, baptiste auguie wrote: Dear list, I have a data.frame with x, y values and a 3-level factor group, say. I want to create a new column in this data.frame with the values of y scaled to 1 by group. Perhaps the example below describes it best: x - seq(0, 10, len=100) my.df - data.frame(x = rep(x, 3), y=c(3*sin(x), 2*cos(x), cos(2*x)), # note how the y values have a different maximum depending on the group group = factor(rep(c(sin, cos, cos2), each=100))) library(reshape) df.melt - melt(my.df, id=c(x,group)) # make a long format df.melt - df.melt[ order(df.melt$group) ,] # order the data.frame by the group factor df.melt$norm - do.call(c, tapply(df.melt$value, df.melt$group, function(.v) {.v / max(.v)})) # calculate the normalised value per group and assign it to a new column library(lattice) xyplot(norm + value ~ x,groups=group, data=df.melt, auto.key=T) # check that it worked This procedure works, but it feels like I'm reinventing the wheel using hammer and saw. I tried to use aggregate, by, ddply (plyr package), but I coudn't find anything straight-forward. with(my.df, ave(y, group, FUN = function(x){x/max(x)})) ?ave I'll appreciate any input, Baptiste _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] tapply within a data.frame: a simpler alternative?
On 10 Dec 2008, at 17:25, hadley wickham wrote: On Wed, Dec 10, 2008 at 11:02 AM, baptiste auguie [EMAIL PROTECTED] wrote: Dear list, I have a data.frame with x, y values and a 3-level factor group, say. I want to create a new column in this data.frame with the values of y scaled to 1 by group. Perhaps the example below describes it best: x - seq(0, 10, len=100) my.df - data.frame(x = rep(x, 3), y=c(3*sin(x), 2*cos(x), cos(2*x)), # note how the y values have a different maximum depending on the group group = factor(rep(c(sin, cos, cos2), each=100))) library(reshape) df.melt - melt(my.df, id=c(x,group)) # make a long format df.melt - df.melt[ order(df.melt$group) ,] # order the data.frame by the group factor df.melt$norm - do.call(c, tapply(df.melt$value, df.melt$group, function(.v) {.v / max(.v)})) # calculate the normalised value per group and assign it to a new column library(lattice) xyplot(norm + value ~ x,groups=group, data=df.melt, auto.key=T) # check that it worked This procedure works, but it feels like I'm reinventing the wheel using hammer and saw. I tried to use aggregate, by, ddply (plyr package), but I coudn't find anything straight-forward. It's pretty easy with ddply: df.melt - ddply(df.melt, .(group), transform, norm = y / max(y)) Hadley -- http://had.co.nz/ Very nice indeed! My test failed as I somehow misunderstood the syntax and didn't think of applying transform(). Many thanks too, baptiste __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] line length in legend
From the code of legend() the length seems to be hard-wired (seg.len = 2). You could copy the code and add this seg.len as a free parameter in your own custom function. An alternative is to use the lattice package which has a size argument for this purpose. See ? xyplot in the key section. Hope this helps, baptiste On 10 Dec 2008, at 17:37, Gabor Grothendieck wrote: Perhaps you could just place the labels right on the graphs: library(zoo) z - as.zoo(window(EuStockMarkets, end = 1992)) plot(z, screen = 1) text(time(z)[1], z[1], colnames(z), cex = .6) On Wed, Dec 10, 2008 at 11:58 AM, Giovanni Petris [EMAIL PROTECTED] wrote: Hello, Is it possible to set the length of the lines appearing in a legend? For example, with plot(window(EuStockMarkets, end = 1992), plot.type = s, lty = c(13, 6413, 431313, B4)) legend(1991.7, 2200, legend = colnames(EuStockMarkets), lty = c(13, 6413, 431313, B4)) I end up with a legend in which the dot-dash patterns of the different line types are hard to distinguish. With a longer piece of line that would be easier. Thank you in advance, Giovanni -- Giovanni Petris [EMAIL PROTECTED] Associate Professor Department of Mathematical Sciences University of Arkansas - Fayetteville, AR 72701 Ph: (479) 575-6324, 575-8630 (fax) http://definetti.uark.edu/~gpetris/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ref card for data manipulation?
Hi, Good idea, what do you say we try and write a page on this in the R wiki? I started the topic: http://wiki.r-project.org/rwiki/doku.php?id=guides:overview-data-manip Once the content is there, it wouldn't be much of an effort to create a reference-card format if required. Best wishes, baptiste On 11 Dec 2008, at 12:38, Vitalie Spinu wrote: On Wed, 10 Dec 2008 18:29:43 +0100, Peter Dalgaard [EMAIL PROTECTED] wrote: You (as many before you) have overlooked the ave() function, which can replace the ordering as well the do.call(c,tapply()) Majority of questions on this list concern data manipulation. Many are repetitive. Overlooking like that will always happen unless some comprehensive data manipulation documentation is made. I think many people would benefit if a specialized data.manip ref.card were conceived. Tom Short's card is an excellent one but it does not cover high level packages like plyr, reshape, DoBy, and a few base data.manip functions are not there as well. Vitalie. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] generate combination multiset (set with repetition)
Hi, Perhaps you can use expand.grid and then remove the mirror combinations, values - 1:3 tmp - expand.grid(values, values) unique.combs - tmp[tmp[, 1]=tmp[, 2], ] unique.combs[do.call(order, unique.combs), ] # reorder if you wish Var1 Var2 111 412 713 522 823 933 I vaguely recall a discussion a few months ago on extending this approach to a variable number of arguments to expand.grid. Hope this helps, baptiste On 11 Dec 2008, at 17:00, Reuben Cummings wrote: Hi, This has been asked before but not sufficiently answered from what I could find. How do you create combinations with repetitions (multisets) in R? If I have set - array(1:3) And I want to choose all combinations of picking 2 numbers, I want to get a print out like [,1] [,2] [1,]11 [2,]12 [3,]13 [4,]22 [5,]23 [6,]33 subsets(set, 2, allow.repeat=T) should work, but I can't get the multic package to install, t(combn(set,2)) was suggested but it doesn't produce repetitions; expand.grid(rep(list(1:3), 2)) was also suggested, but it produces permuations, not combinations. Additionally, I would like to iterate through each resultant set for large n (similar to the description for getNextSet {pcalg}). Any suggestions? Reuben Cummings __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 merge list of dataframes?
have you tried do.call(rbind, aa) , or perhaps do.call(merge, aa) ? Hope this helps, baptiste On 15 Dec 2008, at 13:23, 江文恺 wrote: Dear all: I have a list of dataframes like this, i try to merge this lists of dataframes into one single dataframe, and keep ther column names as usual, how can i do this? i try lapply(aa,rbind), but it dose not work. Best regard! summary(aa) Length Class Mode [1,] 3 data.frame list [2,] 3 data.frame list [3,] 3 data.frame list [4,] 3 data.frame list [5,] 3 data.frame list [6,] 3 data.frame list [7,] 3 data.frame list ... aa[1] [[1]] b p d 11 pair1 1.07293 21 pair2 1.74022 31 pair3 4.17572 41 pair4 1.52449 51 pair5 1.63937 61 pair6 4.36470 81 pair8 1.17507 10 1 pair10 0.41672 11 1 pair11 3.62334 aa[2] [[1]] b p d 13 2 pair13 1.12680 14 2 pair14 1.41834 15 2 pair15 1.94462 16 2 pair16 4.97495 17 2 pair17 2.49566 18 2 pair18 6.76947 19 2 pair19 1.81448 20 2 pair20 6.25511 aa[3] [[1]] bp d 21 3 pair21 2.67789 22 3 pair22 1.57610 24 3 pair24 0.63215 25 3 pair25 0.79549 26 3 pair26 1.71219 27 3 pair27 39.29264 _ [[elided Hotmail spam]] [[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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] passing arguments to subset from a function
I wrote a dirty hack last time I faced this problem, I'll be curious to see what is the proper way of dealing with the scoping and evaluation rules. library(datasets) myfunction-function(table, extraction) { table2-subset(table,extraction) return(table2) } condition1 - quote(iris$Species==setosa) # I'm not sure how to evaluate within the environment, perhaps you could use with(table, subset(table, extraction) ) in your function condition2 - bquote(.(condition1) iris$Sepal.Width 3.5) # say, if you want to concatenate several conditions together myfunction(iris, extraction= eval(condition1)) myfunction(iris, extraction= eval(condition2)) Best wishes, baptiste On 17 Dec 2008, at 19:07, GOUACHE David wrote: Hello R-helpers, I'm writing a long function in which I manipulate a certain number of datasets. I want the arguments of said function to allow me to adapt the way I do this. Among other things, I want my function to have an argument which I will pass on to subset() somewhere inside my function. Here is a quick and simplified example with the iris dataset. myfunction-function(table, extraction) { table2-subset(table, extraction) return(table2) } myfunction(iris, extraction= Species==setosa) ## end What I would like is for this function to return exactly the same thing as : subset(iris, Species==setosa) Thanks for your help. Regards, David Gouache __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Componentwise means of a list of matrices?
I thought this was a good candidate for the plyr package, but it seems that l*ply functions are meant to operate only on separate list elements: Lists are the simplest type of input to deal with because they are already naturally divided into pieces: the elements of the list. For this reason, the l*ply functions dont need an argument that describes how to break up the data structure. (from: plyr: divide and conquer, Hadley Wickham 2008) Perhaps a new case to consider? Best wishes, baptiste On 30 Dec 2008, at 15:33, Stephan Kolassa wrote: Dear useRs, I have a list, each entry of which is a matrix of constant dimensions. Is there a good way (i.e., not using a for loop) to apply a mean to each matrix entry *across list entries*? Example: foo - list(rbind(c(1,2,3),c(4,5,6)),rbind(c(7,8,9),c(10,11,12))) some.sort.of.apply(foo,FUN=mean) I'm looking for a componentwise mean across the two entries of foo, i.e., the following output: [,1] [,2] [,3] [1,]456 [2 _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ [[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] Componentwise means of a list of matrices?
In fact, when writing my post I tried to do exactly what you did in creating a 3d array from the list, and I failed miserably! This is (imho) partly because the syntax is not very clean or straightforward as compared to the apply and *ply family. A list of matrices with equal dimensions is easily produced by mapply(... , simplify=F), or lapply, while an array needs to be created in a more verbose manner (as far as i know, some version of a loop). I just remembered the abind package which makes this a bit easier, although the default is not quite as convenient for this purpose as I'd initially hoped: foo - list(rbind(c(1,2,3),c(4,5,6)),rbind(c(7,8,9),c(10,11,12))) foo2 - unlist(foo) dim(foo2) - c(dim(foo[[1]]), length(foo)) library(abind) foo3 - do.call(function(...) abind(..., along=3), foo) foo2==foo3 Best wishes, baptiste On 30 Dec 2008, at 18:53, hadley wickham wrote: On Tue, Dec 30, 2008 at 10:21 AM, baptiste auguie ba...@exeter.ac.uk wrote: I thought this was a good candidate for the plyr package, but it seems that l*ply functions are meant to operate only on separate list elements: Lists are the simplest type of input to deal with because they are already naturally divided into pieces: the elements of the list. For this reason, the l*ply functions don't need an argument that describes how to break up the data structure. (from: plyr: divide and conquer, Hadley Wickham 2008) Perhaps a new case to consider? Possibly, but here I would argue that the choice of data structure isn't quite right - if the matrices all have the same dimension, then they should be stored in an array, not a list: foo - list(rbind(c(1,2,3),c(4,5,6)),rbind(c(7,8,9),c(10,11,12))) foo2 - unlist(foo) dim(foo2) - c(dim(foo[[1]]), length(foo)) Then you can use apply (or aaply) directly on that matrix: apply(foo2, c(1,2), mean) apply(foo2, c(1,2), mean, trim = 0.1) etc. Hadley -- http://had.co.nz/ _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Componentwise means of a list of matrices?
Thanks, in fact it's quite clean this way. I've added this tip to the R-wiki, http://wiki.r-project.org/rwiki/doku.php?id=guides:overview-data-manip baptiste On 30 Dec 2008, at 19:25, Gabor Grothendieck wrote: Or even: abind(foo, along = 3) On Tue, Dec 30, 2008 at 1:24 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: Try: do.call(abind, c(foo, along = 3)) On Tue, Dec 30, 2008 at 1:15 PM, baptiste auguie ba...@exeter.ac.uk wrote: In fact, when writing my post I tried to do exactly what you did in creating a 3d array from the list, and I failed miserably! This is (imho) partly because the syntax is not very clean or straightforward as compared to the apply and *ply family. A list of matrices with equal dimensions is easily produced by mapply(... , simplify=F), or lapply, while an array needs to be created in a more verbose manner (as far as i know, some version of a loop). I just remembered the abind package which makes this a bit easier, although the default is not quite as convenient for this purpose as I'd initially hoped: foo - list(rbind(c(1,2,3),c(4,5,6)),rbind(c(7,8,9),c(10,11,12))) foo2 - unlist(foo) dim(foo2) - c(dim(foo[[1]]), length(foo)) library(abind) foo3 - do.call(function(...) abind(..., along=3), foo) foo2==foo3 Best wishes, baptiste On 30 Dec 2008, at 18:53, hadley wickham wrote: On Tue, Dec 30, 2008 at 10:21 AM, baptiste auguie ba...@exeter.ac.uk wrote: I thought this was a good candidate for the plyr package, but it seems that l*ply functions are meant to operate only on separate list elements: Lists are the simplest type of input to deal with because they are already naturally divided into pieces: the elements of the list. For this reason, the l*ply functions don't need an argument that describes how to break up the data structure. (from: plyr: divide and conquer, Hadley Wickham 2008) Perhaps a new case to consider? Possibly, but here I would argue that the choice of data structure isn't quite right - if the matrices all have the same dimension, then they should be stored in an array, not a list: foo - list(rbind(c(1,2,3),c(4,5,6)),rbind(c(7,8,9),c(10,11,12))) foo2 - unlist(foo) dim(foo2) - c(dim(foo[[1]]), length(foo)) Then you can use apply (or aaply) directly on that matrix: apply(foo2, c(1,2), mean) apply(foo2, c(1,2), mean, trim = 0.1) etc. Hadley -- http://had.co.nz/ _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Execution of a .sce file through R
That's really a scilab question, nothing to do with R as far as I can see. Moreover, you haven't provided any of the information requested in the posting guide (OS, example, ...). i'm guessing that something along those lines should work, system(scilab -nw -f yourscript.sce) that is, provided your file is in the working directory and your shell knows about scilab (untested). If this fails, you need to make sure that you know the command to run a scilab script from a terminal, and I doubt this is the place to ask for it. Hope this helps, Baptiste On 31 Dec 2008, at 06:13, ykank wrote: Dear R Users Does some has any idea about how to execute a scilab file(.sce file) from the Terminal in R. Any kind of guidance would be highly welcomed and appreciated. -- View this message in context: http://www.nabble.com/Execution-of-a-.sce-file-through-R-tp21227441p21227441.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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] recursive relevel
Dear list, I'm having second thoughts after solving a very trivial problem: I want to extend the relevel() function to reorder an arbitrary number of levels of a factor in one go. I could not find a trivial way of using the code obtained by getS3method(relevel,factor). Instead, I thought of solving the problem in a recursive manner (possibly after reading Paul Graham essays on Lisp too recently). Here is my attempt : order.factor - function (x, ref) { last.index - length(ref) # convenience for matlab's end keyword if(last.index == 1) return(relevel(x, ref)) # end case, normal case of relevel my.new.list - list(x=relevel(x, ref[last.index]), # creating a list with updated parameters, # going through the list in reverse order ref=ref[-last.index]) # chop the vector from its last level return(do.call(order.factor, my.new.list)) # recursive call } ff - factor(c(a, b, c, d)) ff relevel(ff, levels(ff)[1]) relevel(ff, levels(ff)[2]) # that's the usual case: you want to put a level first order.factor(x=ff, ref=c(a, b)) order.factor(x=ff, ref=c(c)) order.factor(x=ff, ref=c(c, d)) # that's my wish: put c and d in that order as the first two levels I'm hoping this can be improved in several aspects: - there is probably already a better function I missed or overlooked (I'd still be curious about the following points, though) - after reading a few threads, it appears that some recursive functions are fragile in some sense, and I'm not sure what this means in practice. (Should I use Recall, somehow?) - it's probably quite slow for large data.frames - I could not think of a good name, this one might clash with some S3 method perhaps? - any other thoughts welcome! Best wishes, Baptiste _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] recursive relevel
On 9 Jan 2009, at 15:26, Dimitris Rizopoulos wrote: I think that you can still use to core of stats:::relevel.factor; the only thing that needs to be changed is the controls for bad values of the 'ref' argument, i.e., relevelNew - function (x, ref, ...) { lev - levels(x) if (is.character(ref)) ref - match(ref, lev) if (any(is.na(ref))) stop('ref' must be an existing level) nlev - length(lev) if (any(ref 1 | ref nlev)) stop(gettextf(ref = %d must be in 1:%d, ref, nlev), domain = NA) factor(x, levels = lev[c(ref, seq_along(lev)[-ref])]) } ff - factor(c(a, b, c, d)) ff relevelNew(ff, c) relevelNew(ff, c(c, d)) I hope it helps. Best, Dimitris Very good point! I knew I was missing something obvious, but I was wrongly assuming that the changes needed were more drastic. I'm now wondering why this wasn't implemented in relevel() in the first place. Perhaps such a small modification could be useful, at least in the documentation? Thanks, baptiste baptiste auguie wrote: Dear list, I'm having second thoughts after solving a very trivial problem: I want to extend the relevel() function to reorder an arbitrary number of levels of a factor in one go. I could not find a trivial way of using the code obtained by getS3method(relevel,factor). Instead, I thought of solving the problem in a recursive manner (possibly after reading Paul Graham essays on Lisp too recently). Here is my attempt : order.factor - function (x, ref) { last.index - length(ref) # convenience for matlab's end keyword if(last.index == 1) return(relevel(x, ref)) # end case, normal case of relevel my.new.list - list(x=relevel(x, ref[last.index]), # creating a list with updated parameters, # going through the list in reverse order ref=ref[-last.index]) # chop the vector from its last level return(do.call(order.factor, my.new.list)) # recursive call } ff - factor(c(a, b, c, d)) ff relevel(ff, levels(ff)[1]) relevel(ff, levels(ff)[2]) # that's the usual case: you want to put a level first order.factor(x=ff, ref=c(a, b)) order.factor(x=ff, ref=c(c)) order.factor(x=ff, ref=c(c, d)) # that's my wish: put c and d in that order as the first two levels I'm hoping this can be improved in several aspects: - there is probably already a better function I missed or overlooked (I'd still be curious about the following points, though) - after reading a few threads, it appears that some recursive functions are fragile in some sense, and I'm not sure what this means in practice. (Should I use Recall, somehow?) - it's probably quite slow for large data.frames - I could not think of a good name, this one might clash with some S3 method perhaps? - any other thoughts welcome! Best wishes, Baptiste _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] recursive relevel
Thanks Thierry, A quick test shows almost equivalent timing with the modification of relevel() suggested earlier: relevel - function (x, ref, ...) { lev - levels(x) if (is.character(ref)) ref - match(ref, lev) if (any(is.na(ref))) stop('ref' must be an existing level) nlev - length(lev) if (any(ref 1 | ref nlev)) stop(gettextf(ref = %d must be in 1:%d, ref, nlev), domain = NA) factor(x, levels = lev[c(ref, seq_along(lev)[-ref])]) } system.time(relevel(y, c(D, B))) user system elapsed 5.972 0.258 6.395 system.time(order.factor3(y, c(D, B))) user system elapsed 5.962 0.274 6.459 It's always good to learn other options, though. Thanks, baptiste On 9 Jan 2009, at 15:50, ONKELINX, Thierry wrote: Dear Baptiste, You can avoid the recursive stuff. And it will run about twice as fast. order.factor - function (x, ref) + { + last.index - length(ref) # convenience for matlab's end keyword + if(last.index == 1) return(relevel(x, ref)) # end case, normal case + my.new.list - list(x=relevel(x, ref[last.index]), ref=ref[- last.index]) + return(do.call(order.factor, my.new.list)) # recursive call + } order.factor2 - function(x, ref){ + factor(x, levels = c(ref, sort(levels(x)[!levels(x) %in% ref]))) + } order.factor3 - function(x, ref){ + factor(x, levels = c(ref, sort(levels(x)[!levels(x) %in% ref])), labels = c(ref, sort(levels(x)[!levels(x) %in% ref]))) + } x - factor(sample(LETTERS[1:5], 1000, replace = TRUE)) y - factor(sample(LETTERS[1:20], 1000, replace = TRUE)) system.time(order.factor(x, c(D, B))) user system elapsed 5.690.386.09 system.time(order.factor2(x, c(D, B))) user system elapsed 3.900.204.12 system.time(order.factor3(x, c(D, B))) user system elapsed 3.260.193.46 system.time(order.factor(y, c(D, B))) user system elapsed 17.430.39 17.84 system.time(order.factor3(y, c(D, B))) user system elapsed 8.250.178.46 HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] Namens baptiste auguie Verzonden: vrijdag 9 januari 2009 15:11 Aan: R R-help Onderwerp: [R] recursive relevel Dear list, I'm having second thoughts after solving a very trivial problem: I want to extend the relevel() function to reorder an arbitrary number of levels of a factor in one go. I could not find a trivial way of using the code obtained by getS3method(relevel,factor). Instead, I thought of solving the problem in a recursive manner (possibly after reading Paul Graham essays on Lisp too recently). Here is my attempt : order.factor - function (x, ref) { last.index - length(ref) # convenience for matlab's end keyword if(last.index == 1) return(relevel(x, ref)) # end case, normal case of relevel my.new.list - list(x=relevel(x, ref[last.index]), # creating a list with updated parameters, # going through the list in reverse order ref=ref[- last.index]) # chop the vector from its last level return(do.call(order.factor, my.new.list)) # recursive call } ff - factor(c(a, b, c, d)) ff relevel(ff, levels(ff)[1]) relevel(ff, levels(ff)[2]) # that's the usual case: you want to put a level first order.factor(x=ff, ref=c(a, b)) order.factor(x=ff, ref=c(c)) order.factor(x=ff, ref=c(c, d)) # that's my wish: put c and d in that order as the first two levels I'm hoping this can be improved in several aspects: - there is probably already a better function I missed or overlooked (I'd still be curious about the following points, though) - after reading a few threads, it appears that some recursive functions are fragile in some sense, and I'm not sure what this means in practice. (Should I use Recall, somehow?) - it's probably quite slow for large data.frames - I could not think of a good name, this one might clash with some S3 method perhaps? - any other thoughts welcome
Re: [R] indexing question
you can also look at subset, my.data.frame - data.frame(a=rnorm(10), b=factor(sample(letters[1:4], 10, replace=T))) str(my.data.frame) my.data.frame[my.data.frame$b == a, ] subset(my.data.frame, b == a) by the way, it is probably safer not to use data as a variable name as it is also a function. Hope this helps, baptiste On 13 Jan 2009, at 09:33, Dimitris Rizopoulos wrote: have a look at ?[.data.frame; what you need is the following: dat - data.frame(a = rbinom(20, 1, 0.5), x = rnorm(20), y = rnorm(20)) dat dat[dat$a == 1, ] I hope it helps. Best, Dimitris Bunny, lautloscrew.com wrote: Hi all, i have a pretty easy indexing question, at least i believe so. The main reason i post it here, is that brackets and $ are hard to google. How do I index correctly, if i just want to display the whole dataset conditioned on the fact that some particular column equals one. I know i can do something like: data$somecolumn[data$particularcol ==1] . That will show all some column values where the particular column is 1. Unfortunately something like : data[data$particularcol ==1] does not work to get the whole matrix. is there some easy way except the % in % stuff ? Thx in advance __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to get legend outside of plot?
Hi, I think this is a very common question on this list. I've just created a page in the R wiki (inspired by https://stat.ethz.ch/pipermail/r-help/2007-May/132466.html) . With some suggestions and improvements, hopefully we can make a good reference for others to refer to in the future: http://wiki.r-project.org/rwiki/doku.php?id=tips:graphics-misc:legendoutside Hope this helps, baptiste On 14 Jan 2009, at 01:27, Mike Williamson wrote: I am creating a CDF plot function more user-friendly than any default r function. Depending upon the bimodality of the data (it is often bimodal), or any other strange data trends, the points can end up gathering in just about any corner of the plot. So, when I add a legend, whether I choose to add it in the bottom right, top left, or wherever, it will sometimes end up putting the legend right on the data itself. So, I tried to force the legend to certain data values (e.g., the largest in x the smallest in y, to really get the bottom right), but then this means most of the legend is missing because it is outside of the plot region. How can I create a legend that is fully outside of the plot, similar to what excel does by default, for example? Thanks! Mike [[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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Removing duplicates from a list
Your dummy data is not a reproducible example. I'm guessing ?unique could help you. Hope this helps, baptiste On 14 Jan 2009, at 13:19, glenn wrote: For a list say; list1-{1,2,3,4,5,2,1} How do I remove the duplicates please? My real list is 20,000 obs long of dates with many duplicates Regards Glenn [[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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] publication statistics from Web of Science
Dear list, This is a bit of an off-topic question, but I'm hoping to get some advice from more experienced people. I've used the website Web of Science to manually collect publication counts responding to several keywords as a function of date, since the 1960s. http://apps.isiknowledge.com/RAMore.do?product=UAsearch_mode=sid=p1g9lf...@eja6pjhkdqid=1ra_mode=morera_name=PublicationYeardb_id=UGBviewType=raMore This is a really long and error-prone process. Once the data was collected I rearranged it in a form R could read (see example in the end), this step wasn't too bad. Finally, I plotted histograms to show the temporal trends. I have two questions: - Is there a package or external tool to facilitate the collection of data from this kind of online search tool? I could not find any public API for this website, although some tools like Endnote clearly access the database somehow. I'd be very grateful for any pointer. - I feel like the display and choice of search terms is very arbitrary and subjective. Any general advice on how to present this data better is most welcome. (I should mention that i'd rather not involve any complicated statistical analysis, I only want to make sure that the presentation is not horribly biased). Best regards, baptiste statistics - list(list(values=read.table(textConnection( date count 2007 600 2006 588 2008 555 2005 430 2004 418 2003 334 2002 277 2001 239 2000 226 1997 184 1999 184 1998 182 1996 129 1995 108 1994 92 1993 67 1992 53 1991 47 1990 37 1989 14 1988 11 1983 10 1987 7 1985 6 1986 6 1981 5 1984 5 1979 4 1982 4 2009 3 1971 2 1933 1 1973 1 1974 1 1977 1 1978 1 1980 1), head=T),type=1, cumSum=4833, search=photonics), list(values=read.table(textConnection( date count 2008 129 2007 92 2006 50 2005 26 2004 15 2003 4 1972 1 2001 1 2002 1), head=T),type=1, cumSum=319, search=plasmonics), list(values=read.table(textConnection( date count 2008 3207 2007 3105 2006 2666 2005 2323 2004 1910 2003 1552 2002 1372 2001 1292 2000 1095 1999 992 1998 863 1997 771 1996 643 1995 484 1993 418 1994 407 1992 345 1991 321 1990 120 1989 91 1988 82 1987 78 1981 77 1986 73 1983 72 1978 69 1979 68 1985 66 1976 63 1975 62 1980 59 1984 54 1982 52 1973 50 1977 50 1972 46 1974 43 1971 38 1969 28 1970 28 2009 26 1968 18 1967 11 1966 8 1962 5 1963 4 1900 3 1960 3 1961 3 1948 2 1912 1 1949 1 1950 1 1953 1 1954 1 1959 1 1964 1 1965 1), head=T),type=1, cumSum=25226, search=plasmonics+ plasmon), list(values=read.table(textConnection( date count 2008 2716 2007 2640 2006 2257 2005 1991 2004 1625 2003 1302 2002 1129 2001 1056 2000 862 1999 814 1998 650 1997 574 1996 427 1995 338 1994 272 1993 260 1991 187 1992 176 1990 62 1989 51 1981 41 1988 41 1987 36 1986 32 1983 30 1980 29 1982 28 1984 28 1985 27 1975 25 1976 23 2009 23 1973 22 1979 22 1972 15 1974 15 1977 13 1971 10 1978 10 1970 9 1968 7 1969 7 1966 1 ), head=T),type=2, cumSum=19883, search=surface plasmon), list(values=read.table(textConnection( date count 2008 324 2007 295 2006 248 2005 220 2004 156 2003 126 2002 113 2000 86 2001 84 1996 66 1999 59 1997 53 1998 53 1993 39 1992 34 1994 29 1995 29 1991 25 1973 2 1987 2 1970 1 1972 1 1978 1 1983 1 1984 1 1989 1 2009 1 ), head=T),type=2, cumSum=2050, search=localised or particle plasmon), list(values=read.table(textConnection( date count 2007 196 2008 165 2005 141 2006 141 2003 112 2004 109 2002 83 2001 75 1999 62 2000 51 1998 38 1997 29 1995 13 1996 11 1993 6 1992 4 1994 4 1991 2 2009 2 1990 1), head=T),type=2, cumSum=1245, search=SPR sensor), list(values=read.table(textConnection( date count 2008 290 2007 225 2006 167 2005 138 2004 101 2003 79 2001 54 2002 51 2000 42 1998 31 1999 30 1997 27 1996 25 1992 20 1995 20 1991 15 1994 14 1993 10 1973 2 1984 2 1990 2 2009 2 1963 1 1972 1 1974 1 1977 1 1978 1 1982 1 1983 1 1988 1 1989 1), head=T), cumSum=1356,type=1, search=light scattering gold)) str(statistics) treatOne - function(ml){ data.frame(ml$values, search= as.character(ml$search)) } # treatOne(statistics[[1]]) library(plyr) stats.list - llply(statistics[-3], treatOne) stats.df - do.call(rbind, stats.list) stats.melt - melt(stats.df, id.var=c(date, search)) str(stats.melt) # stats.melt - within(stats.melt, counts=value) library(ggplot2) p - ggplot(data = subset(stats.melt, date1960 ), mapping = aes(x = date,y = value)) + facet_wrap(~search,ncol=2, scale=free_y) + layer(colour=grey, geom = c( histogram), stat = identity ) + scale_y_continuous(number of publications) p _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] publication statistics from Web of Science
For the record, I thought I'd share two findings: First, the web of science website does seem to have some sort of API, as discussed here: http://scientific.thomson.com/support/faq/webservices/ It does not seem like a trivial thing to set up though. Second, because I could not pass the search term easily in the address, I looked into Google scholar instead, where a typical search looks like: http://scholar.google.co.uk/scholar?as_q=plasmonicsnum=10btnG=Search+Scholaras_epq=as_oq=as_eq=as_occt=anyas_sauthors=as_publication=as_ylo=as_yhi=1960as_allsubj=allhl=enlr= here it is trivial to create such a string with the desired keyword and dates, and retrieve the number of results using readLines(url) and grep. Thanks to Phil Spector for some pointers. Best wishes, baptiste On 14 Jan 2009, at 13:44, baptiste auguie wrote: Dear list, This is a bit of an off-topic question, but I'm hoping to get some advice from more experienced people. I've used the website Web of Science to manually collect publication counts responding to several keywords as a function of date, since the 1960s. http://apps.isiknowledge.com/RAMore.do?product=UAsearch_mode=sid=p1g9lf...@eja6pjhkdqid=1ra_mode=morera_name=PublicationYeardb_id=UGBviewType=raMore This is a really long and error-prone process. Once the data was collected I rearranged it in a form R could read (see example in the end), this step wasn't too bad. Finally, I plotted histograms to show the temporal trends. I have two questions: - Is there a package or external tool to facilitate the collection of data from this kind of online search tool? I could not find any public API for this website, although some tools like Endnote clearly access the database somehow. I'd be very grateful for any pointer. - I feel like the display and choice of search terms is very arbitrary and subjective. Any general advice on how to present this data better is most welcome. (I should mention that i'd rather not involve any complicated statistical analysis, I only want to make sure that the presentation is not horribly biased). Best regards, baptiste statistics - list(list(values=read.table(textConnection( date count 2007 600 2006 588 2008 555 2005 430 2004 418 2003 334 2002 277 2001 239 2000 226 1997 184 1999 184 1998 182 1996 129 1995 108 1994 92 1993 67 1992 53 1991 47 1990 37 1989 14 1988 11 1983 10 1987 7 1985 6 1986 6 1981 5 1984 5 1979 4 1982 4 2009 3 1971 2 1933 1 1973 1 1974 1 1977 1 1978 1 1980 1), head=T),type=1, cumSum=4833, search=photonics), list(values=read.table(textConnection( date count 2008 129 2007 92 2006 50 2005 26 2004 15 2003 4 1972 1 2001 1 2002 1), head=T),type=1, cumSum=319, search=plasmonics), list(values=read.table(textConnection( date count 2008 3207 2007 3105 2006 2666 2005 2323 2004 1910 2003 1552 2002 1372 2001 1292 2000 1095 1999 992 1998 863 1997 771 1996 643 1995 484 1993 418 1994 407 1992 345 1991 321 1990 120 1989 91 1988 82 1987 78 1981 77 1986 73 1983 72 1978 69 1979 68 1985 66 1976 63 1975 62 1980 59 1984 54 1982 52 1973 50 1977 50 1972 46 1974 43 1971 38 1969 28 1970 28 2009 26 1968 18 1967 11 1966 8 1962 5 1963 4 1900 3 1960 3 1961 3 1948 2 1912 1 1949 1 1950 1 1953 1 1954 1 1959 1 1964 1 1965 1), head=T),type=1, cumSum=25226, search=plasmonics+ plasmon), list(values=read.table(textConnection( date count 2008 2716 2007 2640 2006 2257 2005 1991 2004 1625 2003 1302 2002 1129 2001 1056 2000 862 1999 814 1998 650 1997 574 1996 427 1995 338 1994 272 1993 260 1991 187 1992 176 1990 62 1989 51 1981 41 1988 41 1987 36 1986 32 1983 30 1980 29 1982 28 1984 28 1985 27 1975 25 1976 23 2009 23 1973 22 1979 22 1972 15 1974 15 1977 13 1971 10 1978 10 1970 9 1968 7 1969 7 1966 1 ), head=T),type=2, cumSum=19883, search=surface plasmon), list(values=read.table(textConnection( date count 2008 324 2007 295 2006 248 2005 220 2004 156 2003 126 2002 113 2000 86 2001 84 1996 66 1999 59 1997 53 1998 53 1993 39 1992 34 1994 29 1995 29 1991 25 1973 2 1987 2 1970 1 1972 1 1978 1 1983 1 1984 1 1989 1 2009 1 ), head=T),type=2, cumSum=2050, search=localised or particle plasmon), list(values=read.table(textConnection( date count 2007 196 2008 165 2005 141 2006 141 2003 112 2004 109 2002 83 2001 75 1999 62 2000 51 1998 38 1997 29 1995 13 1996 11 1993 6 1992 4 1994 4 1991 2 2009 2 1990 1), head=T),type=2, cumSum=1245, search=SPR sensor), list(values=read.table(textConnection( date count 2008 290 2007 225 2006 167 2005 138 2004 101 2003 79 2001 54 2002 51 2000 42 1998 31 1999 30 1997 27 1996 25 1992 20 1995 20 1991 15 1994 14 1993 10 1973 2 1984 2 1990 2 2009 2 1963 1 1972 1 1974 1 1977 1 1978 1 1982 1 1983 1 1988 1 1989 1), head=T), cumSum=1356,type=1, search=light scattering gold)) str(statistics) treatOne - function(ml){ data.frame(ml$values, search= as.character(ml$search)) } # treatOne(statistics[[1]]) library(plyr) stats.list - llply(statistics[-3], treatOne) stats.df - do.call(rbind, stats.list) stats.melt - melt(stats.df, id.var
[R] regexp problem (was: Re: publication statistics from Web of Science)
Whoops, it seems I could use some help with regular expressions... Consider the following two functions, creating a search string, and retrieving the content from the url, makeURLsearch - function(key, dates=c(NULL, NULL)){ base.search - http://scholar.google.co.uk/scholar?; key.search - paste(as_q=, key,, sep=) other.search - num=10btnG=Search + Scholar as_epq=as_oq=as_eq=as_occt=anyas_sauthors=as_publication= dates.search - paste(as_ylo=, dates[1], as_yhi=, dates[2], as_allsubj=allhl=enlr=, sep=) full.search - paste(base.search, key.search, other.search, dates.search, sep=) return(full.search) } makeURLsearch(plasmonics) makeURLsearch(photonics, c(1980, NULL)) retrieveNumberPublications - function(url){ x - readLines(url) y - grep('of about',x, value=TRUE) z - gsub('of about\\s+/b','\\1',y[1],perl=TRUE) # this does not do what I wanted # the bit to retrieve is the number below # b10/b of about b21,900/b for bbphotonics/b z } retrieveNumberPublications( makeURLsearch(photonics, c(2008, NULL)) ) I can isolate the long string containing the result I want, but not single out the value which lies between b10/b of about b21,900/b for bbphotonics/b . Any regexp guru to help me out? I've never got my head around these, other than trivial cases. Many thanks, baptiste On 15 Jan 2009, at 09:45, baptiste auguie wrote: For the record, I thought I'd share two findings: First, the web of science website does seem to have some sort of API, as discussed here: http://scientific.thomson.com/support/faq/webservices/ It does not seem like a trivial thing to set up though. Second, because I could not pass the search term easily in the address, I looked into Google scholar instead, where a typical search looks like: http://scholar.google.co.uk/scholar?as_q=plasmonicsnum=10btnG=Search+Scholaras_epq=as_oq=as_eq=as_occt=anyas_sauthors=as_publication=as_ylo=as_yhi=1960as_allsubj=allhl=enlr= here it is trivial to create such a string with the desired keyword and dates, and retrieve the number of results using readLines(url) and grep. Thanks to Phil Spector for some pointers. Best wishes, baptiste _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] challenge in using layout with r bind function
Hi, Try this, layout(matrix(c(1,1,2,3), ncol=2, byrow=T)) hist(1:10) plot.new()# empty space plot(1:10) HTH, baptiste 2009/8/16 RAVI KAPOOR ravk...@gmail.com: Hi Can any one explain how i can divide the graphic window into two rows and two columns -- allocate figure 1 all of row 1 and allocate figure 2 the intersection of column 2 and row 2 Actually through above also want to understand the use of rbind() function that is used in call to layout() Thanks in advance for help and time Regards ravi [[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. -- _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.