Re: [R] graph paper look

2012-01-18 Thread baptiste auguie
You could draw a grid with grid, using grid.grill, library(grid) pdf("grid.pdf", width=21/2.54,height=29.7/2.54) grid.grill(h = unit(seq(0, 297, by=1), "mm"), v = unit(seq(0, 210, by=1), "mm"), gp=gpar(col="grey",lwd=0.1)) grid.grill(h = unit(seq(0, 297, by=5), "mm"), v = un

Re: [R] Executable expressions

2012-01-18 Thread baptiste auguie
One reason might be that you can easily fool the user into running unexpected/unreadable commands. Guess what this does: cmd <- paste(c(letters[c(19L, 25L, 19L, 20L, 5L, 13L)], "(' ", letters[c(19L, 21L, 4L, 15L)], " ", letters[c(4L, 5L, 19L, 20L, 18L, 15L, 25L)], " ", letters[c(1L, 12L, 12L)], "

Re: [R] Gray levels

2012-01-25 Thread baptiste auguie
The scales package? gradient_n_pal(c("red","white","blue"), c(0,0.5,1)) (seq(0,1,length=100)) HTH, baptiste On 26 January 2012 10:36, Jeffrey Joh wrote: > > The gray (level) function returns different shades of gray, where level is a > vector of numbers ranging from 0 to 1.  0 is white and 1

Re: [R] logical subsetting, indexes and NAs

2012-01-28 Thread baptiste auguie
Hi, which(x < 15) omits the NA (treated as false). HTH, b. On 29 January 2012 09:36, Federico Calboli wrote: > Dear All, > > just a quick example: > > >> x  = 1:25 >> x[12] = NA > >> x >  [1] 1 2 3 4 5 6 7 8 9 10 11 NA 13 14 15 16 17 18 19 20 21 22 23 24 25 > >> y = x[x<10] >> y >  [1]  1  2

Re: [R] How I assign the result of a plot to a variable?

2012-01-29 Thread baptiste auguie
Try this, plot(1:10) img <- grid::grid.cap() # grid.raster(img) stream <- col2rgb(img) write.table(stream, file="dam.txt", row.names = FALSE, col.names = FALSE) (you'll have to restore the dimensions of the matrix once you've read the rgb values for each pixel) HTH, baptiste On 30

Re: [R] how do I exort a list of numbers into csv file?

2012-02-05 Thread baptiste auguie
Hi, If you don't mind having NAs for missing values, try the following, mylist = list(1:3, 4:7) library(plyr) write.csv(do.call(rbind.fill.matrix, lapply(mylist, matrix, nrow=1)), file="") HTH, b. On 6 February 2012 15:01, Michael wrote: > Hi all, > > I have a list of vector of numbers - the

Re: [R] 3D confidence ellipsoid with ellipse projections onto 2D plane

2012-02-08 Thread baptiste auguie
Hi, If you read French, you might find the following discussion interesting, http://www.forum.math.ulg.ac.be/viewthread.html?id=45765 It contains some good suggestions to project an ellipsoid onto a plane, which as I understand might be related to your question. HTH, b. On 8 February 2012 0

Re: [R] Version control (git, mercurial) for R packages

2012-02-08 Thread baptiste auguie
On 9 February 2012 13:02, David Winsemius wrote: > > On Feb 8, 2012, at 6:33 PM, Tom Roche wrote: > >> >> Peter Langfelder Thu Feb 9 00:01:31 CET 2012 >>> >>> I'm exploring using a version control system >> >> >> +1! welcome to the new millenium :-) >> >>> to keep better track of changes to the [R

Re: [R] Version control (git, mercurial) for R packages

2012-02-09 Thread baptiste auguie
Once upon a time r-forge had the option to sync from an external svn repository, e.g. hosted on googlecode. I haven't seen it available for some time, sadly. I'm sure many users would appreciate if this feature came back with the new interface. Not sure if it could work with git as well, though. b

Re: [R] Color cells of a matrix as in Excel

2012-02-14 Thread baptiste auguie
A minimum code to plot a coloured matrix with text labels could be the following: library(grid) library(scales) library(RColorBrewer) diverging_palette <- function(d = NULL, centered = FALSE, midpoint = 0, colors = brewer.pal(7,"PRGn")){ half <- length(colors)/2

Re: [R] Defining a viewport scale in {Grid}

2012-02-16 Thread baptiste auguie
The default units of polygonGrob are "npc", I think you want "native" instead. Try the following, library(grid) d = data.frame(x=rnorm(100, 10), y=rnorm(100, -100)) v = dataViewport(xData=d$x, yData=d$y) grid.points(d$x,d$y, default.units="native", vp=v) HTH, b. On 17 February 2012 02:47,

Re: [R] parse .ps files with R?

2012-02-18 Thread baptiste auguie
Hi, the grImport package provides some tools for this. HTH, b. On 19 February 2012 16:06, Nick Matzke wrote: > Hi, > > Is there a way to parse a postscript (*.ps) file with R (or perhaps with > some other command-line utility)? > > E.g., I have a map in postscript format with lots of features,

Re: [R] How to "flatten" a multidimensional array into a dataframe?

2012-04-19 Thread baptiste auguie
library(plyr) adply(my.array,1:3) HTH, baptiste On 20 April 2012 08:46, Emmanuel Levy wrote: > Hi, > > I have a three dimensional array, e.g., > > my.array = array(0, dim=c(2,3,4), dimnames=list( d1=c("A1","A2"), > d2=c("B1","B2","B3"), d3=c("C1","C2","C3","C4")) ) > > what I would like to get

Re: [R] write a png inside a pdf for large graphics?

2012-04-23 Thread baptiste auguie
Hi, On 24 April 2012 05:00, Duncan Murdoch wrote: > On 23/04/2012 10:49 AM, Adam Wilson wrote: >> >> I routinely write graphics into multi-page PDFs, but some graphics (i.e. >> plots of large spatial datasets using levelplot()) can result in enormous >> files.  I'm curious if there is a better wa

Re: [R] print table on plot

2012-04-26 Thread baptiste auguie
Hi, try also grid.table() in gridExtra b. On 27 April 2012 01:26, statquant2 wrote: > Hello, > I would like to be able to plot an array on a plot, something like: >        |arg1  | arg2 | arg3 > val1| 0.9    | 1.1    | 2.4 > val2| 0.33  | 0.23 | -1.4 > val3| hello| stop | test > I know Rwave is

Re: [R] Kerning of italic text in plotmath

2012-05-15 Thread baptiste auguie
For better typography, try tikzDevice, it uses LaTeX to render the text. b. On 16 May 2012 07:23, Fisher Dennis wrote: > David > > You missed the point -- the issue was not the spacing between WORDS.  It was > the spacing between LETTERS (as noted in the original email) > Other suggestions woul

Re: [R] New Eyes Needed to See Syntax Error

2012-05-17 Thread baptiste auguie
Your log10(HCO3 and sqrt(HCO3 seem to be missing closing brackets. HTH, baptiste On 18 May 2012 11:34, Rich Shepard wrote: >  One of many scripts to produce 4 lattice plots on one page keeps throwing > an error. I've tried manipulating the file to eliminate the error, but have > not been able t

Re: [R] Catenating strings involving plotmath symbols.

2012-05-18 Thread baptiste auguie
Try this, bquote(.(L1) * .(L2)) HTH, b. On 19 May 2012 16:17, Rolf Turner wrote: > > In the context in which I am actually working it is necessary for > me to build parts of a text string to place on a plot in two separate > stages. > > The following toy example illustrates what I am trying to

Re: [R] package grid: mirror grob objects along an axis

2012-05-22 Thread baptiste auguie
You can rotate the viewport to flip around the horizontal axis, library(grid) grid.text("Chiral") grid.text("Chiral", vp=viewport(angle=180, y=unit(0.5,"npc")-unit(1,"line"))) HTH, b. On 23 May 2012 05:34, Thomas Zumbrunn wrote: > Maybe my question was not concise enough. I was referring to ob

Re: [R] package grid: mirror grob objects along an axis

2012-05-22 Thread baptiste auguie
Oops, sent too early; this obviously just a rotation, not a mirror image. It illustrates the problem though ;) b. On 23 May 2012 07:32, baptiste auguie wrote: > You can rotate the viewport to flip around the horizontal axis, > > library(grid) > grid.text("Chiral") &g

Re: [R] sweave tables as images?

2012-05-25 Thread baptiste auguie
you can open a device that has the exact dimensions of the table, g = tableGrob(head(iris, 4)) png("test.png", width=convertWidth(grobWidth(g), "in", value=TRUE), height=convertHeight(grobHeight(g), "in", value=TRUE),units="in", res=150) grid.draw(g) dev.off() Doing this with knitr might

Re: [R] sweave tables as images?

2012-05-25 Thread baptiste auguie
2012 09:43, Alexander Shenkin wrote: > this works - thanks baptiste!  i'm working in Sweave right now - perhaps > it will be tough in knitr as you mention. > > On 5/25/2012 4:31 PM, baptiste auguie wrote: >> you can open a device that has the exact dimensions of the table, &

[R] gridBase and layout

2008-09-20 Thread baptiste auguie
Dear list, I have produced a fairly intricate plot arrangement for use in a publication using layout() and gridBase, and out of curiosity I'd like to learn whether a more elegant and robust solution could be obtained with grid to avoid the layout() function. library(gridBase) x <- seq(

Re: [R] lower and upper limits in integrate as vectors

2008-09-20 Thread baptiste auguie
Hi, I think you want to Vectorize integrate(), not integrand(). Here's a way using mapply, integrand <- function(z) { return(z * z) } vec1<-1:3 vec2<-2:4 mapply(integrate, lower=vec1, upper=vec2, MoreArgs=list(f=integrand) ) baptiste On 20 Sep 2008, at 13:08, Andreas Wittmann wrote: D

Re: [R] lattice: Color in Barchart legend

2008-09-24 Thread baptiste auguie
Hi, you can use par.settings to get a consistent color scheme, pal1 <- rgb(196, 255, 255, max = 255) pal2 <- rgb( 0, 35, 196, max = 255) df <- data.frame( Gruppe = c("A", "B", "A", "B"), Kat = c("x1", "x1", "w1", "w1"), value= c(1,2, 4, 5)) barchart(value ~ Kat, group=

Re: [R] How can I comment out whole chunks of code?

2008-09-24 Thread baptiste auguie
just a thought: you might want to have a look at the brew package (R- forge). Instead of source()ing the document in the R console, you'd use brew(). By default, any text is considered a comment, only lines contained between <% %> will be run as R code. baptiste On 24 Sep 2008, at 21:03, M

Re: [R] Lattice: how to reduce/shrink plot area

2008-09-25 Thread baptiste auguie
Hi, I'm not sure I understand your example, it'd be easier with some reproducible code. I think you'd better off using grid, in particular the figure 5.22 from the book R Graphics provides an example of embedding a lattice graph in a page. Here's a simplified version, library(grid) librar

Re: [R] Creating a Legend

2008-09-25 Thread baptiste auguie
Hi, I think you want the following, df <- data.frame(x=rnorm(100), y=rnorm(100)) plot(df) legend("topright", title="Land Use Type", cex=0.75, pch=16, col=c("red", "green"),legend=c("Urban", "green"), ncol=2) I could not find a way to have a different text size for the title,

[R] large linear system - iterative scheme?

2008-09-26 Thread baptiste auguie
Dear list, I'm using solve(A,b) to solve (!) a linear system, where A is a large (100 x 100) symmetric, dense, complex matrix. The precise structure of A is block-Toeplitz, which means that the best algorithm for inversion would probably be based on fft. Anyway, I'm looking for an iterativ

Re: [R] include scripts into main file (the LaTeX way)

2008-09-26 Thread baptiste auguie
you mean like ?source ? On 26 Sep 2008, at 13:49, Michael Schulte wrote: Dear R-people, I want to use an idea from LaTeX in the work flow with R. It is possible in LaTeX to have a main file from which other files are called (ie included). So for example if you have book, the main index file

Re: [R] Return a list

2008-09-26 Thread baptiste auguie
?attach or ?with Hope this helps, baptiste On 26 Sep 2008, at 14:57, Stefan Fritsch wrote: Dear R Users, another problem for me is the output of a function. I have several output variables which I give back with the list command. test <- function {return(list(a,b,c,d,e,f,g,...))}

Re: [R] remove multiple elements from vector

2008-09-27 Thread baptiste auguie
Hi, ?unique should work fine for this. I think the problem in your implementation is that you modify x in the loop, in particular its length may become shorter than the stopping condition. HTH, baptiste On 27 Sep 2008, at 14:30, Bastian Offermann wrote: Hello all, one brief question

Re: [R] plyr package: passing further arguments fail

2008-10-07 Thread baptiste auguie
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 optio

[R] panel.groups: use group.number to define colors

2008-10-07 Thread baptiste auguie
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")

Re: [R] panel.groups: use group.number to define colors

2008-10-07 Thread baptiste auguie
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

Re: [R] panel.groups: use group.number to define colors

2008-10-07 Thread baptiste auguie
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

Re: [R] nls, lattice, and conversion over to ggplot

2008-10-10 Thread baptiste auguie
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 comm

Re: [R] plotCI

2008-10-11 Thread baptiste auguie
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 Azeved

Re: [R] lattice panel question

2008-10-14 Thread baptiste auguie
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),

Re: [R] What editors can I get R in Mac OS X to talk to?

2008-10-23 Thread baptiste auguie
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 cod

Re: [R] Filling symbols in xyplot

2008-10-25 Thread baptiste auguie
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="r

[R] orthographic projection of ellipsoids

2008-10-26 Thread baptiste auguie
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

Re: [R] passing arguments to subset from a function

2008-12-17 Thread baptiste auguie
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$S

Re: [R] Componentwise means of a list of matrices?

2008-12-30 Thread baptiste auguie
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

Re: [R] Componentwise means of a list of matrices?

2008-12-30 Thread baptiste auguie
at 18:53, hadley wickham wrote: On Tue, Dec 30, 2008 at 10:21 AM, baptiste auguie 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

Re: [R] Componentwise means of a list of matrices?

2008-12-30 Thread baptiste auguie
PM, Gabor Grothendieck wrote: Try: do.call(abind, c(foo, along = 3)) On Tue, Dec 30, 2008 at 1:15 PM, baptiste auguie 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 syn

Re: [R] Execution of a .sce file through R

2008-12-31 Thread baptiste auguie
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, p

[R] recursive relevel

2009-01-09 Thread baptiste auguie
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 thou

Re: [R] recursive relevel

2009-01-09 Thread baptiste auguie
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, bapt

Re: [R] recursive relevel

2009-01-09 Thread baptiste auguie
nner 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

Re: [R] indexing question

2009-01-13 Thread baptiste auguie
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 va

Re: [R] How to get legend outside of plot?

2009-01-14 Thread baptiste auguie
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: ht

Re: [R] Removing duplicates from a list

2009-01-14 Thread baptiste auguie
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

[R] publication statistics from Web of Science

2009-01-14 Thread baptiste auguie
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.

Re: [R] publication statistics from Web of Science

2009-01-15 Thread baptiste auguie
_ylo=&as_yhi=1960&as_allsubj=all&hl=en&lr= 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,

[R] regexp problem (was: Re: publication statistics from Web of Science)

2009-01-15 Thread baptiste auguie
s not do what I wanted # the bit to retrieve is the number below # 10 of about 21,900 for photonics z } retrieveNumberPublications( makeURLsearch("photonics", c(2008, NULL)) ) I can isolate the long string containing the result I want, but not single out t

Re: [R] Multiple lattice plots on a page: aligning x-axes vertically

2009-01-25 Thread baptiste auguie
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

Re: [R] retrieving variables values from a function

2009-01-27 Thread baptiste auguie
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

Re: [R] plot Ticks

2009-01-27 Thread baptiste auguie
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 re

Re: [R] Plot dagger symbol in R

2009-01-29 Thread baptiste auguie
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 da

Re: [R] Odp: Matrix

2009-02-02 Thread baptiste auguie
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 [

Re: [R] overlaying plots from a list of data frames

2009-02-04 Thread baptiste auguie
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

Re: [R] maptools: Test if point is in polygon

2009-02-05 Thread baptiste auguie
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, i

Re: [R] seq(along= surprise

2009-02-05 Thread baptiste auguie
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:

[R] recursive derivative a list of polynomials

2009-02-08 Thread baptiste auguie
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 correspon

Re: [R] Fast fourier transformation

2009-02-10 Thread baptiste auguie
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

Re: [R] general inverse solver?

2009-02-11 Thread baptiste auguie
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 inspirat

Re: [R] How to comment in R

2009-02-11 Thread baptiste auguie
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 toda

Re: [R] How to comment in R

2009-02-11 Thread baptiste auguie
On 11 Feb 2009, at 13:41, Gustaf Rydevik wrote: On Wed, Feb 11, 2009 at 2:15 PM, baptiste auguie 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

Re: [R] two scatter plots in one

2009-02-12 Thread baptiste auguie
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(res

Re: [R] Multiple merge, better solution?

2009-02-19 Thread baptiste auguie
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"

Re: [R] Multiple merge, better solution?

2009-02-19 Thread baptiste auguie
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

Re: [R] Multiple merge, better solution?

2009-02-19 Thread baptiste auguie
s 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 : Hi, I think Reduce could help you. DF1 &l

Re: [R] Insert value in a Vector Alternately

2009-02-19 Thread baptiste auguie
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 m

Re: [R] Insert value in a Vector Alternately

2009-02-19 Thread baptiste auguie
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: Pe

Re: [R] adding a reference line to an xyplot

2009-02-20 Thread baptiste auguie
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 typ

Re: [R] adding a reference line to an xyplot

2009-02-20 Thread baptiste auguie
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 t

Re: [R] How to transfer a list of space delimited character elements into a char vector?

2009-02-20 Thread baptiste auguie
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 novic

Re: [R] line joining graphs

2009-02-23 Thread baptiste auguie
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 wrot

Re: [R] Modifying Names from (x,y] into x

2009-02-26 Thread baptiste auguie
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(

Re: [R] accessing and preserving list names in lapply

2009-02-27 Thread baptiste auguie
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

Re: [R] rounding problem

2009-02-27 Thread baptiste auguie
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= s

Re: [R] using a for loop with variable as vectors

2009-02-27 Thread baptiste auguie
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

Re: [R] Reshape

2009-03-03 Thread baptiste auguie
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]

Re: [R] ggplot2: annotated horizontal lines

2009-03-03 Thread baptiste auguie
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 s

Re: [R] ggplot2: annotated horizontal lines

2009-03-03 Thread baptiste auguie
"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

[R] advice on using this C code in R

2009-03-08 Thread baptiste auguie
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

Re: [R] fill the space between to lines

2009-03-08 Thread baptiste auguie
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 betwe

Re: [R] Summary of data.frame according to colnames and grouping factor

2009-03-08 Thread baptiste auguie
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: ### s

Re: [R] Merge 10 data frames with 3 id columns that are common to all data frames

2009-03-08 Thread baptiste auguie
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")

Re: [R] Merge 10 data frames with 3 id columns that are common to all data frames

2009-03-08 Thread baptiste auguie
-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.631676 2 0.058783 baptiste auguie-2 wrote: Hi,

Re: [R] How to write a function that accepts unlimited number of input arguments?

2009-03-09 Thread baptiste auguie
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

Re: [R] How to write a function that accepts unlimited number of input arguments?

2009-03-09 Thread baptiste auguie
) 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 > wrote: > Hi, > > > On 9 Mar 2009, at 15:32, Sean Zhang wrote: > >> Dear R-help

Re: [R] system() not accepting strings from cat()

2009-03-10 Thread baptiste auguie
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

Re: [R] help with loop

2009-03-12 Thread baptiste auguie
On 12 Mar 2009, at 13:22, richard.cot...@hsl.gov.uk wrote: I'm trying to write a loop to sum my data in the following way: (the second - the first) + (the third - the second) + (the fourth - the third) + ... for each column. This is just sum(diff(x)), or even x[length(x)] - x[1]. I think r

Re: [R] R-help: grep in for loop using index - doesn't work

2009-03-12 Thread baptiste auguie
Hi, your example is quite messy (neither reproducible or minimal). I think you could try the following, mdf <- data.frame(1:3) names(mdf) <- "147" i <- 147 mdf[ as.character(i) ] Hope this helps, baptiste On 11 Mar 2009, at 22:34, Mohan Singh wrote: Hi everyone I am trying to

Re: [R] [OT] two question about color space.

2009-03-14 Thread baptiste auguie
Hi, For a good discussion of the link between colour and spectra I would suggest, http://www.fourmilab.ch/documents/specrend/ which provides an open-source C code to perform the conversion you ask for. I asked for some advice on how to wrap a R function around this code last week but sad

Re: [R] [OT] two question about color space.

2009-03-14 Thread baptiste auguie
On 14 Mar 2009, at 13:08, Jinsong Zhao wrote: Hi, For a good discussion of the link between colour and spectra I would suggest, http://www.fourmilab.ch/documents/specrend/ which provides an open-source C code to perform the conversion you ask for. I asked for some advice on how to wrap a

Re: [R] [OT] two question about color space.

2009-03-15 Thread baptiste auguie
h/documents/specrend/ On 14 Mar 2009, at 12:33, baptiste auguie wrote: Hi, For a good discussion of the link between colour and spectra I would suggest, http://www.fourmilab.ch/documents/specrend/ which provides an open-source C code to perform the conversion you ask for. I asked for s

Re: [R] Testing for Inequality à la "select case "

2009-03-15 Thread baptiste auguie
Hi, I think you could get a cleaner solution using ?cut to split your data in given ranges (the break argument), and then using this factor to give the appropriate percentage. Hope this helps, baptiste On 15 Mar 2009, at 20:12, diegol wrote: Using R 2.7.0 under WinXP. I need to write

<    2   3   4   5   6   7   8   >