Re: [R] ggplot2: Histogram with negative values on x-axis doesn't work

2009-10-30 Thread baptiste auguie
2009/10/30 hadley wickham : > I read anything that mentions > ggplot2 no matter where it is. > ... one should hope this statement only applies to "the Internet" though, does it? Please do share your regexp if it's not the case. :) baptiste __ R-help@r

Re: [R] superscript troubles

2009-11-02 Thread baptiste auguie
Hi, Try this, x = rnorm(1) y = rnorm(1) leg = bquote(r^2*"="*.(round(x,digits=3))*", P="*.(round(y, digits=3))) plot.new() legend (bty ="n","topright",legend=leg) HTH, baptiste 2009/11/2 Jacob Kasper : > I know that this has been revisited over and over, yet I cannot figure out > how to solve

Re: [R] how to display a string containing greek chrs and variables

2009-11-03 Thread baptiste auguie
Hi, try this, plot.new() x=0.8 text(0.5, 0.5, bquote(rho == .(x))) HTH, baptiste 2009/11/3 : > > I'm trying something that I thought would be pretty simple, but it's proving > quite frustrating... > > I want to display, for instance, the correlation coefficient "rho" in a > graph. > > I can d

Re: [R] R and Python

2009-11-04 Thread baptiste auguie
Hi, It looks like SAGE might be another option, http://www.sagemath.org/index.html though I never tried it. HTH, 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

Re: [R] Obtaining midpoints of class intervals produced by cut and table

2009-11-08 Thread baptiste auguie
Hi, Maybe something like this (inspired by ?cut), cut2num <- function(f){ labs <- levels(f) d <- data.frame(lower = as.numeric( sub("\\((.+),.*", "\\1", labs) ), upper = as.numeric( sub("[^,]*,([^]]*)\\]", "\\1", labs) )) d$midpoints <- rowMeans(d) d } a <- c(1, 2, 3, 4

Re: [R] Find the first values in vector

2009-11-09 Thread baptiste auguie
Hi, One way would be, vec[ cumsum(!vec)==0 ] HTH, baptiste 2009/11/9 Grzes : > > Hi ! > I have a vector: > vec= TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE TRUE  TRUE  FALSE > and I'm looking for a method which let me get only the first values equal > TRUE from this vector. It means that I

[R] drop unused levels in subset.data.frame

2009-11-10 Thread baptiste auguie
Dear list, subset has a 'drop' argument that I had often mistaken for the one in [.factor which removes unused levels. Clearly it doesn't work that way, as shown below, d <- data.frame(x = factor(letters[1:15]), y = factor(LETTERS[1:3])) s <- subset(d, y=="A", drop=TRUE) str(s) 'data.frame': 5

Re: [R] drop unused levels in subset.data.frame

2009-11-10 Thread baptiste auguie
AM, baptiste auguie wrote: > >> Dear list, >> >> subset has a 'drop' argument that I had often mistaken for the one in >> [.factor which removes unused levels. >> Clearly it doesn't work that way, as shown below, >> >> d <- data.frame(x = fa

Re: [R] All possible combinations of functions within a function

2009-11-10 Thread baptiste auguie
Hi, >From what I understand of your code, you might find the following construct useful, funs <- c("mean", "sum", "sd", "diff") x <- 1:10 lapply(funs, do.call, args=list(x)) and then working with lists rather than naming every object individually. You might find mapply useful too when you have t

Re: [R] Discontinuous graph

2009-11-16 Thread baptiste auguie
Hi, An alternative with ggplot2, library(ggplot2) ggplot(data=coords) + geom_segment(aes(x=a, xend=b, y=c, yend=c)) HTH, baptiste 2009/11/16 David Winsemius : > > On Nov 16, 2009, at 12:40 PM, Tim Smith wrote: > >> Hi, >> I wanted to make a graph with the following table (2 rows, 3 columns

Re: [R] printing a single row, but dont know which row to print

2009-11-16 Thread baptiste auguie
Hi, Try this, set.seed(2) # reproducible d = matrix(sample(1:20,20), 4, 5) d d[ d[ ,2] == 18 , ] You may need to test with all.equal if your values are subject to rounding errors. HTH, baptiste 2009/11/16 frenchcr : > > > I have 20 columns of data, and in column 5 I have a value of 17600 but

Re: [R] in excel i can sort my dataset, what do i use in R

2009-11-16 Thread baptiste auguie
?order ?sort 2009/11/16 frenchcr : > > > > In excel a handy tool is the sort data by column ...i.e. i can highlight the > whole dataset and sort it according to a particular column...like sort the > data in a column in acending or decending order where all the other columns > change aswell. > > I

Re: [R] extracting the last row of each group in a data frame

2009-11-16 Thread baptiste auguie
Hi, You could try plyr, library(plyr) ddply(d,.(Name), tail,1) Name Value 1A 3 2B 8 3C 2 4D 3 HTH, baptiste 2009/11/16 Hao Cen : > Hi, > > I would like to extract the last row of each group in a data frame. > > The data frame is as follows > > Name Value > A

Re: [R] CM Fonts in PDF output

2009-11-17 Thread baptiste auguie
Hi, Not answering your question, but the tikzDevice package is another option if you want to match LaTeX fonts seamlessly. HTH, baptiste 2009/11/17 Markus Jochmann : > > Hi! > > On Linux I try to produce pdf graphs with computer modern fonts so that they > look nice in LaTeX documents. I run fo

Re: [R] Lattice plot

2009-11-18 Thread baptiste auguie
x2: >> x2 >  chr start1 end1 meth positive > 1   1     10   20  1.5        y > 4   1     35   70  3.0        y > 5   1    120  140 -1.3        n > 6   1    180  190  0.2        y > > > ## Code courtesy of BAPTISTE AUGUIE > library(ggplot2) > ggplot(data=x2) +

[R] parsing numeric values

2009-11-18 Thread baptiste auguie
Dear list, I'm seeking advice to extract some numeric values from a log file created by an external program. Consider the following example, input <- readLines(textConnection( "some text =1.3770E-03 =3.4644E-07 =1.9412E-04 =4.8840E-08 other text =1.3770E-0

Re: [R] parsing numeric values

2009-11-18 Thread baptiste auguie
h case we do not need combine > - \\d+ matches one or more digits > - \\. matches a decimal point > - [-+]? matches -, + or nothing (i.e. an optional sign). > - parentheses around the regular expression not needed > > On Wed, Nov 18, 2009 at 7:28 AM, Henrique Dallazuanna > wro

Re: [R] parsing numeric values

2009-11-18 Thread baptiste auguie
s reasonably general, but I haven't checked it > carefully and would appreciate folks pointing out where it trips up (e.g. > perhaps with NA's). > > Best, > > Bert Gunter > Genentech Nonclinical Biostatistics > >  -Original Message- > From: r-help-boun

Re: [R] parsing numeric values

2009-11-18 Thread baptiste auguie
>          V3         V6 > 1 0.00137700 3.4644e-07 > 2 0.00019412 4.8840e-08 > 3 0.00137700 3.4644e-07 > 4 0.00019412 4.8840e-08 > > > > On Wed, Nov 18, 2009 at 1:54 PM, baptiste auguie > wrote: >> Hi, >> >> Thanks for the alternative approach. Howe

Re: [R] name of a name

2009-11-19 Thread baptiste auguie
Hi, Try this, d <- data.frame(a=1:4, b=3:6) var <- "a" mean(d[var]) ## or, if you are not aware of ## fortune("parse") xx <- paste("d$",var, sep="") mean(eval(parse(text=xx))) HTH, baptiste 2009/11/19 William Simpson : > I have quite a complicated problem that's hard to describe. > > S

Re: [R] ddply function nesting problems

2009-11-19 Thread baptiste auguie
Hi, I think your ddply call with a calculation inside ".( )" is the problem. Are you sure you need to do this? Performing the cut outside ddply seems to work fine, determine_counts<-function() { min_range<-1 max_range<-30 bin_range_size<-5 Me_df<-data.frame(Data

Re: [R] How to concatenate expressions

2009-11-20 Thread baptiste auguie
Hi, You can try this, though I hope to learn of a better way to do it, a = c(quote(alpha),quote(beta),quote(gamma)) b = lapply(1:3, function(x) as.character(x)) c = c(quote('-10'^th), quote('-20'^th), quote('-30'^th)) testplot <- function(a,b,c) { text <- lapply(seq_along(a), function(i

Re: [R] Define return values of a function

2009-11-22 Thread baptiste auguie
hi, Try making your last line invisible( list(table=xtb, elbat=btx) ) HTH, baptiste 2009/11/22 Soeren.Vogel : > I have created a function to do something: > > i <- factor(sample(c("A", "B", "C", NA), 793, rep=T, prob=c(8, 7, 5, 1))) > k <- factor(sample(c("X", "Y", "Z", NA), 793, rep=T, prob

Re: [R] How to make a matrix of a number of factors?

2009-11-22 Thread baptiste auguie
Hi, Try this, do.call(expand.grid, lapply(7:3, seq, from=1)) HTH, baptiste 2009/11/22 Peng Yu : > I use the following code to generate a matrix of factors. I'm > wondering if there is a way to make it more general so that I can have > any number of factors (not necessarily 5). > > a=3 > b=4

Re: [R] lattice: plotting in a loop

2009-11-25 Thread baptiste auguie
Hi, it's a FAQ, you need to print() the plot, http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f baptiste 2009/11/25 Ryan Archer : > Hi, > > I'm having trouble seeing graphics output from lattice xyplot() when called > from inside a for loop: > > x <-

Re: [R] Does nargin and nargout work with R functions?

2009-11-26 Thread baptiste auguie
Hi, I think you can use match.call() to retrieve the number of arguments passed to a function (see below), but I don't think nargout makes sense in R like it does in Matlab. foo <- function(...){ print(match.call()) nargin <- length(as.list(match.call())) -1 print(nargin) } foo(a=1, b=2)

Re: [R] Concave hull

2009-11-26 Thread baptiste auguie
2009/11/26 Ted Harding : > Raising a rather general question here. > > This is a tantalising discussion, but the notion of "concave hull" > strikes me as extremely ill-defined! > > I'd like to see statement of what it is (generically) supposed to be. I'm curious too, but I can imagine the followin

Re: [R] Concave hull

2009-11-27 Thread baptiste auguie
dea: > alphahull, phull is other package, > > kjetil > > On Thu, Nov 26, 2009 at 6:11 PM, baptiste auguie > wrote: >> 2009/11/26 Ted Harding : >>> Raising a rather general question here. >>> >>> This is a tantalising discussion, but the notion of

Re: [R] Simple Function doesn't work?

2009-11-27 Thread baptiste auguie
Hi, The error message, Error in grid[i] <- x + (i - 1) * (y - x)/m : object of type 'closure' is not subsettable indicates that "grid" is actually known to R as a function (type grid to see its definition). You can define your own variable with the same name, but that needs to be done before t

Re: [R] Replace Values in Matrix

2009-11-27 Thread baptiste auguie
Hi, Try this, matrizt[is.na(matrizt)] <- 0 HTH, baptiste 2009/11/27 Romildo Martins : > Hello, > > how to replace the "NA" by number zero? > >> matrizt >                 [,1]           [,2]             [,3]        [,4] > [1,] 1.000            NA             NA         NA > [2,] 0.6717685 0

Re: [R] Why .Diag and .asSparse are not accessible in R sessions?

2009-11-29 Thread baptiste auguie
Hi, They're not exported from the stats namespace, stats:::.Diag stats:::.asSparse ?":::" HTH, baptiste 2009/11/29 Peng Yu : > '.Diag' and '.asSparse' are defined in contrast.R. I'm wondering why I > don't see them in my R session. Is it because that they start with > '.'? > > ___

Re: [R] "subset" or "condition" as argument to a function

2009-12-01 Thread baptiste auguie
Hi, an alternative to parse() is to use quote and bquote, set.seed(123) d = data.frame(a=letters[1:5], b=1:10, c=sample(0:1, 10, repl=TRUE)) cond1 <- quote(a=="b") cond2 <- quote(b < 6) cond3 <- bquote(.(cond1) & .(cond2)) subset(d, eval(cond1)) subset(d, eval(cond2)) subset(d, eval(cond3)) HT

Re: [R] ggplot legend for multiple time series

2009-12-01 Thread baptiste auguie
Hi, I don't understand why you used scale_manual_colour if you want only black lines. To have different line types in the legend you can map the linetype to the data, huron <- data.frame(year=1875:1972, level=LakeHuron) ggplot(huron, aes(year)) + geom_line(aes(y=level+5, linetype="above")) +

Re: [R] multidimensional point.in.polygon??

2009-12-04 Thread baptiste auguie
"outside the convex hull", > hence my question. > > In searching r-project.org I came across a thread in which baptiste auguie > said "one general way to do this would be to compute the convex hull > (?chull) of the augmented set of points and test

Re: [R] Apparent different in symbol scaling between xyplot and grid.points

2009-12-04 Thread baptiste auguie
Hi, I think the size mismatch occurs because of a different default for the fontsize (and grid.points has a size of 1 character by default). Compare the following two examples, # default grid.newpage() pushViewport(viewport(x=unit(0.5, "npc"), y=unit(0.5, "npc"))) lplot.xy(data.frame(x=0.55,y=0.5

Re: [R] User's function

2009-12-04 Thread baptiste auguie
Hi, try ?do.call do.call(cbind, replicate(3, 1:10, simplify=FALSE)) HTH, baptiste 2009/12/4 Lisa : > > Hello, All, > > I want to write a function to do some works based on the arguments. For > example, bind some variables (arguments) as this: > > myfunction <- function(arg1, arg2, arg3, …) > {

Re: [R] adding bmp/jpg/gif to an existing plot

2009-12-04 Thread baptiste auguie
Hi, If you can first convert the image to ppm format, the pixmap package has an addlogo function that can do just what you want, x <- read.pnm(system.file("pictures/logo.ppm", package="pixmap")[1]) plot(1:10,1:10) addlogo(x, px=c(2, 4), py=c(6, 8), asp=1) One could probably get inspiration from

Re: [R] Referencing variable names rather than column numbers

2009-12-05 Thread baptiste auguie
Hi, Try this, cor(pollute[ ,c("Pollution","Temp","Industry")]) and ?"[" in particular, "Character vectors will be matched to the names of the object " HTH, baptiste 2009/12/5 John-Paul Ferguson : > I apologize for how basic a question this is. I am a Stata user who > has begun using R, and th

Re: [R] A GGPLOT ploting question

2009-12-07 Thread baptiste auguie
Hi, I think you have two options: 1- use a specific formatter in scale_x_continuous, e.g. last_plot + scale_x_continuous(formatter="percent") 2- specify breaks and labels, last_plot + scale_x_continuous(breaks=c(2,6), labels=paste(c(2,6),"%")) HTH, baptiste 2009/12/7 Megh : > > library(ggp

Re: [R] outputting functions in lapply

2009-12-07 Thread baptiste auguie
Hi, I was about to send the exact same answer as you just received, so I'll add a note instead. Your problem looks a bit like Currying, Curry <- # original from roxygen function (f, ..., .left=TRUE) { .orig = list(...) function(...){ if(.left) {args <- c(.orig, list(...))} else {

Re: [R] How to apply five lines of code to ten dataframes?

2009-12-07 Thread baptiste auguie
Hi, You could define a function that does the calculations for a given data.frame and apply it to all your data.frames, d1 <- data.frame(a=1:10, b=rnorm(10)) d2 <- data.frame(a=-(1:10), b=rnorm(10)) calculations <- function(d){ if(is.character(d)) d <- get(d) transform(d, c =

Re: [R] Greek symbols on "ylab=" using barchart() {Lattice}

2009-12-09 Thread baptiste auguie
Hi, try this, barchart(1:2, ylab=expression(mu*g/m^3)) ?plotmath baptiste 2009/12/9 Peng Cai : > Hi All, > > I'm trying to write "ug/m3" as y-label, with greek letter "mu" replacing "u" > AND "3" going as a power. > > These commands works in general: > > plot.new() > text(0.5, 0.5, expression(

Re: [R] Greek symbols on "ylab=" using barchart() {Lattice}

2009-12-09 Thread baptiste auguie
space between > "Concentration" and "(mu*g/m^3)". > > Thanks again, > Peng Cai > > On Wed, Dec 9, 2009 at 12:02 PM, baptiste auguie < > baptiste.aug...@googlemail.com> wrote: > >> Hi, >> >> try this, >> >> barchart(1:2, yl

Re: [R] multidimensional point.in.polygon??

2009-12-10 Thread baptiste auguie
I feel I > and Baptiste are wandering in the dark :-( > > Any hints? > > Thanks in advance, > > Keith Jewell > - > "baptiste auguie" wrote in message > news:de4e29f50912040550m71fbffafnfa1ed6e0f4451...@mail.gmail.

Re: [R] Avoid for-loop in creating data.frames

2009-12-10 Thread baptiste auguie
Hi, Is the following close enough? apply(set2, 2, function(x) x[is.na(x)]) HTH, baptiste 2009/12/10 Andreas Wittmann : > Dear R-users, > > after several tries with lapply and searching the mailing list, i want to > ask, wheter and how it is possibly to avoid the for-loop in the following > pie

Re: [R] mutlidimensional in.convex.hull (was multidimensional point.in.polygon??)

2009-12-11 Thread baptiste auguie
2009/12/10 Charles C. Berry : [snipped] > Many? > > >> set.seed(1234) >> ps <- matrix(rnorm(4000),ncol=4) >> phull <-  convhulln(ps) >> xs <- matrix(rnorm(1200),ncol=4) >> phull2 <- convhulln(rbind(ps,xs)) >> nrp <- nrow(ps) >> nrx <- nrow(xs) >> outside <- unique(phull2[phull2>nrp])-nrp >> done <-

Re: [R] get the enclosing function name

2009-12-11 Thread baptiste auguie
Hi, .NotYetImplemented gives an example, function () stop(gettextf("'%s' is not implemented yet", as.character(sys.call(sys.parent())[[1L]])), call. = FALSE) HTH, baptiste 2009/12/11 Hao Cen : > Hi, > > Is there a way to get the enclosing function name within a function? > > For example,

Re: [R] code for [[.data.frame

2009-12-13 Thread baptiste auguie
`[[.data.frame` and more generally see Rnews Volume 6/4, October 2006 "Accessing the Sources". HTH, baptiste 2009/12/13 Guillaume Yziquel : > Hello. > > I'm currently trying to wrap up data frames into OCaml via OCaml-R, and I'm > having trouble with data frame subsetting: > >> # x#column 1;;

Re: [R] Combinations

2009-12-14 Thread baptiste auguie
Hi, Try this, apply(expand.grid(letters[1:3], letters[24:26]), 1, paste,collapse="") [1] "ax" "bx" "cx" "ay" "by" "cy" "az" "bz" "cz" ?expand.grid HTH, baptiste 2009/12/14 Amelia Livington : > > Dear R helpers, > > I am working on the scenario analysis pertaining to various interest rates. >

Re: [R] problem with a densityplot

2009-12-16 Thread baptiste auguie
FAQ: http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f you need to print() HTH, baptiste 2009/12/16 c...@autistici.org : > Hi, > i have a script how i launch lattice to make a densityplot. > in the script: > > jpeg(file="XXX.jpg") > densityplot(~f_di

[R] fortune-like FAQ search

2009-12-16 Thread baptiste auguie
Dear list, I'm not so familiar with the internals of the fortunes package, but I really like the interface. I was wondering if someone had implemented a similar functionality to parse the entries of the R FAQ < http://cran.r-project.org/doc/FAQ/R-FAQ.html >. Say, if I was to answer a question "Wh

Re: [R] mutlidimensional in.convex.hull (wasmultidimensionalpoint.in.polygon??)

2009-12-18 Thread baptiste auguie
Hi, Excellent, thanks for doing this! I had tried the 2D case myself but I was put off by the fact that Octave's convhulln had a different ordering of the points to R's geometry package (an improvement to Octave's convhulln was made after it was ported to R). I'm not sure how you got around this

[R] expand.grid game

2009-12-19 Thread baptiste auguie
Dear list, In a little numbers game, I've hit a performance snag and I'm not sure how to code this in C. The game is the following: how many 8-digit numbers have the sum of their digits equal to 17? The brute-force answer could be: maxi <- 9 # digits from 0 to 9 N <- 5 # 8 is too large test <- 1

Re: [R] expand.grid game

2009-12-19 Thread baptiste auguie
2009/12/19 David Winsemius : > > On Dec 19, 2009, at 9:06 AM, baptiste auguie wrote: > >> Dear list, >> >> In a little numbers game, I've hit a performance snag and I'm not sure >> how to code this in C. >> >> The game is the following: h

Re: [R] expand.grid game

2009-12-19 Thread baptiste auguie
)==17) {idx<-c(idx,i)}) user system elapsed 34.050 1.109 35.791 I'm surprised by idx<-c(idx,i), isn't that considered a sin in the R Inferno? Presumably growing idx will waste time for large N. Thanks, baptiste 2009/12/19 David Winsemius : > > On Dec 19, 2009, at 1:36

Re: [R] expand.grid game

2009-12-19 Thread baptiste auguie
) p Best, baptiste [David: sorry for the duplicate, i initially sent an attachment that was too large for the list] > 2009/12/19 David Winsemius : >> >> On Dec 19, 2009, at 2:10 PM, David Winsemius wrote: >> >>> >>> On Dec 19, 2009, at 1:36 PM, baptiste

Re: [R] expression()

2009-12-20 Thread baptiste auguie
Hi, try this, ylab = expression(Temperature~(degree*F)) ?plotmath baptiste 2009/12/20 Kim Jung Hwa : > Hi All, > > I'm wondering if its possible to write degree in symbol. > > I would like y-label as "Temperature (degreeF)". where degree should be in > symbols. Thanks in advance, > > #R Code >

[R] basic proto question

2009-12-20 Thread baptiste auguie
Dear list, I made the following example of a proto object that contains some data and a spline interpolation. I don't understand why test$predict() fails with this error message: Error: evaluation nested too deeply: infinite recursion / options(expressions=)? Best regards, baptiste test <- pro

Re: [R] basic proto question

2009-12-20 Thread baptiste auguie
to refer to stats::predict.  Change the line that calls predict to: > > stats::predict(.$spline(), x.fine) > > On Sun, Dec 20, 2009 at 11:49 AM, baptiste auguie > wrote: >> Dear list, >> >> I made the following example of a proto object that contains some data >>

Re: [R] How to rotate an axis?

2009-12-20 Thread baptiste auguie
Hi, Do you want a ternary plot? http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=34 It's easy to rotate an axis with Grid graphics, library(grid) pushViewport(viewport(0.5,0.5, width=0.5, height=unit(3, "lines"))) grid.xaxis(at=seq(-0.5,0.5,by=0.1), vp=viewport(x=1, angle=-60)) HTH

Re: [R] expand.grid game

2009-12-21 Thread baptiste auguie
rybody who participated, I have learned interesting things from a seemingly innocuous question. Best regards, baptiste 2009/12/21 Robin Hankin : > Hi > > library(partitions) > jj <- blockparts(rep(9,8),17) > dim(jj) > > gives 318648 > > > HTH > > rk

Re: [R] String question

2009-12-23 Thread baptiste auguie
Will this do? temp <- paste("m", 1:3, sep="",collapse=",") HTH, baptiste 2009/12/23 Knut Krueger : > Hi to all > > I need a string like > temp <- paste("m1","m2","m3",sep=",") > But i must know how many items are in the string,afterwards > the other option would be to use a vector > temp <- c("

Re: [R] String question

2009-12-23 Thread baptiste auguie
Isn't paste doing exactly this? temp <- c("November", "December","Monday","Tuesday") paste(temp, collapse=",") # "November,December,Monday,Tuesday" HTH, baptiste 2009/12/23 Ted Harding : > On 23-Dec-09 11:08:02, Knut Krueger wrote: >> Jim Lemon schrieb: >>> Not as easy as I thought it would be

Re: [R] PGF Device

2009-05-07 Thread baptiste auguie
X formulas. Best wishes, baptiste On 7 May 2009, at 14:39, Dieter Menne wrote: Lasse Bombien phonetik.uni-muenchen.de> writes: Am Mittwoch, den 06.05.2009, 16:08 +0200 schrieb baptiste auguie: I think the pgfSweave project on R-forge is working on this (as far as i know it currently r

Re: [R] howto find x value where x=max(x)

2009-05-08 Thread baptiste auguie
try this: with(fp, Frequenz[which.max(AmpNorm)]) baptiste On 8 May 2009, at 14:49, Jonas Stein wrote: Hi, fp is a data frame like this ,[ fp ] |Frequenz AmpNorm | 1 3322 0.0379490639 | 2 3061 0.0476033058 | 3 2833 0.0592954124 | 4 2242 0.1275510204 ` i

Re: [R] aggregate over x cases

2009-05-11 Thread baptiste auguie
try this, library(plyr) ddply(d, .(block, trial), function(.d) .d[1:2, ]) block trial x y 1 1 1 605 150 2 1 1 603 148 3 1 2 607 148 4 1 2 605 152 HTH, baptiste On 11 May 2009, at 13:49, Jens Bölte wrote: Hello, I have been struggling for quite some

Re: [R] aggregate over x cases

2009-05-11 Thread baptiste auguie
good point, i forgot about head (!), library(plyr) ddply(d, .(block, trial), head, 2) block trial x y 1 1 1 605 150 2 1 1 603 148 3 1 2 607 148 4 1 2 605 152 On 11 May 2009, at 14:04, Gabor Grothendieck wrote: Try this: do.call(rbind, by(DF, DF[1:2], he

Re: [R] Read many .csv files into an R session automatically, without specifying filenames

2009-05-11 Thread baptiste auguie
Hi, I once made this function (essentially the same as Romain), assignFiles <- function (pattern = "csv", strip = "(_|.csv|-| )", ...) # strip is any pattern you want to remove from the filenames { listFiles <- list.files(pattern = pattern, all.files = FALSE, full.names = FALSE,

Re: [R] From two colors to 01 sequences

2009-05-12 Thread baptiste auguie
Depending on the nature of your pdf file, it may be possible to use the grImport package. I've never used it before, but a quick test seems promising, > # create a test picture > colorStrip <- > function (colors, draw = T) > { > x <- seq(0, 1 - 1/ncol(colors), length = ncol(colors)) >

Re: [R] read multiple large files into one dataframe

2009-05-13 Thread baptiste auguie
I'd first try plyr and see if it's efficient enough, library(plyr) listOfFiles <- list.files(pattern= ".txt") d <- ldply(listOfFiles, read.table) str(d) alternatively, d <- do.call(rbind, lapply(listOfFiles, read.table)) HTH, baptiste On 13 May 2009, at 12:45, SYKES, Jennifer wrote:

Re: [R] specify the number of decimal numbers

2009-05-14 Thread baptiste auguie
Alternatively, signif(c(pi,exp(1)), 3) ?signif # and others in that page HTH, baptiste On 14 May 2009, at 13:47, jim holtman wrote: Depending on what you want to do, use 'sprintf': x <- 1.23456789 x [1] 1.234568 as.character(x) [1] "1.23456789" sprintf("%.1f %.3f %.5f", x,x,x) [1]

Re: [R] Graphical output format

2009-05-15 Thread baptiste auguie
On 15 May 2009, at 10:01, Prof Brian Ripley wrote: On Fri, 15 May 2009, Dieter Menne wrote: Stats Wolf gmail.com> writes: Postscript, however, does not have to be what I need for two reasons. First, it does not accept some special characters from foreign languages (exactly like PDF). '

Re: [R] ggplot2: annotating plot with mathematical formulae

2009-05-16 Thread baptiste auguie
If you're desperate for a workaround, you might want to try this example using pgfSweave, http://ggplot2.wik.is/Mathematical_annotations On a similar vein, you could try psfrag replacements with a postscript device (there is some code for this on the list archives). Feel free to comment /

Re: [R] Simple plotting errors

2009-05-18 Thread baptiste auguie
I'd suggest you first combine the 12 data.frames into one, using melt() from the reshape package. makeDummy <- function(.){ # since you don't provide a reproducible example data.frame(x=letters[1:10], y=rnorm(10)) } listOf12DataFrames <- lapply(1:12, makeDummy) library(re

[R] size of point symbols

2009-05-21 Thread baptiste auguie
Dear list, This might be a topic for r-devel but i may be missing something obvious. I don't understand the rationale in the absolute sizes of the point symbols, and I couldn't find it documented. The example below uses Grid to check the size of the symbols against a square of 10mm x 10mm

Re: [R] Behavior of seq with vector from

2009-05-22 Thread baptiste auguie
Hi, Perhaps you can try this, seq.weave <- function(froms, by, length, ... ){ c( matrix(c(sapply(froms, seq, by=by, length = length/2, ...)), nrow=length(froms), byrow=T) ) } seq.weave(c(2, 3), by=3, length=8) seq.weave(c(2, 3, 4), by=

Re: [R] reduce size of plot inside window and place legend beside plot

2009-05-27 Thread baptiste auguie
Try this and see if it helps (if not, please help improving it), http://wiki.r-project.org/rwiki/doku.php?id=tips:graphics-misc:legendoutside HTH, baptiste On 27 May 2009, at 20:31, Wade Wall wrote: Hi all, I have been trying to figure out how to place a legend beside a plot, rather than w

Re: [R] How this addition works?

2009-05-28 Thread baptiste auguie
recycling rule: repeat the shorter element as many times as necessary, all.equal(1:2 + 1:10 , rep(1:2, length=10) + 1:10) # TRUE HTH, baptiste On 28 May 2009, at 22:00, bogaso.christofer wrote: I have following addition : 1:2 + 1:10 [1] 2 4 4 6 6 8 8 10 10 12 I could not unde

[R] grid.edit() for ggplot2

2009-05-31 Thread baptiste auguie
Dear all, I'm trying to access and modify grobs in a ggplot2 plot. The basic idea for raw Grid objects I understand from Paul Murrell's R graphics book, or this page of examples, http://www.stat.auckland.ac.nz/~paul/grid/copygrob/copygrobs.R However I can't figure out how to apply this to

Re: [R] ggplot2: How to export several plots with same width?

2009-06-01 Thread baptiste auguie
I'm not sure it's currently possible with ggplot2 (lattice and latticeExtra offer some workarounds for this). Perhaps you can try this, http://wiki.r-project.org/rwiki/doku.php?id=tips:graphics-ggplot2:sharelegend (neater here: ) http://learnr.wordpress.com/2009/05/26/ggplot2-two-or-more-plo

Re: [R] Axis label spanning multiple plots

2009-06-01 Thread baptiste auguie
you can use title() with the sub argument, title(sub="x label", outer=T) # you might want to play around with line argument baptiste On 1 Jun 2009, at 22:03, Andre Nathan wrote: Hello On Wed, 2009-05-27 at 13:38 -0600, Greg Snow wrote: Create an outer margin (see ?par), then use mtext to

Re: [R] Axis label spanning multiple plots

2009-06-01 Thread baptiste auguie
H, baptiste On 1 Jun 2009, at 22:30, Andre Nathan wrote: > On Mon, 2009-06-01 at 22:24 +0200, baptiste auguie wrote: >> you can use title() with the sub argument, >> >> title(sub="x label", outer=T) # you might want to play around with >> line argument &

Re: [R] Fwd: subset dataframe/list

2009-06-01 Thread baptiste auguie
your data *seems* to have an unusual decimal separator. That would explain why the two-step conversion to numeric fails, while the brute conversion to numeric always gives the factor integer codes. I don't know where your data comes from (str() would be helpful in any case), but if you read

Re: [R] Fwd: subset dataframe/list

2009-06-01 Thread baptiste auguie
of course, this only applies if you have, getOption("OutDec") == "." In any case, follow David's suggestions. baptiste On 1 Jun 2009, at 23:20, baptiste auguie wrote: your data *seems* to have an unusual decimal separator. That would explain why the two-step co

Re: [R] grid.edit() for ggplot2

2009-06-02 Thread baptiste auguie
Perfect, thank you! Thanks also to Gabor G. for the links. baptiste On 2 Jun 2009, at 01:30, Paul Murrell wrote: Hi baptiste auguie wrote: Dear all, I'm trying to access and modify grobs in a ggplot2 plot. The basic idea for raw Grid objects I understand from Paul Murrell's

[R] type = 'b' with Grid

2009-06-04 Thread baptiste auguie
Dear all, I feel like I've been reinventing the wheel with this code (implementing type = 'b' for Grid graphics), http://econum.umh.ac.be/rwiki/doku.php?id=tips:graphics-grid:linesandpointsgrob Has anyone here attempted this with success before? I found suggestions of overlapping large white

Re: [R] Mixed Latin, Greek and subscript characters in axis label

2009-06-05 Thread baptiste auguie
Jonathan Williams wrote: Dear R-helpers, I have been trying to figure out how to plot a graph with an axis label consisting of a mixture of Latin, Greek and subscript characters. Specifically, I need to write A[beta]{1-42}, where A is Latin script A, [beta] is Greek lower case beta and {1-42} is

Re: [R] mean

2009-06-08 Thread baptiste auguie
Ben Bolker wrote: amor Gandhi wrote: Hi, I have gote the following data x1 <- c(rep(1,6),rep(4,7),rep(6,10)) x2 <- rnorm(length(x1),6,1) data <- data.frame(x1,x2) and I would like to compute the mean of the x2 for each individual of x1, i. e. x1=1,4 and 6? You'll probably get sev

Re: [R] Combining elements of vectors

2009-06-08 Thread baptiste auguie
Marie Sivertsen wrote: Dear list, I have a vector of elements which I want to combined each with each, but none with itself. For example, v <- c("a", "b", "c") and I need a function 'combine' such that combine(v) [[1]] [1] "a" "b" [[2]] [1] "a" "b" [[3]] [1] "b" "c" I a

[R] removing elements from a "unit" vector

2009-06-09 Thread baptiste auguie
Dear list, I'm quite surprised by this, unit(1:5,"char")[-c(1:2)] #4char 3char # what's going on?? while I expected something like, c(1:5)[-c(1:2)] # 3 4 5 Note that, unit(1:5,"char")[c(1:2)] # 1char 2char # fine ?unit warns about unit.c for concatenating, but also says, It is possible

Re: [R] Extracting Sequence Data from a Vector

2009-06-10 Thread baptiste auguie
jim holtman wrote: try this: Oh well, i spent the time writing this so i might as well post my (almost identical) solution, x<-c(1:3, 6: 7, 10:13) breaks = c(TRUE, diff(x) != 1) data.frame(start = x[breaks], length = tabulate(cumsum(breaks))) Hoping this works, baptiste x [1

Re: [R] removing elements from a "unit" vector

2009-06-12 Thread baptiste auguie
Paul Murrell wrote: Hi The bug is now fixed in the development version (thanks to Duncan for the diagnosis and suggested fix). Paul Thank you both for your help and dedication! Best regards, baptiste -- _ Baptiste Auguié School of Physics University of Exe

Re: [R] Squaring one column of data

2009-06-12 Thread baptiste auguie
Kenny Larsen wrote: Hi, A fairly basic problem I think, here although searching the inetrnet doesn't seem to reveal a solution. I have a dataset with two columns of real numbers. It is read in via read.table. I simply need to square the data in the second column and then plot it. I have tried ex

Re: [R] a proposal regarding documentation

2009-06-15 Thread baptiste auguie
I knew I had seen this in action! But as you mention, most pages only display ~~RDOC~~ at the moment. I second the idea of using the wiki for such collaborative work. If the current (r-devel) version of all help pages could be automatically copied to the wiki, users would have a convenient way t

Re: [R] Assigning Data a name from within another variable?

2009-06-15 Thread baptiste auguie
Kenny Larsen wrote: Hi All, I have hunted high and low and tried dozens of things but have yet to achieve the result I require. Below is my code (taken mostly from another thread on here) thus far: files<-list.files() files<-files[grep('.wm4', files)] labels<-gsub('.wm4', '',files) for(i in 1:

Re: [R] display SVG, PNG, GIF, JPEG, TIFF, PPM in new plot frame

2009-06-15 Thread baptiste auguie
Hi, the grImport package provides some functionality for svg and postscript graphics, http://cran.r-project.org/web/packages/grImport/index.html Best, baptiste Robbie Morrison wrote: Dear R-help I want to display an image file in a new plot frame. SVG is my preferred format, but I ca

Re: [R] confusion on levels() function, and how to assign a wanted order to factor levels, intentionally?

2009-06-16 Thread baptiste auguie
Hi, I tend to use a slightly modified version of stats::relevel, (from an old thread on this list), 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(

Re: [R] confusion on levels() function, and how to assign a wanted order to factor levels, intentionally?

2009-06-16 Thread baptiste auguie
Commenting on this, is there a strong argument against modifying relevel() to reorder more than one level at a time? I started a topic a while back ("recursive relevel", https://stat.ethz.ch/pipermail/r-help/2009-January/184397.html) and I've happily used the proposed change since then by over

Re: [R] Superscript in y-axis of plot

2009-06-16 Thread baptiste auguie
For the sake of brevity, I like to use this trick, plot(0, 0) mtext(~"Monthly Precipitation (mm x "*10^2*"/month)") HTH, baptiste __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide htt

Re: [R] Testing if all elements are equal in a vector/matrix

2009-06-16 Thread baptiste auguie
utkarshsinghal wrote: Hi Jim, What you are saying is correct. Although, my computer might not have same speed and I am getting the following for 10M entries: user system elapsed 0.559 0.038 0.607 Moreover, in the case of character vectors, it gets more than double. In my modeling,

<    1   2   3   4   5   6   7   8   >