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

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],

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)) y -

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] 1.2

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 stats.wolf at 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

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)

[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

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),

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

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

[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

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: )

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

[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

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}

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 seven

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 am not very

[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 to

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

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

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

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

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

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

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(lev)

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

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

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

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

2009-06-16 Thread baptiste auguie
[correcting a stupid error in my previous post] testTwoStages - function(x, y, head.stop = 100){ if(!isTRUE(all(head(x, head.stop) == head(y, head.stop { print(paste(quick test returned FALSE)) return(FALSE) } else { full.test = isTRUE(all(tail(x, length(x) - head.stop) == tail(y,

Re: [R] searching help for partial matches

2009-06-17 Thread baptiste auguie
Steve Jaffe wrote: The situation is that I know there is a function and know approximately what the name is, and want to find the exact name. Is there a way of searching for near-matches (similar to unix apropos). For example, I know there is a function called something like allequal (or

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

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 use

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

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
, 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 some advice on how to wrap a R function

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

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

2009-03-15 Thread baptiste auguie
very comfortable with factors. Could you please give me some advice? Thank you very much. baptiste auguie-2 wrote: 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

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

2009-03-16 Thread baptiste auguie
. -thomas On Sun, 15 Mar 2009, baptiste auguie wrote: I've put together a rough R port of that C code [*] in a package on r-forge: http://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/pkg/spectral/?root=photonics http://r-forge.r-project.org/R/?group_id=160 ( package spectral

Re: [R] Simple Plot with Grid's Viewport

2009-03-19 Thread baptiste auguie
On 19 Mar 2009, at 07:22, Dieter Menne wrote: Gundala Viswanath gundalav at gmail.com writes: I have the following code that try to plot simple sinus curve into 2x2 grid in 1 page. But this code of mine create 4 plots in 1 page each. What's wrong with my approach? ... library(lattice)

Re: [R] functions within a list

2009-03-20 Thread baptiste auguie
Hi, you could have a look at the doBy package which makes these operations easier. Hadley's plyr package is also another option. baptiste On 20 Mar 2009, at 01:01, Altaweel, Mark R. wrote: Hi, I am trying to perform various functions on a list with a number of elements. For example. I

Re: [R] Multi-line texts in plots

2009-03-20 Thread baptiste auguie
Hi, it would help if you provided a minimal example. Here is one approach I often use with the plotting package ggplot2, parameters - expand.grid(m=c(0, 1), s=seq(0.1, 1,length=10)) x - seq(-5, 5, length=300) foo - function(m, s){ data.frame(x=x, y=dnorm(x, m, s), m=factor(m),

Re: [R] Help with functions within a list

2009-03-20 Thread baptiste auguie
is not as large as I would expect. Thanks again in advance. Mark -Original Message- From: baptiste auguie [mailto:ba...@exeter.ac.uk] Sent: Fri 3/20/2009 4:32 AM To: Altaweel, Mark R. Cc: r-help@r-project.org Subject: Re: [R] functions within a list Hi, you could have a look at the doBy

Re: [R] lattice multipanel strip placement - with two factors

2009-03-23 Thread baptiste auguie
I'm not sure I understood your problem (can you provide an reproducible example?), but perhaps you can try useOuterStrips() in the latticeExtra package (the formatting becomes similar to that of the ggplot2 package, perhaps another option to consider) Hope this helps, baptiste On 23 Mar

Re: [R] Problems with combining plots

2009-03-23 Thread baptiste auguie
On 23 Mar 2009, at 11:52, johnhj wrote: I have still the same problem... As you said I tried with par(mfrow=c(2,1)) and par(mfrow=c(1,2)) but without success. Could R compiler be the problem ? Why not? But may I suggest you try first the following example I sent you yesterday,

Re: [R] Looping of read.table and assignment

2009-03-23 Thread baptiste auguie
You need only one loop, year - 1951:2000 filelist - paste(C:\\Documents and Settings\\Data\ \table_,year,.txt, sep=) filelist for (ii in seq_along(year)) { assign(paste(table_, year[ii], sep=), read.table(file=ifile[ii], header=TRUE, sep=,)) }

Re: [R] Replacing a few variable values within a DataFrame...

2009-03-23 Thread baptiste auguie
On 23 Mar 2009, at 17:39, Jason Rupert wrote: I would like to replace a few varaibles within a data frame. For example, in the dataframe below (contrived) I would like to replace the current housesize value only if the Location is HSV. However, I would like to leave the other values

Re: [R] How to set up a function for Central Limit Theorem

2009-03-23 Thread baptiste auguie
(a - replicate(5,rnorm(10))) colMeans(a) should get you started. HTH, baptiste On 23 Mar 2009, at 18:29, pfc_ivan wrote: I tried using the for (i..) to make 1000 differents sets of numbers, but then I dont know how to get the mean value of all of them... because I dont even think 1000

Re: [R] Manual sort in a for loop

2009-03-25 Thread baptiste auguie
well, the literal answer is that paste(arunoff_,table_year,_temp) is a character vector of length 1 so your indexing cannot work. What you want is to index the data that corresponds to this variable name, ?get But I should stress that this manipulation with assign and get seems completely

[R] [.data.frame and lapply

2009-03-25 Thread baptiste auguie
Dear all, Trying to extract a few rows for each element of a list of data.frames, I'm puzzled by the following behaviour, d - lapply(1:4, function(i) data.frame(x=rnorm(5), y=rnorm(5))) str(d) lapply(d, [, i= c(1)) # fine, this extracts the first columns lapply(d, [, j= c(1, 3)) #

Re: [R] [.data.frame and lapply

2009-03-25 Thread baptiste auguie
thanks to some off-list replies, I got this to work, On 25 Mar 2009, at 18:56, baptiste auguie wrote: Dear all, Trying to extract a few rows for each element of a list of data.frames, I'm puzzled by the following behaviour, d - lapply(1:4, function(i) data.frame(x=rnorm(5), y=rnorm(5

Re: [R] [.data.frame and lapply

2009-03-26 Thread baptiste auguie
this, which is expected (same as d[1:2] ): `[.data.frame`(d, i=1:2) x y 1 0.45141341 0.03943654 2 -0.87954548 1.83690210 3 -0.91083710 0.22758584 4 0.06924279 1.26799176 5 -0.20477052 -0.25873225 Romain baptiste auguie wrote: Dear all, Trying to extract a few

Re: [R] Reading in files with variable parts to names

2009-03-26 Thread baptiste auguie
Hi, If your directory contains only files you want to load anyway, then list.files() is your friend, list.files(pattern = comp) # or pattern =.asc for example If you do need to create the names manually, then you could create the combinations with expand.grid, as in, do.call(paste,

Re: [R] Ploting a matrix

2009-03-27 Thread baptiste auguie
Something like this perhaps, a - matrix(rnorm(5*49), ncol=49) pdf(width=15, height=15) par(mfrow= c(8,6)) apply(a[,-1], 2, plot, x= a[,1]) dev.off() HTH, baptiste On 27 Mar 2009, at 11:05, skrug wrote: Hi evrybody, in a matrix consisting of 49 columns, I would like to plot all

Re: [R] color vectors other than gray()

2009-03-27 Thread baptiste auguie
?colorRamp Hope this helps, baptiste On 27 Mar 2009, at 13:16, Paulo E. Cardoso wrote: I'm trying to create a graph where different cells of a grid (a shapefile) will be painted with a color share scale, where the most easy way is to use gray(). Can I somehow get a vector (gradient) of

Re: [R] color vectors other than gray()

2009-03-27 Thread baptiste auguie
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 I need to discriminate shading level accordingly to the abundance value (level). I don't know how to proceed. Paulo E. Cardoso -Mensagem original- De: baptiste auguie [mailto:ba...@exeter.ac.uk] Enviada: sexta-feira, 27 de Março de 2009

Re: [R] Ploting a matrix

2009-03-27 Thread baptiste auguie
[,-1], 2, plot, x= b[,1]) Also all columns have the same length, [R] states that the length are different. Can you help me? baptiste auguie schrieb: Something like this perhaps, a - matrix(rnorm(5*49), ncol=49) pdf(width=15, height=15) par(mfrow= c(8,6)) apply(a[,-1], 2, plot, x= a[,1

Re: [R] Ploting a matrix

2009-03-27 Thread baptiste auguie
15931 37895 84565 Thanks baptiste auguie schrieb: the result of read.table is a data.frame, not a matrix as you first suggested. Can you copy the result of str(b) so we know what your data is made of? I'm guessing the most elegant solution will be to use the reshape package, followed

Re: [R] Assignment to variables fails to loop

2009-03-27 Thread baptiste auguie
The variable name in your call to assign should vary within the for loop, otherwise you're always assigning the value to the same variable. Consider the following example, listOfNames - c(a, b, c) listOfVariables - c(vara, varb, varc) for(index in seq_along(listOfNames)){

Re: [R] text matching and substitution

2009-03-28 Thread baptiste auguie
yet another attempt, colours - as.character(paste(letters,colours(),stuff,LETTERS)) target - c(red,blue,green,gray) matches - melt(sapply(target, grep, x=colours)) colours[matches$value] - matches$L1 (probably a worse idea than a straight for loop, though) baptiste On 28 Mar 2009,

Re: [R] how to input multiple .txt files

2009-03-30 Thread baptiste auguie
may i suggest the following, a - do.call(rbind, lapply(cust1_files, read.table)) (i believe expanding objects in a for loop belong to the R Inferno) baptiste On 30 Mar 2009, at 12:58, Mike Lawrence wrote: cust1_files = list.files(path=path_to_my_files,pattern='cust1',full.names=TRUE)

Re: [R] Using apply to get group means

2009-03-31 Thread baptiste auguie
Not exactly the output you asked for, but perhaps you can consider, library(doBy) summaryBy(x3~x2+x1,data=x,FUN=mean) x2 x1 x3.mean 1 1 A 1.5 2 1 B 2.0 3 1 C 3.5 4 2 A 4.0 5 2 B 5.5 6 2 C 6.0 the plyr package also provides similar functionality, as do

Re: [R] STACK

2009-04-01 Thread baptiste auguie
perhaps, unlist(d, use.names=F) baptiste On 1 Apr 2009, at 22:15, oscar linares wrote: Dear Rxperts I have a data.frame as follows ABCD 14 710 25 811 36 912 I want to convert it to a data frame with a single row (i.e., stack the columns

Re: [R] how to sort and group the data?

2009-04-02 Thread baptiste auguie
try this, d = read.table(textConnection(USER NAME 12 admin 12 admin 10 admin 10 advertising 61 process 17snapshot 61ticket 61ticket 30snapshot 10advertising 10advertising 10advertising 10advertising ),head=T) str(d) # note that NAME is a

Re: [R] Deleting rows based on identity variable

2009-04-02 Thread baptiste auguie
just for curiosity, `%ni%` - Negate(`%in%`) 1 %ni% c(2,1) [1] FALSE d1[id %ni% c(1,4), ] baptiste On 2 Apr 2009, at 22:17, gina patel wrote: I have another question, if I now want to remove multiple id's e.g. id=1 or 4 is there a simple OR command I can use? I tried d2-(d1[id != 1 |

[R] plyr and table question

2009-04-03 Thread baptiste auguie
Dear all, I'm puzzled by the following example inspired by a recent question on R-help, cc - textConnection(user_id website time 20google0930 21yahoo0935 20facebook1000 25facebook1015 61google

Re: [R] Help pasting string as object name

2009-04-03 Thread baptiste auguie
Hi, Is this what you want? d - data.frame(density.AL = seq(1, 10), density.AK = seq(1, 10), # many others... Date=letters[1:10]) # dummy example library(reshape) melt(subset(d, Date == b), id=Date) BTW, I spotted a few awkward things in your code, st - c(AL, AK)

[R] factorise variables in a data.frame

2009-04-03 Thread baptiste auguie
Dear list, I often need to convert several variables from numeric or integer into factors (before plotting, for instance), as in the following example, d - data.frame( x = seq(1, 10), y = seq(1, 10), z = rnorm(10), a = letters[1:10]) d2 - within(d,

Re: [R] factorise variables in a data.frame

2009-04-03 Thread baptiste auguie
Excellent! I felt it was fairly trivial but i can be quite dense on Friday mornings. I really like the generalisation. Many thanks, baptiste On 3 Apr 2009, at 12:11, Wacek Kusnierczyk wrote: baptiste auguie wrote: Dear list, I often need to convert several variables from numeric

Re: [R] plyr and table question

2009-04-03 Thread baptiste auguie
935 1 4 25 facebook 1015 1 5 61 google 940 1 Have I missed a built-in function to obtain this result? Thanks, baptiste On 3 Apr 2009, at 14:16, hadley wickham wrote: On Fri, Apr 3, 2009 at 4:43 AM, baptiste auguie ba...@exeter.ac.uk wrote: Dear all, I'm puzzled

Re: [R] plyr and table question

2009-04-03 Thread baptiste auguie
of course! Thanks, baptiste On 3 Apr 2009, at 14:48, hadley wickham wrote: On Fri, Apr 3, 2009 at 8:43 AM, baptiste auguie ba...@exeter.ac.uk wrote: That makes sense, so I can do something like, count - function(x){ as.integer(unclass(table(x))) } count(d$user_id) ddply(d

Re: [R] Conversions From standard to metric units

2009-04-03 Thread baptiste auguie
I had a similar need for conversions in optics. I put together several functions and data on r-forge, where it does not clutter CRAN but can still be shared conveniently with others. baptiste On 3 Apr 2009, at 19:27, Duncan Murdoch wrote: stephen sefick wrote: I am starting to use R

Re: [R] help with formula and data= argument

2009-04-05 Thread baptiste auguie
Hi, It seems to me that you could write a generic function myplot() and have different methods for each class of object (like plot does). Either S3 or S4 classes would do I think. Then it is only a matter of making each method work separately. In particular, the method for a formula

Re: [R] comparing columns in a dataframe

2009-04-05 Thread baptiste auguie
Hi, Have you looked at the compare package? It might do what you want (I just remember seeing its description on R News recently but I've never used it), d - data.frame(x=1:10,y=sin(1:10),z=factor(letters[1:10])) d1 - d d1$x[2:3] - jitter(d$x[2:3] ) d2 - subset(d1, !(z %in% c(a,g)))

Re: [R] Collapse data matrix with extra info separated by commas

2009-04-06 Thread baptiste auguie
Here's one attempt with plyr, hopefully Hadley will give you a better solution ( I could not get cast() to do it either) test - data .frame (a=c(A,A,A,A,B,B,B),b=c(1,1,2,2,1,1,1),c=sample(1:7)) ddply(test,.(a,b),.fun=function(.) paste(.)[3]) a b V1 1 A 1c(2, 4) 2 B 1 c(7,

Re: [R] strange (?) behavoir of expand.grid()

2009-04-07 Thread baptiste auguie
Hi, I think it's a FAQ (== vs all.equal to test for equality), and not related to expand.grid. See ?all.equal and ?== You don't need which, gridd[gridd[,2]==0.6 , ] would work fine, or more elegantly (imho), gridd - expand.grid(x=x,y=y ) subset(gridd, factor(x) == 0.6) Hope this

Re: [R] change default output size when using Sweave

2009-04-08 Thread baptiste auguie
On 8 Apr 2009, at 11:44, Duncan Murdoch wrote: Mark Heckmann wrote: Dear Duncan, Thanks for the reply. This works, but unfortunately I need a different solution. My script is supposed to run completely automated and the graphics I produce vary in size each time I run the script. But I

Re: [R] Clear all with/without function()

2009-04-08 Thread baptiste auguie
clr - function () rm(list = ls(pos = .GlobalEnv), pos = .GlobalEnv) this works for me HTH, baptiste On 8 Apr 2009, at 10:50, Taraxacum88 wrote: why rm(list=ls(all=TRUE),envir=globalenv()) is ok but ca-function() rm(list=ls(all=TRUE),envir=globalenv()) ca() does not work? Thank

Re: [R] Howto Plot With Transparent Background

2009-04-08 Thread baptiste auguie
with base graphics, par(bg=NA) see ?par Hope this helps, baptiste On 8 Apr 2009, at 12:54, Gundala Viswanath wrote: Is there a way to do it in R? Especially generating plot in EPS/PDF format. By transparent I mean clear (not white) background. I want to attached it to dark PPT slides. -

Re: [R] xyplot - show values of a series on graph

2009-04-08 Thread baptiste auguie
with ggplot2, d - melt(df2,id=year) qplot(year,value,data=d,colour=variable,geom=c(line,point)) + geom_text(data= subset(d, variable == cars), aes(label=value)) with lattice, my best guess would be to use grid.text in a custom panel function. Hope this helps, baptiste On 8 Apr 2009, at

Re: [R] xyplot - show values of a series on graph

2009-04-08 Thread baptiste auguie
, just=top)} ) baptiste auguie-2 wrote: with ggplot2, d - melt(df2,id=year) qplot(year,value,data=d,colour=variable,geom=c(line,point)) + geom_text(data= subset(d, variable == cars), aes(label=value)) with lattice, my best guess would be to use grid.text in a custom panel function. Hope

Re: [R] turning list into vector/dataframe

2009-04-10 Thread baptiste auguie
try this, do.call(rbind, resample2) #or simply, replicate(1000, Cusum(sample(lambs,replace=F))) you could also look at the plyr package. Hope this helps, baptiste On 10 Apr 2009, at 09:03, Melissa2k9 wrote: Hi, I have used this command : resamples-lapply(1:1000,function(i)

Re: [R] Physical Units in Calculations

2009-04-13 Thread baptiste auguie
Hi, Two thoughts I'd like to share on this subject: 1) Something really cool for conversions between units is the Google search bar: type in 3 inches in cm and you get, 3 inches = 7.62 centimeters or, 3 £ in dollar, 3 UK£ = 4.4007 U.S. dollars or 12 cubic meters to pints,

Re: [R] matching lists

2009-04-14 Thread baptiste auguie
Try this, numbers - c(one,two,three,four) values - c(10,20,30,40) v - list(sample(numbers,3),sample(numbers,2)) v sapply(v,function(.l) values[match(.l, numbers)] ) HTH, baptiste On 14 Apr 2009, at 13:01, Manoel Silva wrote: Dear All, Here's my problem. I have two lists: v [[1]] [1]

Re: [R] subset dataframe by rows using character vector?

2009-04-14 Thread baptiste auguie
Is this what you want? plotNames - c(plot1, plot2, plot3) # plot is probably best left as the name of the base function full.data[full.data$PLOTID %in% plotNames, ] # note the comma HTH, baptiste On 14 Apr 2009, at 15:20, zack holden wrote: Dear List, I'm stuck on what seems like

Re: [R] subset dataframe by rows using character vector?

2009-04-14 Thread baptiste auguie
glad it was helpful. %in% is a logical operator, so you can use ! to negate the result (with parentheses), ! ( 4 %in% 1:3) Alternatively, define a new operator, `%ni%` - Negate(`%in%`) 1 %ni% c(2,1) Next time you ask a follow-up question please send it to the r-help list so others can

Re: [R] Automating object creation

2009-04-14 Thread baptiste auguie
?assign (but are you sure you really want to name all these objects separately? Usually in R you would put them together in a list or a data.frame, it is much more convenient for later manipulations) On 14 Apr 2009, at 18:32, Zachary Patterson wrote: I am new to R. I would like to

Re: [R] How to apply a function to all combinations of the values of 2 or more variables?

2009-04-15 Thread baptiste auguie
I think you want to have a look at the plyr or doBy packages. It would be easier to give a precise answer with a minimal example. HTH, baptiste On 15 Apr 2009, at 18:03, Lane, Jim wrote: Hi, All Forgive me if this is a stupid newbie question. I'm having no luck googling an answer to this,

Re: [R] (hopefully) simple array op

2009-04-15 Thread baptiste auguie
Do you want abind? http://cran.r-project.org/web/packages/abind/index.html baptiste On 15 Apr 2009, at 19:33, Cable, Samuel B Civ USAF AFMC AFRL/RVBXI wrote: I have a multidimensional array a, for example, a , , 1 [,1] [,2] [1,]13 [2,]24 , , 2 [,1] [,2] [1,]

Re: [R] segment between points on different plots

2009-04-16 Thread baptiste auguie
Hi, You should give a minimal reproducible example so that we know more precisely what you want to do (what's a multigraph?). Perhaps you can get inspiration from Paul Murrell's R graphics book, in particular Figure 5.22,

Re: [R] segment between points on different plots

2009-04-16 Thread baptiste auguie
a large graph and plotting small portions of it below.I'm drawing lines from the large graph to the smaller ones to show which part of the large graph it is. On Thu, Apr 16, 2009 at 4:34 PM, baptiste auguie ba...@exeter.ac.uk wrote: Hi, You should give a minimal reproducible example

Re: [R] Howto build combinations of colums of a data frame

2009-04-16 Thread baptiste auguie
Perhaps, apply(combn(letters[1:4],2), 2, paste,collapse=) Hope this helps, baptiste On 16 Apr 2009, at 17:33, Juergen Rose wrote: Am Donnerstag, den 16.04.2009, 10:59 -0400 schrieb David Winsemius: Thanks David, is there also a shorter way to get the columns names of the new data frames?

Re: [R] Digitizing the Plot

2009-04-16 Thread baptiste auguie
The grImport package seems to provide such possibility for vector graphics, http://www.stat.auckland.ac.nz/~paul/Talks/gddg.pdf imageJ is another open-source option. baptiste On 16 Apr 2009, at 16:44, Shubha Vishwanath Karanth wrote: Hi R, Wanted to check if there are any packages

Re: [R] Sweave: Howto write real TeX formula in plot

2009-04-19 Thread baptiste auguie
Perhaps try the pgfSweave package on r-forge? http://r-forge.r-project.org/projects/pgfsweave/ HTH, baptiste On 19 Apr 2009, at 22:15, Jonas Stein wrote: Hi, i use Sweave to put plots in my .tex Documents. (pdflatex) Is there a nice solution for this: a) get a real LaTeX formula in the

Re: [R] The assign(paste(...,i),...) idiom

2009-04-20 Thread baptiste auguie
I vaguely recall thinking with such convoluted constructs when switching from Matlab to R. The lack of generic data structures such as lists makes you define variable names that you can identify and manipulate. There are structures in Matlab, but I think they are much less used than lists

Re: [R] plotting with R

2009-04-22 Thread baptiste auguie
if it hasn't been suggested already: ggplot2 also has a book and a website: http://had.co.nz/ggplot2/ I would recommend any newcomer to have a look as it provides a clear, consistent and elegant syntax to produce very nice plots. baptiste On 22 Apr 2009, at 03:14, Erik Iverson wrote: In

Re: [R] how to split and handle a big R program into multiple files

2009-04-23 Thread baptiste auguie
If most of the functions are quite stable (you don't change them too often), you could also consider creating a R package with package.skeleton. baptiste On 23 Apr 2009, at 10:39, jgar...@ija.csic.es wrote: source() and the use of functions ... Javier --- I am working on a program

Re: [R] R: how to split and handle a big R program into multiple files

2009-04-23 Thread baptiste auguie
It is an R command (package utils), see ?package.skeleton baptiste On 23 Apr 2009, at 10:51, mau...@alice.it wrote: Is that an R command ? I browswd for the on-line hlp about such a command but could not find it. Thank you. maura -Messaggio originale- Da: baptiste auguie

<    1   2   3   4   5   6   7   8   >