[R] melting a list: basic question

2008-07-25 Thread baptiste auguie
Dear list, I'm trying to use the reshape package to perform a merging operation on a list of data.frames as illustrated below, a <- 1:10 example <- list( data.frame(a=a, b=sin(a)), data.frame(a=a, b=cos(a)) ) melt(example, id = a) this produces the desired result, where the data.fram

Re: [R] melting a list: basic question

2008-07-25 Thread baptiste auguie
Given that I cannot arbitrarily change the data to make "a" an integer, can I still use "a" as a grouping variable? I tried melt(example, id = factor(a)) but it does not work either. Must this change from numeric values to factors be done before applying melt? Thanks, baptiste On 25 Jul

Re: [R] melting a list: basic question

2008-07-26 Thread baptiste auguie
On 26 Jul 2008, at 02:52, hadley wickham wrote: On Fri, Jul 25, 2008 at 8:50 PM, hadley wickham <[EMAIL PROTECTED]> wrote: On Fri, Jul 25, 2008 at 9:49 AM, baptiste auguie <[EMAIL PROTECTED]> wrote: Dear list, I'm trying to use the reshape package to perform a merging

Re: [R] Converting english words to numeric equivalents

2008-07-28 Thread baptiste auguie
Here is my attempt at this (taking a specific understanding of the ill- defined "equivalence" relation), unletter <- function(word){ word.broken <- strsplit(word, NULL) set.of.numbers <- sapply(word.broken[[1]], function(let) which(let == letters)) paste(set.of.numbe

Re: [R] Converting english words to numeric equivalents

2008-07-28 Thread baptiste auguie
10:47, (Ted Harding) wrote: On 28-Jul-08 09:29:22, baptiste auguie wrote: Here is my attempt at this (taking a specific understanding of the ill- defined "equivalence" relation), unletter <- function(word){ word.broken <- strsplit(word, NULL) set.of.numbers <

[R] standardize ggplot and lattice themes

2008-08-01 Thread baptiste auguie
Dear list, I'm writing a long document (thesis) and as much as I would like to use only ggplot2 for the graphics, some features are still a bit undocumented so I often end up choosing either ggplot2, lattice, or base plots (which i know better) depending on the particular graph to produc

Re: [R] lapply, sapply

2008-08-02 Thread baptiste auguie
It seems to me that the reshape package should do the job, library(reshape) # note that you need to fix the method to melt lists in the current version ( passing ... to the method for data.frames, as discussed here last week) cast(data=melt(dat), fun.aggregate = function(.x) rle(.x)$length[

[R] recursive root finding

2008-08-07 Thread baptiste auguie
Dear list, I've had this problem for a while and I'm looking for a more general and robust technique than I've been able to imagine myself. I need to find N (typically N= 3 to 5) zeros in a function that is not a polynomial in a specified interval. The code below illustrates this, by cre

[R] lattice: add vertical lines in xyplot

2008-08-07 Thread baptiste auguie
Hi list, This is a very basic question about lattice: I wish to add some vertical lines in each panel of a xyplot as demonstrated in this example: library(lattice) 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", "

Re: [R] lattice: add vertical lines in xyplot

2008-08-07 Thread baptiste auguie
2008 at 11:54 AM, baptiste auguie <[EMAIL PROTECTED]> wrote: Hi list, This is a very basic question about lattice: I wish to add some vertical lines in each panel of a xyplot as demonstrated in this example: library(lattice) xx <- seq(1, 10, length=100) x <- rep(xx, 4) y <- c(cos(

Re: [R] recursive root finding

2008-08-08 Thread baptiste auguie
d not find a clean way to implement it. Any thoughts welcome! I feel like I've overlooked an obvious trick. Many thanks, baptiste On 7 Aug 2008, at 11:49, baptiste auguie wrote: Dear list, I've had this problem for a while and I'm looking for a more general and robust technique

Re: [R] re cursive root finding

2008-08-08 Thread baptiste auguie
3) once a zero is found, look for zeros on both sides, etc... this quickly makes a complicated decision tree when the number of zeros grows and I could not find a clean way to implement it. Any thoughts welcome! I feel like I've overlooked an obvious trick. Many thanks, baptiste On 7 Aug 2

Re: [R] re cursive root finding

2008-08-08 Thread baptiste auguie
Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] ] On Behalf Of baptiste auguie Sent: Friday, August 08, 2008 1:25 PM To: Hans W. Borchers Cc: r-help@r-project.org Subject: Re: [R] re cursive root finding On 8 Aug 2008, at 16:44, Hans W. Borchers wrote: As your curve is def

[R] levels values of cut()

2008-08-09 Thread baptiste auguie
Dear list, I have the following example, from which I am hoping to retrieve numeric values of the factor levels (that is, without the brackets): x <- seq(1, 15, length=100) y <- sin(x) my.cuts <- cut(which(abs(y) < 1e-1), 3) levels(my.cuts) hist() does not suit me for this, as it does n

Re: [R] re cursive root finding

2008-08-09 Thread baptiste auguie
ind a clean way to implement it. Any thoughts welcome! I feel like I've overlooked an obvious trick. Many thanks, baptiste On 7 Aug 2008, at 11:49, baptiste auguie wrote: Dear list, I've had this problem for a while and I'm looking for a more general and robust technique than I

Re: [R] levels values of cut()

2008-08-09 Thread baptiste auguie
# function(...) as.numeric(c(...)),backref=-2,simplify=TRUE)) lims } cutIntervals(1:5, 3) Many thanks, baptiste On 9 Aug 2008, at 11:12, Prof Brian Ripley wrote: On Sat, 9 Aug 2008, baptiste auguie wrote: Dear list, I have the foll

[R] lattice : using both strip and strip.left

2008-08-25 Thread baptiste auguie
Dear all, I'm routinely using lattice and ggplot2, I wish to create a lattice theme that looks not too dissimilar to ggplot's defaults so I can include both graphs in a document with a consistent look. To illustrate my questions, consider the following example: library(ggplot2) library(l

Re: [R] Using sample() with a data frame ?

2008-08-25 Thread baptiste auguie
Hi, I find convenient to use a custom function for this: sample.df <- function (df, N = 1000, ...) { df[sample(nrow(df), N, ...), ] } sample.df(daf1,1000) Hope this helps, baptiste On 25 Aug 2008, at 12:31, Martin Hvidberg wrote: I have a data frame (daf1), that holds +8 record

Re: [R] R-ish challenge for dependent ranking

2008-08-25 Thread baptiste auguie
Hi I think you want something like, with(ds, tapply(yn, drank1group, rank) ) also, the reshape package should do this sort of thing neatly. Hope this helps, baptiste On 25 Aug 2008, at 16:10, ivo welch wrote: Dear R wizards: First, thanks for the notes on SQL. These pointers will make

Re: [R] lattice : using both strip and strip.left

2008-08-25 Thread baptiste auguie
Brilliant! I've just ordered your book to learn more about lattice as its use is quite gripping despite a steep learning curve. Many thanks, baptiste On 25 Aug 2008, at 23:07, Deepayan Sarkar wrote: On Mon, Aug 25, 2008 at 4:47 AM, baptiste auguie <[EMAIL PROTECTED]> wrote

Re: [R] Combine x-axis labels size

2008-08-27 Thread baptiste auguie
Hi, I'm not sure I understand what you want, but perhaps: x <- 1:9 y <- x plot(x, y, ann=F, xaxt="n") axis(1, lab=F) -> positions mtext(paste(positions), side = 1, line = 1, outer = F, at = test, cex=1:length(positions)) HTH, baptiste On 27 Aug 2008, at 18:36, Dani Valverde wrote: Hel

Re: [R] Combine x-axis labels size

2008-08-27 Thread baptiste auguie
Aug 2008, at 18:51, baptiste auguie wrote: Hi, I'm not sure I understand what you want, but perhaps: x <- 1:9 y <- x plot(x, y, ann=F, xaxt="n") axis(1, lab=F) -> positions mtext(paste(positions), side = 1, line = 1, outer = F, at = test, cex=1:length(positions)) HTH

Re: [R] give all combinations

2008-08-31 Thread baptiste auguie
I had a similar problem recently where I used the following code: v <- factor(letters[1:3]) all.cases <- expand.grid(v, v) all.cases[as.numeric(all.cases[, 2]) >= as.numeric(all.cases[, 1]), ] I'm not sure how to extend it cleanly to an arbitrary number of vectors, though. Baptiste On 31

Re: [R] challenge in using layout with r bind function

2009-08-16 Thread baptiste auguie
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 : > 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 fi

Re: [R] Display the character variables in a dataset in R

2009-08-17 Thread baptiste auguie
Hi, If you have a data.frame, perhaps this can help, tc = textConnection("carat cut color clarity depth table price x y z 1 0.23 Ideal E SI2 61.555 326 3.95 3.98 2.43 2 0.21 Premium E SI1 59.861 326 3.89 3.84 2.31 3 0.23 Good E VS1 56.965

Re: [R] help simplifying complex graphic arguments to a function

2009-08-18 Thread baptiste auguie
I'm facing a similar challenge with a grid.table function (see example below). I envisaged two routes, 1- rather than assigning a list of properties for each cell, I would define a matrix for each property. For instance, the default could be, fill = matrix("grey90", nrow(values), ncol(values)) #

Re: [R] Remove columns

2009-08-18 Thread baptiste auguie
Try this, a[ ,as.logical(colSums(a))] mind an unfortunate logical vs integer indexing trap: isTRUE(all.equal( a[ ,!!colSums(a)] , a[ ,colSums(a)] )) [1] FALSE HTH, baptiste 2009/8/18 Alberto Lora M : > Hi Everbody > > Could somebody help me.? > > I need to remove the columns where the sum o

Re: [R] ggplot2 transparent pdf

2009-08-19 Thread baptiste auguie
Try this, print(p+ opts(plot.background= theme_rect(fill=NA))) HTH, baptiste 2009/8/19 rajesh j : > Hi, > I plotted a histogram using ggplot2 and saved it as a pdf.However, the > portions outside the histogram dont appear transparent when I use a > non-white bg colour in my latex document.What

Re: [R] how to fill the area under the density line with semitransparent colors

2009-08-19 Thread baptiste auguie
Hi, One way using ggplot2, library(ggplot2) ggplot(data=myda, mapping=aes(x=traits, y=..density..)) + stat_density(aes(fill=factor), alpha=0.5, col=NA, position = 'identity') + stat_density(aes(colour = factor), geom="path", position = 'identity', size=2) HTH, baptiste 2009/8/19 Mao Jianfeng

Re: [R] Move legend text to the left legend box border

2009-08-19 Thread baptiste auguie
I believe you want "x.intersp", txt <- c("Setosa Petals", "Versicolor Sepals") plot(1,1,t="n") legend("top", txt, text.col=1:2, cex=0.7, inset=c(0,1/3)) legend("center", txt, text.col=1:2, cex=0.7, x.intersp = -0.5) HTH, baptiste 2009/8/19 Stefan Grosse : > On Wed, 19 Aug 2009 10:20:03 +0200

Re: [R] graph label greek symbol failure

2009-08-19 Thread baptiste auguie
plot(1:10,ylab=expression("temperature "*delta*t)) 2009/8/19 e-letter : > On 18/08/2009, Gavin Simpson wrote: >> On Tue, 2009-08-18 at 13:06 +0100, e-letter wrote: >>> On 17/08/2009, Michael Knudsen wrote: >>> > On Mon, Aug 17, 2009 at 12:51 PM, e-letter wrote: >>> > >>> >> I have tried to add

Re: [R] Creating a list of combinations

2009-08-20 Thread baptiste auguie
the short answer is to add [[i]] in your loop, file_list[[i]] <- paste(index$month[i], index$year[i], sep='') yet a shorter answer would be, file_list = apply(index, 1, paste, collapse="") HTH, baptiste 2009/8/20 Steve Murray : > > Dear R Users, > > I have 120 objects stored in R's memory and

Re: [R] A question on List

2009-08-21 Thread baptiste auguie
Try this, mat <- replicate(4, matrix(rnorm(25), 5), simpl=F) mat vect <- rnorm(4) mapply( `*` , mat, vect, SIMPLIFY=F) HTH, baptiste PS: I see someone replied already, but you might find replicate useful too 2009/8/21 RON70 : > > Suppose I have following list : > > mat <- vector("list") > fo

Re: [R] Where to put source code?

2009-08-21 Thread baptiste auguie
Hi, Say you have the following data and functions that you want to reuse, d = data.frame(1:10) foo = function(x,y , ...){ plot(x,y, type="l", ...) } You may save the code in a file "testing.r", noting that in general data may find a convenient storage format using save(d, file= "mydata.

Re: [R] 2d color coded line plot

2009-08-21 Thread baptiste auguie
geom_path in ggplot2 is another option, see two examples on this page: http://had.co.nz/ggplot2/geom_path.html HTH, baptiste 2009/8/21 Jim Lemon : > Gonçalo Graça wrote: >> >> Hi! I'm not experienced very experienced with R and i'm looking for a way >> doing plots like in this example >> http:

Re: [R] Problem with passing a string to subset

2009-08-21 Thread baptiste auguie
Try this, mystr <-"c==1" subset(foo, eval(parse(text = mystr)) ) library(fortunes) fortune("parse") # try several times # I prefer this, but there is probably a better way mycond<- quote(c==1) subset(foo, eval(bquote(.(mycond))) ) HTH, baptiste 2009/8/21 Sebastien Bihorel : > Dear R-users, >

Re: [R] Problem with passing a string to subset

2009-08-22 Thread baptiste auguie
That's right, however the bquote construct may be useful when combining several conditions, subset(foo, eval(bquote(.(mycond) & a < 5)) ) baptiste 2009/8/22 Vitalie S. : > On Fri, 21 Aug 2009 22:38:09 +0200, baptiste auguie > wrote: > >> Try this, >> >> m

Re: [R] problem plotting with ggplot2

2009-08-28 Thread baptiste auguie
Hi, Have you checked that you have the latest version of ggplot2 and plyr? Please post your sessionInfo() HTH, baptiste 2009/8/28 romunov > Dear R-Help subsribers, > > upon running into a wonderful ggplot2 package by accident, I abruptly > encountered another problem. Almost every command ru

Re: [R] Google's R Style Guide

2009-08-31 Thread baptiste auguie
2009/8/31 David Scott > > > I think this discussion is valuable, and have previously asked about style > which I think is very important. Base R does suffer from very inconsistent > naming and as I think Duncan said it makes it very difficult sometimes to > remember names when you have variations

Re: [R] Google's R Style Guide

2009-08-31 Thread baptiste auguie
Murdoch > baptiste auguie wrote: > >> 2009/8/31 David Scott >> >> >> >>> I think this discussion is valuable, and have previously asked about >>> style >>> which I think is very important. Base R does suffer from very >>> i

Re: [R] Simple column selection question- which and character lists

2009-08-31 Thread baptiste auguie
Hi, I think you want %in% instead of == see ?"%in%" HTH, baptiste 2009/8/31 AllenL > > Dear R-list, > Seems simple but have tried multiple approaches, no luck. > > I have a list of column names: > > >names.species.bio.18=c("Achimillb","Agrosmitb","Amorcaneb","Andrgerab","Ascltubeb","Elymcana

Re: [R] combining grid.text, expression and variables

2009-09-02 Thread baptiste auguie
Hi, Try this, library(grid) value <- c(0.1) lab <- c("test", expression(bquote(paste(.(value[1]*100), " and percentiles1", sep=""))), bquote(expression(.(value[1]*100)*" and percentiles2")), bquote(paste(.(value[1]*100), " and percentiles3", sep="")) ) grid.newpage

Re: [R] get function to return object "name"?

2009-09-02 Thread baptiste auguie
Hi, Try this, myplot <- function(subject) { plot(subject, main=deparse(substitute(subject))) } s1 <- c(200,200,190,180) myplot(s1) see ?deparse HTH, baptiste 2009/9/2 Marianne Promberger > Dear list, > > I've written a function that plots subjects. Something like: > > myplot <- functi

Re: [R] combining grid.text, expression and variables

2009-09-02 Thread baptiste auguie
asy way to bullet proof the code: use as.expression when building lab > > Thanks > > baptiste auguie wrote: > >> Hi, >> >> Try this, >> >> >> library(grid) >> >> value <- c(0.1) >> >> lab <- c("test", >>

Re: [R] putting reference lines or grids into the background of a plot

2009-09-03 Thread baptiste auguie
Hi, You may find some inspiration here: http://wiki.r-project.org/rwiki/doku.php?id=tips:graphics-misc:ggplot2theme_inbase HTH, baptiste 2009/9/3 RINNER Heinrich > Dear R-community, > > using R.2.9.1, how do you put reference lines or grids into the > _background_ of a plot? > For example:

Re: [R] User defined function's argument as Subset function's input

2009-09-04 Thread baptiste auguie
Hi, This may come close to what you want, x <- data.frame(ID=rep(letters[1:5],2), A1=rep(10:14,2), A2=rep(2:6,2), A3=c(101:105,95:99), A4=c(-60, rep(c(0, 3), length=9))) # basic conditions cond1 <- quote(ID == "a" & A2 >1) cond2 <- quote(A1 < 10) cond3 <- quote(A1 == 10) # note t

Re: [R] < 0 x 0 matrix >

2009-09-04 Thread baptiste auguie
it's documented as "unexpected" ?diag Note Using diag(x) can have unexpected effects if x is a vector that could be of length one. Use diag(x, nrow = length(x)) for consistent behaviour. And the result follows from this part, else if (length(x) == 1L && nargs() == 1L) { n <- as.int

Re: [R] help with functions

2009-09-04 Thread baptiste auguie
Hi, I think you've got a problem with environments, testA<-function(input=1) { dat <- data.frame(A=seq(input,5), B=seq(6,10)) vec.names<- c("a", "b") env <- new.env() for(i in 1:ncol(dat)) { tab<- dat[,i]-1 assign(vec.names[i], tab, env=env) }

Re: [R] How to print a variable with in double quotes

2009-09-04 Thread baptiste auguie
Hi, Try this, x = 10 noquote(dQuote(x)) noquote(sQuote(x)) HTH, baptiste 2009/9/4 sailu Yellaboina > I want to print a variable with in double quotes. > For example > > x = 10 ; > x ;#prints 10 > "x" ; #prints x > \"x\" ; # Error: unexpected input in "\" > > I want to the out put

Re: [R] How can I appoint a small part of the whole data

2009-09-05 Thread baptiste auguie
Hi, you have two problems in your first scenario, 1- Wrong operator precedence. For example, > 1 == 2 | 3 [1] TRUE where 1==2 is tested as FALSE, but 1 is not tested against 3 for equality as it would be using, > 1 == 2 | 1 == 3 [1] FALSE or using %in% 2:3 Instead, R evaluates "FALSE | 3", a

Re: [R] getting name from function?

2009-09-07 Thread baptiste auguie
Hi, Try this, myFUN <- function(FUN) { return(deparse(substitute(FUN))) } HTH, baptiste 2009/9/7 Rainer M Krug > Hi > > I have the following function which should return the name of FUN: > > myFUN <- function(FUN) { > return( THE_NAME_OF_FUN(FUN)) > } > > Is it possible? What do I have tio

Re: [R] calling combinations of variable names

2009-09-07 Thread baptiste auguie
Hi, It's not enough to create a string with your instructions, it also needs to be evaluated as such. If you really wanted to evaluate your string, you'd need something like, a <- b <- cc <- 1 # dummy example eval(parse(text = "cbind(a, b, cc)")) #library(fortunes) #fortune("parse") but fortune

Re: [R] xyplot {lattice} are different types possible for each panel?

2009-09-07 Thread baptiste auguie
Hi, Something like this perhaps, p <- xyplot(y ~ x | names, layout = c(1, 3), panel = function(...,type="p") { if (panel.number() == 1) { panel.xyplot(...,type = "h") } else { panel.xyplot(...,type = type) } }) plot(p) HTH, baptiste 200

Re: [R] How to do rotation for polygon?

2009-09-11 Thread baptiste auguie
Hi, See if this helps, polygon.regular <- # return a matrix of xy coordinates for a regular polygon centered about (0,0) function (sides = 5) { n <- sides if (n < 3) n <- 3 if (n > 8) n <- 50 th <- pi * 2/n costh <- cos(th) sinth <- sin(th)

Re: [R] Exporting Numerous Graphs

2009-09-14 Thread baptiste auguie
Hi, It's probably easiest with the pdf (or postscript) device, pdf("all.pdf") for(ii in 1:27) plot(rnorm(10), main=paste("plot", ii)) dev.off() Bitmap-based devices can generate sequential filenames (Rplot1.png, Rplot2.png, ...) that you could combine in a single document using external tools

Re: [R] How to set default plotting colors by treatment?

2009-09-14 Thread baptiste auguie
Hi, Using ggplot2, you could do something like this, library(ggplot2) myplot <- function(x, y, data, geom="point"){ ggplot(data=data, map=aes_string(x=x, y=y, colour = "treatment") ) + layer(geom=geom) + scale_colour_manual(values=c("red", "blue")) } d = data.frame(Xmeas=rnorm(10), Ymeas=rn

Re: [R] Which "apply" function to use?

2009-09-14 Thread baptiste auguie
Hi, try this, rowMeans(as.data.frame(Coefs)) # or apply(as.data.frame(Coefs), 1, mean) HTH, baptiste 2009/9/14 Masca, N. > Dear All, > > I have a problem which *should* be pretty straightforward to resolve - but > I can't work out how! > > I have a list of 3 coefficient estimates for 4 diffe

Re: [R] How to refer to the last a few rows?

2009-09-14 Thread baptiste auguie
Hi, tail(x,2) or x[seq(nrow(x)-1, nrow(x)), ] HTH, baptiste 2009/9/14 Peng Yu > Hi, > > x=matrix(1:60,nr=6) > > I can refer the last 2 rows by > x[5:6,] > > If I don't know the total number of rows is 6, is there a way to refer > the last 2 rows? > > Regards, > Peng > > _

Re: [R] ggplot2 graphing multiple lines of data

2009-09-14 Thread baptiste auguie
alternatively, use aes_string, p <- ggplot(bmm, aes_string(x="age", y="bm", colour="pp", group="pp")) p <- p + geom_line() p HTH, baptiste 2009/9/14 smu > hey, > > On Mon, Sep 14, 2009 at 07:51:42AM -0700, John Kane wrote: > > p <- ggplot(bmm, aes(x="age", y="bm", colour="pp", group="pp"))

Re: [R] how to recode with an if-type statement

2009-09-14 Thread baptiste auguie
Of course if w9zd9_1, w9zd9_2, w9zd9_3 were elements of a data.frame (or even a list), you could use indexing, w9zd9 = data.frame(w9zd9_1 = 1:10, w9zd9_2 = 1:10, w9zd9_3 = -2*1:10) average = function(numbers=1, w9zd9){ if(numbers == 1L) return(w9zd9[ ,1]) # vector case fails with rowMeans rowM

Re: [R] expression

2009-09-16 Thread baptiste auguie
Try this, marco2 = matrix(rnorm(4), nrow=2, ncol=2) marco3 = 2.12 i =1 plot.new() mtext(bquote(R^2*.(round(marco2[1,i],digits=3))*" N° of proteins:"*.(marco3[i])),side=4,cex=.6) HTH, baptiste 2009/9/16 Marco Chiapello > /Dear all,/// > /I am very thankful, if you could tell what is the righ

Re: [R] Generalized cumsum?

2009-09-16 Thread baptiste auguie
?Reduce maybe HTH, baptiste 2009/9/16 OKB (not okblacke) >Is there anything like cumsum and cumprod but which allows you to > apply an arbitrary function instead of sum and product? In other words, > I want a function cumfunc(x, f) that returns a vector, so that for all n > up to the

Re: [R] latex code in R -> convert to pdf

2009-09-17 Thread baptiste auguie
Hi, for basic tables (e.g. display a data.frame without fancy formatting), you could try the textplot() function from the gplots package, or this rough function for Grid graphics, source("http://gridextra.googlecode.com/svn/trunk/R/tableGrob.r";) # install.packages("gridextra", repos="http://R-Fo

Re: [R] R functions with array arguments

2009-09-17 Thread baptiste auguie
Try this, sapply(Mabslim , my_gamma, alpha=-1, xstar = -21, xmax = -27) or wrap it with ?Vectorize, vmy_gamma = Vectorize(my_gamma, vectorize.args = "xlim") vmy_gamma(alpha=-1, xstar = -21, xlim= Mabslim, xmax = -27) HTH, baptiste 2009/9/17 Maurizio Paolillo : > Dear R users, > I'm trying t

Re: [R] Help a newbie

2009-09-18 Thread baptiste auguie
I don't understand your question. Where does your data come from in the first place? Is it stored in a file, or is it a result of a previous operation in R, or is it something you need to copy and paste in your script, or ...? the textConnection() construct is often used to make for self-containe

Re: [R] lattice: How to display no box but only a y-axis on the left + Thicker lines

2009-09-18 Thread baptiste auguie
No box is easy, bwplot(y~x, data=data.frame(y=rnorm(10),x=sample(letters[1:3],10,repl=T)), par.settings=list(axis.line=list(col=NA))) but that seems to remove all axis lines and ticks as well. You may have to define a custom panel.axis() function. An alternative is to use grid.remove() to remove

Re: [R] How to avoid copy-paste when copying code from this list

2009-09-19 Thread baptiste auguie
it might be possible to set up a particular mode before copying the history, ### start example ### email = function(op){ if(!missing(op)) { options(op) } else { op <- options() options("prompt" = " ") options("continue" = " ") op } } op = email() a = 1:10 a email(op) a = 1:10 a

[R] matrix operations on grobs and grid units

2009-09-19 Thread baptiste auguie
Dear list, As a minimal test of a more complex grid layout, I'm trying to find a clean and efficient way to arrange text grobs in a rectangular layout. The labels may be expressions, or text with a fontsize different of the default, which means that the cell sizes should probably be calculated usi

Re: [R] How to avoid copy-paste when copying code from this list

2009-09-19 Thread baptiste auguie
Neat! What if, instead, one wanted to format his/her code in the console before sending it by email? Any tips for that? (I proposed something like options("prompt"=" ") above, but got stuck with adding a comment # to printed results) Thanks, baptiste 2009/9/19 Gabor Grothendieck : > Combini

Re: [R] matrix operations on grobs and grid units

2009-09-19 Thread baptiste auguie
A few amendments might make this improved code more readable, e = expression(alpha,"testing very large width", hat(beta), integral(f(x)*dx, a, b)) library(grid) rowMax.units <- function(u, nrow){ # rowMax with a fake matrix of units  matrix.indices <- matrix(seq_along(u), nrow=nrow)  do.call(uni

Re: [R] eval(expr) without printing to screen?

2009-09-19 Thread baptiste auguie
Hi, What about this, eval(parse(text=expr)) (no print) HTH, baptiste 2009/9/19 Nick Matzke : > Hi, > > I have a script which I source, which evaluates a changing expression call > hundreds of times.  It works, but it prints to screen each time, which is > annoying.  There must be simple way

Re: [R] Lattice: combine the same strip?

2009-09-20 Thread baptiste auguie
Hi, Not exactly answering your question, but latticeExtra provides a function useOuterStrips that you could use to have a single S11 strip on the left instead. HTH, baptiste 2009/9/20 di jianing : > Hello R helpers, > > I am producing a figure with dual strips, i.e., x~y | S1 + S2, where S1 an

Re: [R] Plot factors with a loop

2009-09-20 Thread baptiste auguie
Hi, >From what I understand, I would suggest the following strategy, 1- combine all data in a single data.frame (see merge, rbind, reshape package, etc.) 2- plot all data at once using a formula like this, boxplot(d~f,data=df) HTH, baptiste 2009/9/20 Sam Player : > # I have a dataframe with

[R] packGrob and dynamic resizing

2009-09-20 Thread baptiste auguie
Dear all, I'm trying to follow an old document to use Grid frames, Creating Tables of Text Using grid Paul Murrell July 9, 2003 As a minimal example, I wrote this, gf <- grid.frame(layout = grid.layout(1, 1), draw = TRUE) label1 <- textGrob("test", x = 0, just = "left", name="test") gf=place

Re: [R] Putting a text box in a plot

2009-09-21 Thread baptiste auguie
Hi, Maybe the textplot() function in the gplots package? HTH, baptiste 2009/9/21 Sergey Goriatchev : > Hello everyone, > > I have a plot and I want to but a (formatted) box containing text and > numbers, say: > Mean: 0.1 > St.Deviation: 1.1 > Skewness: 1.1 > Kurtosis: 0.5 > > I know there is a

Re: [R] Putting a text box in a plot

2009-09-21 Thread baptiste auguie
ordinates in text() function. > No, there must be another function somewhere that produces these text boxes. > > Best, > Sergey > > On Mon, Sep 21, 2009 at 11:49, baptiste auguie > wrote: >> Hi, >> >> Maybe the textplot() function in the gplots package? >>

Re: [R] plotmath

2009-09-21 Thread baptiste auguie
plot(0, xlab=bquote(theta *" = "* .(x))) ?substitute ?bquote HTH, baptiste 2009/9/21 Jarrod Hadfield : > Hi, > > I want to have a legend that is a mixture of numbers and symbols, and have > found no way of achieving this. > > For example, if I want theta="x" or theta=2 this is easily achieved.

[R] truth (karnaugh) table

2009-09-21 Thread baptiste auguie
Dear list, I think I'm being dense, but I can't get combn or expand.grid to give me this result. I need to generate a matrix of all 16 possible sequences of 4 boolean elements, 0001 0010 0011 0100 . (in the end I'll have to assign NA to the 0s and some value to the 1s but let's kee

Re: [R] truth (karnaugh) table

2009-09-21 Thread baptiste auguie
I knew I was missing the obvious. And to think it's only Monday... Thanks everyone! baptiste 2009/9/21 Henrique Dallazuanna : > Try this: > > do.call(expand.grid, rep(list(0:1), 4)) > > On Mon, Sep 21, 2009 at 2:04 PM, baptiste auguie > wrote: >> Dear list, >>

Re: [R] Variable as a filename

2009-09-23 Thread baptiste auguie
Hi, The short answer would be ?paste (as in paste(year, ".csv", sep="") ), but I'd suggest you try this instead, lf <- list.files(pattern = ".csv") lf # [1] "2003.csv" "2004.csv" "2005.csv" ln <- gsub(".csv", "", lf) ln # [1] "2003" "2004" "2005" length(ln) lapply(lf, read.csv) ?list.files

Re: [R] Sorting

2009-09-23 Thread baptiste auguie
yet another way, > x <- read.table(textConnection("Category Value + b1 + b2 + a7 + a1"), header=TRUE) > y = transform(x, Category = relevel(Category, c("b"))) > str(y) 'data.frame': 4 obs. of 2 variables: $ Category: Facto

Re: [R] Problem in graph plotting

2009-09-23 Thread baptiste auguie
Hi, It's trivial with ggplot2, library(ggplot2) qplot(tp,dp, geom="line") + scale_y_reverse() HTH, baptiste 2009/9/23 David Winsemius : > > On Sep 23, 2009, at 7:58 AM, FMH wrote: > >> Dear All, >> >> Let: >> dp: depth of the river >> tp: temperature with respect to depth >> >> We can have a s

Re: [R] Problem in graph plotting

2009-09-23 Thread baptiste auguie
Try this, d <- na.omit(data.frame(tp,dp)) plot(d, t="l", ylim=rev(range(d$dp))) ?na.omit HTH, baptiste 2009/9/23 FMH : > Thank you for the code. I found that the coding does not work if there is an > NA in dp variable. For instance; > > # > dp <- c(1,4,NA,2,5,7,9,8,9,2) >

Re: [R] Flattening Graphics

2010-02-10 Thread baptiste auguie
Hi, You could try the grid.grab() function in R devel if your graphics use the Grid package. It will read the graphical output as a bitmap which you can then export in a multipage pdf. It may not be really flattening per se but that would definitely help with the viewing speed. HTH, baptiste O

Re: [R] Flattening Graphics

2010-02-11 Thread baptiste auguie
Hi, On 11 February 2010 22:14, Paul Murrell wrote: > Hi > > > baptiste auguie wrote: >> >> Hi, >> >> You could try the grid.grab() function in R devel if your graphics use >> the Grid package. It will read the graphical output as a bitmap which > >

Re: [R] evaluate variable within expression - how?

2010-02-14 Thread baptiste auguie
Hi, Try with bquote, plot.new() myText <- "some text" text(.5, .5, bquote(bold(.(myText basically, bquote( .(myText) ) performs the substitution before applying bold() (see ?bquote). HTH, baptiste On 14 February 2010 17:36, Mark Heckmann wrote: > #  I want to plot bold text. The text sh

Re: [R] Problems with boxplot in ggplot2:qplot

2010-02-14 Thread baptiste auguie
Hi, it's hard to tell what's wrong without a reproducible example, but I noted two things: - AFAIK there is no plot method for ggplot2. You probably meant print(p) instead - if you map x to factor(month), I think it will be incompatible with your xlim values range(month). HTH, baptiste On 14

Re: [R] unexpected results with higher-order functions and lapply

2010-02-14 Thread baptiste auguie
Hi, I believe it's lazy evaluation. See ?force HTH, baptiste On 14 February 2010 20:32, Jyotirmoy Bhattacharya wrote: > I want to use lapply and a function returning a function in order to build a > list of functions. > >> genr1 <- function(k) {function() {k}} >> l1 <- lapply(1:2,genr1) >> l1[

Re: [R] Bind field of a list

2010-02-19 Thread baptiste auguie
Hi, Try this, unlist(test) or do.call(c, test) HTH, baptiste On 19 February 2010 15:19, statquant wrote: > > Hello all > I am new in R and so easy stuff are difficult... > let say that I have a list > test <- list(a=c("x","v"),b=c("n","m")) > how can I without a loop get test$a bind with te

Re: [R] Exporting Graphs

2010-02-21 Thread baptiste auguie
Hi, just to make sure, you didn't forget to close the device with dev.off() ? baptiste On 21 February 2010 20:48, Karthik wrote: > Hello Tal, > This is the code. > > >> hist(rnorm(100)) >> jpeg("histogram.jpeg") > --- > > Even when I decrease the qua

Re: [R] How to fill in a region with different patterns?

2010-02-25 Thread baptiste auguie
Hi, If you are curious you might like to try a highly experimental Grid function I wrote some time ago, library(grid) source("http://gridextra.googlecode.com/svn/trunk/R/patternGrob.r";) grid.newpage() grid.pattern(x=seq(1/6, 5/6, length=6), width=unit(1/8,"npc"), height=unit(0.5,"npc"),

Re: [R] Plotting a Trivial Matrix

2010-02-26 Thread baptiste auguie
Hi, A minimalist example using Grid graphics, library(RGraphics) bwImage <- function(m, cols=c("white", "black"), draw=TRUE, gp=gpar()){ g <- imageGrob(nrow(m), ncol(m), cols=cols[m+1], gp=gp) if(draw) grid.draw(g) return(g) } m <- matrix(rnorm(200) > 0,

Re: [R] Plotting a Trivial Matrix

2010-02-26 Thread baptiste auguie
On 26 February 2010 11:12, Lorenzo Isella wrote: > Thanks Augustine and Jim for the prompt reply. > You both answered my question. To avoid another post, I would simply like to > know if something along these lines is doable also with ggplot2. > Many thanks > > Lorenzo > Augustine??? Anyhow, wi

Re: [R] Preserving lists in a function

2010-02-27 Thread baptiste auguie
Hi, I think I would follow this approach too, using updatelist() from the reshape package, updatelist <- function (x, y) { common <- intersect(names(x), names(y)) x[common] <- y[common] x } myfunction=function(list1=NULL, list2=NULL, list3=NULL){ list1=updatelist(list(variable1=1

Re: [R] Preserving lists in a function

2010-02-27 Thread baptiste auguie
Point well taken --- grid::gpar() is also a good example; I'll make use of your suggestion in my future coding. Best, baptiste On 27 February 2010 15:02, Barry Rowlingson wrote: > On Sat, Feb 27, 2010 at 11:29 AM, Gabor Grothendieck > wrote: >> Or use modifyList which is in the core of R. > >

Re: [R] Three most useful R package

2010-03-03 Thread baptiste auguie
Hi, The 3 packages I load most often are my own; typically I make a new package for every new job. It automatically loads other packages as dependencies (top-ranked are ggplot2, reshape, plyr) as well as my data and functions I'm currently working with. If some functions evolve further towards a

Re: [R] how to make this sequence: 1,2,3,4,5,4,3,2,1

2010-03-05 Thread baptiste auguie
c(x <- 1:5, rev(x[-length(x)])) On 5 March 2010 07:04, kensuguro wrote: > > I'm just beginning R, with book Using R for Introductory Statistics, and one > of the early questions has me baffled.  The question is, create the > sequence: 1,2,3,4,5,4,3,2,1 using seq() and rep(). > > Now, as a progr

Re: [R] data.frame question

2010-03-07 Thread baptiste auguie
Hi, try this, data.frame(x,as.numeric(x %in% y)) HTH, baptiste On 7 March 2010 21:06, joseph wrote: > hello > > can you show me how to create a data.frame from two factors x and y. column 1 > should be equal to x and column 2 is 1 if it is common to y and 0 if it is > not. > > x=factor(c("A

Re: [R] How to take out the content of character string

2010-03-10 Thread baptiste auguie
Hi, it's generally considered a bad practice but try this, eval(parse(text=AA)) library(fortunes) fortune(106) HTH, baptiste On 10 March 2010 07:46, jq81 wrote: > > My question is represented by the following example. > > For example, I have a character string a, which is defined as > > AA="

[R] write.fortran

2010-03-10 Thread baptiste auguie
Dear all, I'm trying to write tabular data to a text file, these data will be the input of a Fortran program. The format needs to be "(i7,2x,7(e15.7,2x))". I have not been able to find a clean way of producing this output with write.table. I searched for a "write.fortran" function similar to read.

  1   2   3   4   5   6   7   8   >