Re: [R] two questions for R beginners

2010-03-01 Thread hadley wickham
> Suppose X is a dataframe or a matrix.  What would you expect to get from > X[1]?  What about as.vector(X), or as.numeric(X)? > > The point is that a dataframe is a list, and a matrix isn't.  If users don't > understand that, then they'll be confused somewhere.  Making matrices more > list-like in

Re: [R] Why can't "apply" be used with "as.factor" on a data.frame ?

2010-03-07 Thread hadley wickham
The basic reason because apply works with matrices - it first turns the input into a matrix, processes each column and then returns a matrix. See colwise in the plyr package for a function that works column wise on a data frame, returning a data frame. Hadley On Sun, Mar 7, 2010 at 11:07 AM, Tal

Re: [R] vectorizing ANOVA over a vectorized linear model

2010-03-07 Thread hadley wickham
Hi Mark, If efficiency is a concern you might want to read "Computing Thousands of Test Statistics Simultaneously in R" by Holger Schwender and Tina Müller, http://stat-computing.org/newsletter/issues/scgn-18-1.pdf. If you just want to do it, see the examples in http://had.co.nz/plyr/plyr-intro-0

Re: [R] vectorizing ANOVA over a vectorized linear model

2010-03-07 Thread hadley wickham
> 15032 Hunter Court, Westfield, IN  46074 > > (317) 490-5129 Work, & Mobile & VoiceMail > (317) 399-1219 Skype No Voicemail please > > > On Sun, Mar 7, 2010 at 2:08 PM, hadley wickham wrote: >> >> Hi Mark, >> >> If efficiency is a concern you m

Re: [R] ggplot2 rose diagram

2010-03-10 Thread hadley wickham
For Q2 you can use opts(legend.position = c(0.9, 0.9)). For Q3, you can also use scale_y_sqrt(). Hadley On Wed, Mar 10, 2010 at 2:05 PM, Tim Howard wrote: > To answer two of my own questions to get them into the archives (I am slowly > getting the hang of ggplot): > > Q1.  use "opts(axis.text.

Re: [R] ggplot2: "varwidth"-equivalent for geom_boxplot?

2010-03-10 Thread hadley wickham
What is varwidth? Hadley On Wed, Mar 10, 2010 at 1:55 PM, Johannes Graumann wrote: > Hi, > > Is there such a thing? If no: is it easily simulated? > > thanks, Joh > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help

Re: [R] ggplot2 rose diagram

2010-03-10 Thread hadley wickham
> By Q2 I was trying to refer to the Y-axis labels. For the polar plot, the > Y-axis labels reside left of the panel. I was looking for a way to get the > Y-axis labels to radiate out from the center so it would be clear which line > each label refers to. I still can't find any reference to movi

Re: [R] Help with aggregate and cor

2010-03-10 Thread hadley wickham
> Run that function hourly with plyr > > output.hourly <- dlply(df.i1,"tshour",cor.dat) Why not output.hourly <- ddply(df.i1,"tshour",cor.dat) ? Generally you want to work with data frames in R, if at all possible. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of St

Re: [R] ggplot2: "varwidth"-equivalent for geom_boxplot?

2010-03-11 Thread hadley wickham
oportional to the > square-roots of the number of observations in the groups." > > I find this option often very useful. > > Thanks for any insight into how to achieve this with geom_boxplot. > > Joh > > On Wednesday 10 March 2010 16:12:49 hadley wickham wrote: >

[R] [R-pkgs] ggplot2: version 0.8.7

2010-03-13 Thread Hadley Wickham
ggplot2 ggplot2 is a plotting system for R, based on the grammar of graphics, which tries to take the good parts of base and lattice graphics and avoid bad parts. It takes care of many of the fiddly details that make plotting a hassle (l

Re: [R] likelihood ratio test between glmer and glm

2010-03-14 Thread hadley wickham
> Based on a discussion found on the R mailing list but dating back to 2008, I > have compared the log-likelihoods of the glm model and of the glmer model as > follows: > > lrt <- function (obj1, obj2){ > L0 <- logLik(obj1) > L1 <- logLik(obj2) > L01 <- as.vector(- 2 * (L0 - L1)) > df <- attr(L1,

Re: [R] Retrieving latitude and longitude via Google Maps API

2010-03-16 Thread hadley wickham
>>> Does anyone have any experience retrieving latitutde and longitude for >>> an address from the Google Maps API? > > This thread from r-sig-geo may be of interest: > https://stat.ethz.ch/pipermail/r-sig-geo/2010-March/thread.html#7788 In particularly, note that what you are doing is against the

[R] Encrypt/decrypt in R

2010-03-19 Thread Hadley Wickham
Hi all, Does any one know of any encryption/decryption algorithms in R? I'm not looking for anything robust - I want some way of printing output to the screen that the user can't read immediately, but can decrypt a little later. The main thing I don't want to the user to see is a number, so (e.g

Re: [R] Encrypt/decrypt in R

2010-03-19 Thread Hadley Wickham
On Fri, Mar 19, 2010 at 12:35 PM, Barry Rowlingson wrote: > On Fri, Mar 19, 2010 at 5:10 PM, Barry Rowlingson > wrote: >> On Fri, Mar 19, 2010 at 5:00 PM, Hadley Wickham wrote: >>> Hi all, >>> >>> Does any one know of any encryption/decryption algorithms

Re: [R] Using by() and stacking back sub-data frames to one data frame

2009-06-25 Thread hadley wickham
Have a look at ddply from the plyr package, http://had.co.nz/plyr. It's made for exactly this type of operation. Hadley On Wed, Jun 24, 2009 at 10:34 PM, Stephan Lindner wrote: > Dear all, > > > I have a code where I subset a data frame to match entries within > levels of an factor (actually, the

Re: [R] a plot of stacked boxes

2009-06-26 Thread hadley wickham
On Fri, Jun 26, 2009 at 10:27 PM, Osman Al-Radi wrote: > Dear Richard and David, > > Thanks for this reference. I looked into vcd and mosaic plot, it is a nice > plot for investigating associations between two or more variables. However, > I just need to plot the frequency of a single variable as t

Re: [R] simple loop

2009-06-28 Thread hadley wickham
> Also consider ddply in the plyr package (although that's an over kill if > your only having two loops) Maybe, but it sure is much simpler: library(plyr) ddply(data, c("industry","year"), summarise, avg = mean(X1)) Hadley -- http://had.co.nz/ __ R-

Re: [R] ggplot2 x axis question

2009-06-28 Thread hadley wickham
Hi Chris, Try this: qplot(reorder(model, delta), delta, data = growthm.bic) Hadley On Sun, Jun 28, 2009 at 9:53 AM, Christopher Desjardins wrote: > Hi, > I have 45 models that I have named: 1, 2, 3, ... , 45 and I am trying to > plot them in order of ascending BIC values. I am however unclear a

Re: [R] ggplot2 x axis question

2009-06-29 Thread hadley wickham
ackage. That code is giving me > the following error: > >> qplot(reorder(model,delta),delta,data=growthm.bic) > Error in UseMethod("reorder") : no applicable method for "reorder" > > Cheers, > Chris > > On 6/28/09 8:21 PM, hadley wickham wrote: > >

Re: [R] How do I change which R Graphics Device is active?

2009-06-30 Thread hadley wickham
On Tue, Jun 30, 2009 at 2:12 PM, Barry Rowlingson wrote: > On Tue, Jun 30, 2009 at 8:05 PM, Mark Knecht wrote: > >> You could wrap it in a function of your own making, right? >> >> AddNewDev = function() {dev.new();AddNewDev=dev.cur()} >> >> histPlot=AddNewDev() >> >> Seems to work. > >  You leaRn

Re: [R] Select values at random by id value

2009-07-01 Thread hadley wickham
On Wed, Jul 1, 2009 at 2:10 PM, Sunil Suchindran wrote: > #Highlight the text below (without the header) > # read the data in from clipboard > > df <- do.call(data.frame, scan("clipboard", what=list(id=0, > date="",loctype=0 ,haptype=0))) > > # split the data by date, sample 1 observation from each

Re: [R] Select values at random by id value

2009-07-02 Thread hadley wickham
On Thu, Jul 2, 2009 at 8:15 AM, James Martin wrote: > Hadley, Sunil, and list, > > This is not quite doing what I wanted it to do (as far as I can tell). I > perhaps did not explain it thoroughly.  It seems to be sampling one value > for each day leaving ~200 observations. I need for it randomly ch

Re: [R] Learning S3

2009-07-02 Thread Hadley Wickham
On Thu, Jun 18, 2009 at 12:08 PM, Dirk Eddelbuettel wrote: > > On 18 June 2009 at 09:36, Bert Gunter wrote: > | -- or Chapter 4 in S PROGRAMMING? (you'll need to determine if it's "reader > | friendly") > > +1 > > It helped me a lot too back in the day.  But I am wondering if there are good > curre

Re: [R] Passing expression as argument to do.call

2009-07-02 Thread hadley wickham
On Thu, Jul 2, 2009 at 3:34 PM, Sebastien Bihorel wrote: > Dear R-users, > > I would like to know how expressions could be passed as arguments to do.call > functions. As illustrated in the short example below, concatenating lists > objects and an expression creates an expression object, which is no

Re: [R] help with dealing with integer(0) returns from grep used within a conditional loop

2009-07-04 Thread hadley wickham
On Sat, Jul 4, 2009 at 7:56 PM, Mark Kimpel wrote: > I am using grep to locate colnames to automate a report build and have > run into a problem when a colname is not found. The use of integer(0) > in a conditional statement seems to be a no no as it has length 0. > Below is a self-contained trivia

Re: [R] What command lists everything in a package?

2009-07-05 Thread hadley wickham
> 2) Related to the above, how do I tell what packages are currently > loaded at any given time so that I don't waste time loading things > that are already loaded? search() tells me what's available, but > what's loaded? The best I can find so far goes like this: Loading something a second time t

Re: [R] Skeleton Package to Flesh Out?

2009-07-05 Thread hadley wickham
Also make sure to check roxygen (from roxygen.org) - it makes package documentation much much easier. Ironically, the documentation for roxygen currently leaves something to be desired but I think Peter and Manuel are working on it. Hadley On Sat, Jul 4, 2009 at 3:59 PM, Jason Rupert wrote: > >

Re: [R] OK - I got the data - now what? :-)

2009-07-05 Thread hadley wickham
>   I think the root cause of a number of my coding problems in R right > now is my lack of skills in reading and grabbing portions of the data > out of arrays. I'm new at this. (And not a programmer) I need to find > some good examples to read and test on that subject. If I could locate > which co

Re: [R] ggplot2: Boxplot with given box size

2009-07-05 Thread hadley wickham
Hi Malcolm, You need to tell geom_boxplot not to use stat_boxplot: geom_boxplot(aes(lower=y_q1, upper=y_q3, middle=y_med, ymin=y_min, ymax=y_max), stat = "identity") Hadley On Mon, Jul 6, 2009 at 6:55 AM, Malcolm Ryan wrote: > Is there anyway in ggplot2 to set the aesthetics for a geom_boxplot >

Re: [R] NA values trimming

2009-07-06 Thread hadley wickham
On Mon, Jul 6, 2009 at 12:12 AM, nyk wrote: > > Thanks for your reply! This is what I was looking for! > I'm using > nas1 <- apply(data_matrix,1,function(x)sum(is.na(x))/nrow(data_matrix)) > nas2 <- apply(data_matrix,2,function(x)sum(is.na(x))/ncol(data_matrix)) You can simplify this a little: pe

Re: [R] ReShape chicks example - line plots

2009-07-06 Thread hadley wickham
On Mon, Jul 6, 2009 at 8:22 PM, Mark Knecht wrote: > Hi, >   In the examples from the ReShape package there is a simple example > of using melt followed by cast that produces a smallish amount of > output about the chicks database. Here's the code: > > library(reshape) > > names(ChickWeight) <- tol

Re: [R] ggplot2: geom_errorbarh()

2009-07-12 Thread hadley wickham
Hi Benoit, What do you expect width to do? You are already setting the left and right extents with xmin and xmax. Hadley On Thu, Jul 9, 2009 at 10:37 AM, Benoit Boulinguiez wrote: > Hi all, > > quick question: is the optional command "width" effective in the > geom_errorbarh() layer of ggplot?

Re: [R] curve from a formula with ggplot2

2009-07-12 Thread hadley wickham
from a formula. > I'm looking for the equivalent of curve() in ggplot2, Hadley Wickham > mentions geom_curve, but as far as I've seen in the help it doesn't exist. > > My need is to plot a regular scatter plot of experimental data (easy to do > actually) and then add the

Re: [R] Strange error in qplot

2009-07-12 Thread hadley wickham
Hi megh, Unfortunately there's a known bug which prevents you from setting the y axis title in this way. Instead you can do : qplot(...) + scale_y_continuous("") I think I've figured out a work around and it will be fixed in a future release. Hadley On Mon, Jul 13, 2009 at 2:15 AM, megh wrote

Re: [R] strata -- really slow performance

2009-07-12 Thread hadley wickham
> In this simple example, it took less than half a second to generate the > result. That is on a 2.93 Ghz MacBook Pro. > > > So, for your data, the code would look something like this: > > > system.time(DF.new <- do.call(rbind, >                              lapply(split(patch_summary, > patch_summ

Re: [R] how to keep row name if there is only one row selected from a data frame

2009-07-12 Thread hadley wickham
On Mon, Jul 13, 2009 at 5:55 AM, Weiwei Shi wrote: > Hi, there: > > Assume I have a dataframe with rownames like A with rownames like a to e, > >> A >  [,1] [,2] > a    1    6 > b    2    7 > c    3    8 > d    4    9 > e    5   10 > > when I use A[1,], I lost the rowname for it, like below. How co

Re: [R] ggplot2: geom_errorbarh()

2009-07-15 Thread hadley wickham
t Boulinguiez > > > -Message d'origine- > De : hadley wickham [mailto:h.wick...@gmail.com] > Envoyé : dimanche 12 juillet 2009 11:04 > À : Benoit Boulinguiez > Cc : r-help@r-project.org > Objet : Re: [R] ggplot2: geom_errorbarh() > > Hi Benoit, > > Wh

Re: [R] GGPLOT Clipping Regions

2009-07-16 Thread hadley wickham
Could you please give a reproducible example? Thanks, Hadley On Thu, Jul 16, 2009 at 5:41 PM, Alex Brown wrote: > Hi there, > >        I'm trying to find out the command to stop clipping to plot region in > ggplot. > >        I have a bar chart (axis flipped) with labels on the bars, but the > lab

Re: [R] ggplot2: geom_errorbarh()

2009-07-17 Thread hadley wickham
ely... > > > Regards/Cordialement > > > Benoit Boulinguiez > > > -Message d'origine- > De : hadley wickham [mailto:h.wick...@gmail.com] > Envoyé : mercredi 15 juillet 2009 14:52 > À : Benoit Boulinguiez > Cc : r-help@r-project.org > Objet : Re: [R] g

Re: [R] GGPLOT Clipping Regions

2009-07-20 Thread hadley wickham
On Fri, Jul 17, 2009 at 3:39 AM, Alex Brown wrote: > > Sure thing, an example.: > > ggplot > (data.frame(name=letters[1:3],value=c(1,4,9),type=c("fun","fun","not > fun")),aes(x=name,y=value,fill=type,label=paste("value is ",value))) + > geom_bar() + coord_flip() + geom_text(hjust=0) > > I'd like th

Re: [R] Simulate residuals with different properties for a linear model (regression)

2009-07-20 Thread hadley wickham
> for educational purposes I wonder if it is possible to simulate > different data sets (or specifically residuals) for a linear regression. > I would like to show my students residuals with different means, > variances and distributions (normal, but also not normal) in the plots > created with the

Re: [R] animated grid graphics

2009-07-21 Thread hadley wickham
> Ups, I just realized that we have the possibility of using > grid.remove(..., redraw = FALSE) which is more or less what I was looking for. > > But I'm still wondering if its possible to remove a viewport from > a viewport tree: I've talked with Paul about this (for the general case of modifying

Re: [R] animated grid graphics

2009-07-21 Thread hadley wickham
> Drawing grid graphics always takes long, I would write the images to png's > and make the animation. If you use Linux I can suggest some nice tools to do > this. This movie is also much more compatible with all kinds of machines. It > might be that you can get your grid animation working on your

Re: [R] How to replace NAs in a vector of factors?

2009-07-21 Thread hadley wickham
On Tue, Jul 21, 2009 at 7:39 PM, Gene Leynes wrote: > # Just when I thought I had the basic stuff mastered > # This has been quite perplexing, thanks for any help > > > ## Here's the example: > > db1=data.frame( >    olditems=c('soup','','','','nuts'), >    prices=c(4.45, 3.25, 4.42, 2.25, 3.98

Re: [R] strange dlply behavior

2009-07-21 Thread hadley wickham
Hi Damien, This is because of a small bug. You can work around it by explicitly using the force function - dlply(d, "V1", force). The default will be fixed in the next version. Regards, Hadley On Tue, Jul 21, 2009 at 11:18 AM, Damien Moore wrote: > I'm running R 2.9.1 on winXP, using the libr

Re: [R] All possible linear models given multiple explaining variables

2009-07-22 Thread hadley wickham
Have a look at the meifly package, which also includes tools for visualising the resulting models. Hadley On Wed, Jul 22, 2009 at 7:28 AM, Thomas A. Groen wrote: > Hi, > > I would like to have a script/function (or write one) that can calculate the > linear models for all possible combinations of

Re: [R] roclet

2009-07-24 Thread hadley wickham
On Fri, Jul 24, 2009 at 9:08 AM, Steve Lianoglou wrote: > Hi, > > On Jul 24, 2009, at 8:49 AM, > wrote: > >> Hi, >>  can anyone tell me what a "roclet" is exactly? >>  Is this terminology specific to R, or is it used in other languages >> aswell? > > Never heard of it before and google isn't retu

Re: [R] tweak a bit the legend wiht ggplot2

2009-07-31 Thread hadley wickham
Hi Benoit, Unfortunately there's currently no way to do that - the legend automatically corresponds to the geom in the plot. Hadley On Thu, Jul 23, 2009 at 11:30 AM, Benoit Boulinguiez wrote: > Hi all, > > I've this ggplot2 graph > (http://www.4shared.com/file/120101043/f3e9350/isotherm.html). >

Re: [R] Help with reshaping data.frame

2009-08-03 Thread hadley wickham
On Mon, Aug 3, 2009 at 5:23 PM, wrote: > I'm having trouble reshaping a data.frame from long to wide. > (I think that's the right terminology; feel free to educate me.) > I've looked at the reshape function and package and plyr package, > but I can't quite figure out how to do this after a dozen v

[R] ggplot2 course: 19 October, Austin TX / the web

2009-08-04 Thread Hadley Wickham
Hi all, On October 19, I'll be offering a one data ggplot2 course in conjunction with the ISMI Manufacturing Week. The course is open to all and you can attend in person (Austin TX) or over the web. More information available from http://lookingatdata.com/ismi-2009/ Regards, Hadley -- http://

Re: [R] flexible alternative to subsetting dataframe inside nested loops

2010-03-24 Thread hadley wickham
On Wed, Mar 24, 2010 at 8:52 AM, mgierdal wrote: > > I have a dataFrame variable: > >      L1  L2 L3 ... v1 v2 ... >  1 >  2 >  3 >  4 >  ... > > I want to process subsets of it as defined by combinations of L1-L2-L3. I do > it successfully using nested loops: > > for (i in valuesOfL1 { >  for (j

Re: [R] GGPLOT2: Reverse order of legend to match order of x-axis

2010-03-24 Thread hadley wickham
See here: http://learnr.wordpress.com/2010/03/23/ggplot2-changing-the-default-order-of-legend-labels-and-stacking-of-data/ Hadley On Wed, Mar 24, 2010 at 2:40 PM, Ryan Garner wrote: > > How do I reverse the order of the legend in a bar plot to match order of the > x-axis? In other words, I want

Re: [R] Competing with SPSS and SAS: improving code that loops through rows (data manipulation)

2010-03-27 Thread hadley wickham
> # Set up the ratio variables > system.time({ > temp <- cbind(data, do.call(cbind, lapply(names(data)[3:4], function(.x) >        { >                unlist(by(data, data$group, function(.y) .y[,.x] / > max(.y[,.x]))) >        }))) > colnames(temp)[5:6] <- paste(colnames(data)[3:4], 'ind.to.max',

Re: [R] Competing with SPSS and SAS: improving code that loops throughrows (data manipulation)

2010-03-27 Thread hadley wickham
>  exp1^(a[case] * l * 10) > > would be better written out of the loop as > >  b <- exp1^(a * l * 10) And even better as b <- exp(a * l * 10) Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/

Re: [R] regular expression help to extract specific strings from text

2010-03-31 Thread hadley wickham
On Wed, Mar 31, 2010 at 8:20 AM, Tony B wrote: > Dear all, > > Lets say I have the following: > >> x <- c("Eve: Going to try something new today...", "Adam: Hey @Eve, how are >> you finding R? #rstats", "Eve: @Adam, It's awesome, so much better at >> statistics that #Excel ever was! @Cain & @Abl

Re: [R] Sharing levels across multiple factor vectors

2010-04-01 Thread hadley wickham
On Thu, Apr 1, 2010 at 3:05 AM, Peter Dalgaard wrote: > Jeff Brown wrote: >> Sorry for spamming.  I swear I had worked on that problem a long time before >> posting. >> >> But I just figured it out: I have to change the values, which are >> represented as integers, not strings.  So the following c

Re: [R] sample size > 20K? Was: fitness of regression tree: how to measure???

2010-04-01 Thread hadley wickham
> Incidentally, there is nothing new or radical in this; indeed, John Tukey, > Leo Breiman, George Box, and others wrote eloquently about this decades ago. > And Breiman's random forest modeling procedure explicitly abandoned efforts > to build simply interpretable models (from which one might infe

Re: [R] SAS and R on multiple operating systems

2010-04-06 Thread hadley wickham
>  Also I have seen 5,000 page listings in SAS. Is this a pro or a con? Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.c

Re: [R] ggplot2, density barplot and geom_point layer

2010-04-07 Thread hadley wickham
Because of the way you've constructed the plot with qplot, you need to use: myPlot + geom_point( data=medians, aes(x=med,shape=cut, y=0), size=2.5, ) Hadley On Wed, Apr 7, 2010 at 5:11 AM, Johannes Graumann wrote: > Hi, > > Please consider the example below. How can I manage to overlay the p

[R] Using read.table to read file created with read.table and qmethod = "escape"

2010-04-07 Thread Hadley Wickham
df <- data.frame(a = "a\"b") write.table(df, "test.csv", sep = ",", row = F) Is there any to load test.csv into R correctly? I've tried the following: > read.table("test.csv", sep = ",") [1] V1 <0 rows> (or 0-length row.names) Warning message: In read.table("test.csv", sep = ",") : incomplete

[R] Strange csv parsing problem

2010-04-07 Thread Hadley Wickham
> url <- "http://dl.dropbox.com/u/41902/22240.csv"; > > read.csv(url)[, 1] [1] "oppose" NA"oppose" "support" > read.csv(url, header = F)[, 1] [1] "url" [2] "http://maplight.org/us-congress/bill/109-hr-5825/387248"; [3] "http://maplight.org/us-congress/bill/110-hr-3546/378743"; [4] "http:/

Re: [R] Using read.table to read file created with read.table and qmethod = "escape"

2010-04-08 Thread Hadley Wickham
> df <- data.frame(a = "a\"b", v = 4, z = "this is Z") > write.csv(df, "test.csv", row.names = FALSE, quote = FALSE) > read.csv("test.csv", quote = "") Unfortunately my real example is more like: df <- data.frame(a = "a\"b", v = 4, z = "this is: A, B, C") so quote = F won't work. Can write.tabl

Re: [R] Using read.table to read file created with read.table and qmethod = "escape"

2010-04-08 Thread Hadley Wickham
>> Can write.table and read.table really be so asymmetric? > > write() is a wrapper for cat() and read() is a wrapper for scan() so the > question should really be can cat() and scan() be so asymmetric. Looking at > their help pages, I would say that at least some degree of asymmetry is > plausible

Re: [R] Using read.table to read file created with read.table and qmethod = "escape"

2010-04-08 Thread Hadley Wickham
On Thu, Apr 8, 2010 at 8:20 AM, jim holtman wrote: > You were using read.csv and not read.table.  The following seems to work > with using a separator that will probably not appear in the text: > >> df <- data.frame(a = "a\"b", v = 4, z = "this is: A, B, C") >> write.table(df, "test.csv", row.name

Re: [R] Strange csv parsing problem

2010-04-08 Thread Hadley Wickham
> Remove the comma and count.fields gives 11 for all rows. > From your other post(s) on escaped quotes, I assume that > this won't solve your problem with the existing files. (: Right - but assuming I'm not crazy, that should cause an error in read.csv, right? It shouldn't just parse the file reg

Re: [R] Combining ggplot2 objects and/or extracting layers

2010-04-09 Thread hadley wickham
> Other then rebuilding the plots, is there any way either (1) to combine > existing ggplot2 plots or (2) to extract a layer from an existing plot > so that it can be added to another? Not really, although you can always pull apart the plot components. Can you give an example of what you are tryin

Re: [R] error bars on barplot

2010-04-09 Thread hadley wickham
> bar.err (agricolae) > plotCI (gplots) > xYplot (Hmisc) > error.bars (psych) > dispersion (plotrix) > plotCI (plotrix) > Not to mention: http://biostat.mc.vanderbilt.edu/wiki/Main/DynamitePlots Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice Univers

Re: [R] sum specific rows in a data frame

2010-04-15 Thread hadley wickham
On Thu, Apr 15, 2010 at 1:16 AM, Chuck wrote: > Depending on the size of the dataframe and the operations you are > trying to perform, aggregate or ddply may be better.  In the function > below, df has the same structure as your dataframe. Current version of plyr: agg ddply X100.00

Re: [R] sum specific rows in a data frame

2010-04-15 Thread hadley wickham
addition of key columns that don't affect the > number of groups.  For example, grouping by Year and Month, if I add > MonthBegin, a POSIXct column from which the Year and Month columns were > derived, I run out of memory. > > hadley wickham wrote: > >>On Th

Re: [R] sum specific rows in a data frame

2010-04-15 Thread hadley wickham
hat > version? > > On Thu, Apr 15, 2010 at 9:09 AM, hadley wickham wrote: >> >> On Thu, Apr 15, 2010 at 1:16 AM, Chuck wrote: >> > Depending on the size of the dataframe and the operations you are >> > trying to perform, aggregate or ddply may be better.  I

Re: [R] problem with FUN in Hmisc::summarize

2010-04-16 Thread hadley wickham
> corr.V2.V3 = function(x) { >  out = cor(x$V2, x$V3) >  names(out) = "CORR" >  return(out) > } A litte more concisely: corr.V2.V3 = function(x) { c(CORR = cor(x$V2, x$V3)) } -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __

Re: [R] Formatting data, adding column names, use reshape, a newbie question

2010-04-19 Thread hadley wickham
On Mon, Apr 19, 2010 at 5:13 AM, Paul Rigor (ucla) wrote: > Hi all, > I'm an R novice. > > I have data that's already formatted as "molten" that reshape should be able > to work with. For example, the following was read in with > read.csv(filename,sep=" ", header=FALSE) > >      V1               V

Re: [R] ggplot and scale_x_date

2010-04-21 Thread hadley wickham
Hi Liam, Unfortunately this currently isn't supported. It's on my to do list: http://github.com/hadley/ggplot2/issues/issue/94 Hadley On Tue, Apr 20, 2010 at 7:59 PM, Liam Blanckenberg wrote: > Hi all, > > I have a question about setting arbitrary breaks/labels when using GGPLOT > and date/tim

Re: [R] ggplot2: how to specify x-axis limits to geom_abline() ?

2010-04-23 Thread hadley wickham
Use geom_segment and calculate the end points yourself. Hadley On Fri, Apr 23, 2010 at 8:38 AM, arnaud chozo wrote: > Hi all, > > I'd want to plot a segment from a line specified by slope and intercept. > I want to plot this line between two limits, x1 and x2, without imposing > these limits to t

Re: [R] Intersection for two curves

2010-04-24 Thread hadley wickham
>> rm(list=ls()) > > PLEASE, DON'T DO THAT. Or rather you can do it in your workspace but > don't post it. It's not fair to a person who may not read your code line by > line before pasting it into their workspace and having it wiped out. Do you > expect us to completely clear out our workspace

Re: [R] Intersection for two curves

2010-04-24 Thread hadley wickham
>> If clearing out your workspace destroys *any* work, then something is >> seriously wrong with your workflow. >> > > Yes, of course.  Lets all post viruses to run on each others' > machines.  That will teach those users who don't run antivirus and > backup software between each posting to r-help.

Re: [R] Intersection for two curves

2010-04-24 Thread hadley wickham
> Perhaps, true in some respects. I am still chiseling out work using > primitive editing tools. But it still takes several minutes to load the > objects I am working on into memory and then several minutes each to build > new models. The models still reside in memory, since I do not know any > met

Re: [R] Intersection for two curves

2010-04-24 Thread hadley wickham
On Sat, Apr 24, 2010 at 12:54 PM, Peter Ehlers wrote: > Well, this has seriously gotten off the original topic. > > While Hadley makes some sense, it is nevertheless > sometimes the case (surely so for David, I would surmise) > that one is putting together a response to an R-help > query when a ne

Re: [R] Intersection for two curves

2010-04-24 Thread hadley wickham
> Many people seem to be reluctant to define functions, > even thought I think it is a pretty small step from > writing scripts to writing functions. I'm not so sure - I find most students struggle to grasp that next level of abstraction. Generalising from a specific task to a general function is

Re: [R] How to plot a table of numbers as an image using ggplot2?

2010-04-27 Thread hadley wickham
Yes. Hadley PS. If you provide a small reproducible example you are bound to get more useful answers ;) On Tue, Apr 27, 2010 at 8:45 AM, arnaud chozo wrote: > Hi all, > > I'd want to plot a table of numbers such that the values are represented by > gray level. Is there an easy way to do that u

Re: [R] ggplot2 - help with intervals in geom plot

2010-04-27 Thread hadley wickham
> The problem is that I want HCount and HProbCount to use custom > gradients. i.e. a colour for 0-10, next shade for 10-30, next for 30-70 > etc. Use cut to create factor with those levels, and then scale_fill_manual to match values to colours. > Due to some magic done on the data, one uses inter

Re: [R] Combining ggplot2 objects and/or extracting layers

2010-04-28 Thread hadley wickham
t with widths equal to the durations > of the recessions. Once I create a free-standing plot, I'd like to be able > to use it in various other contexts, including adding it to other existing > plots. The alternative is to reconstruct the plot as a layer and add it to > the other plots, but t

Re: [R] Problem with xtabs(), exclude=NULL, and counting NA's

2009-09-24 Thread hadley wickham
> wtf <- factor(x, levels(c(levels(wtf), NA), exclude=NULL) > xtabs (~ wtf, exclude=NULL, na.action=na.pass) Also see addNA. Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read

Re: [R] packGrob and dynamic resizing

2009-09-25 Thread hadley wickham
On Fri, Sep 25, 2009 at 7:55 AM, baptiste auguie wrote: > Thank you Paul, I was convinced I tried this option but I obviously didn't! > > In ?packGrob, the user is warned that packing grobs can be slow. In > order to quantify this, I made the following comparison of 3 > functions, > > - table1 use

Re: [R] How to assess object names within a function in lapply or l_ply?

2009-09-28 Thread hadley wickham
> or with l_ply (plyr package) > l_ply(data.frame(a=1:3, b=2:4), function(x) print(deparse(substitute(x The best way to do this is to supply both the object you want to iterate over, and its names. Unfortunately it's slightly difficult to create a data structure of the correct form to do thi

Re: [R] How to assess object names within a function in lapply or l_ply?

2009-09-28 Thread hadley wickham
> many thanks for your answer and for the enormous work you put into plyr, a > really powerful package. > For now, I will solve my problem with a variable label attribute, I usually > attach to columns in data frames. I asked the list, because I thought, I am > overlooking something trivial, since

Re: [R] R and REST API's

2009-09-28 Thread hadley wickham
On Mon, Sep 28, 2009 at 9:01 AM, Gary Lewis wrote: > Hi - Many organizations now make their data available as XML via a > REST web service architecture. Is there any R package or facility to > access this type of data directly (eg, to make the HTTP GET request > and have the downloaded data put in

Re: [R] 3D to 2D projection

2009-09-28 Thread hadley wickham
> Have you used persp or trans3d before? Here is a little piece of data that I > am want to convert to 2d. I can plot (x,z) or (z,y). I know there is a better > way to convert it to 2d. I did it long time back in my 3d geometry class. http://en.wikipedia.org/wiki/3D_projection ? Hadley -- htt

Re: [R] sort dates within a factor

2009-09-29 Thread hadley wickham
On Tue, Sep 29, 2009 at 6:58 AM, wrote: > Apologies for the misunderstanding. I can come up with a solution that might > suit your needs: > > library(plyr) > out <- ddply(test, .(nr), function(x) data.frame(date=x$date, > index=rank(-as.integer(x$date > out[is.na(out$nr) | is.na(out$date),

Re: [R] Condition to factor (easy to remember)

2009-09-30 Thread hadley wickham
On Wed, Sep 30, 2009 at 2:32 PM, Ista Zahn wrote: > An extremely verbose, but (in my view) easy to understand approach is: > >> data.f <- data; data.f[which(data <= 10)] <- levs[1]; data.f[which(data > >> 10)] <- levs[2]; data.f <- factor(data.f) > All those which()s are unnecessary. And if you

Re: [R] split-apply question

2009-10-02 Thread hadley wickham
On Fri, Oct 2, 2009 at 4:24 AM, jim holtman wrote: > try this: > >> x <- read.table(textConnection("x1  x2  x3 > + A   1    1.5 > + B   2    0.9 > + B   3    2.7 > + C   7    1.8 > + D   7    1.3"), header=TRUE) >> closeAllConnections() >> do.call(rbind, lapply(split(seq(nrow(x)), x$x1), function(

Re: [R] Stranger Behavior -maybe not

2009-10-03 Thread hadley wickham
> The point Duncan was making was > > "What other value would you expect it to have after incrementing from 1 to > 200 and stopping"? Well, depending on the scoping rules of the language you are used to, you might expect i at the top-level to remain undefined. Hadley -- http://had.co.nz/ _

Re: [R] ggplot2: proper use of facet_grid inside a function

2009-10-05 Thread hadley wickham
> Whether or not what follows is to be recommended I don't know, but it > seems to work, > > p <- ggplot(diamonds, aes(carat, ..density..)) + >  geom_histogram(binwidth = 0.2) > > x = quote(cut) > facets = facet_grid(as.formula(bquote(.~.(x > p + facets That's what I'd recommend. You can also

Re: [R] ggplot cumsum refined question (?)

2009-10-06 Thread hadley wickham
> It is much easier to do you data preparation before plotting. > > Cummul <- ddply(subset(DF, precipitation!="NA"), "gauge_name", > function(x){ >        x$Cummul <- cumsum(x$precipitation) >        x > }) With a little less typing: Cummul <- ddply(subset(DF, precipitation!="NA"), "gauge_name",

Re: [R] Letter-based representation of pairwise comparisons

2009-10-06 Thread hadley wickham
Please provide a reproducible example. I've had problems with multcompLetters in the past, because I was giving it slightly incorrect input. Hadley On Tue, Oct 6, 2009 at 7:41 AM, goz wrote: > > hello, > > i try to use the multcomp letters, but i have problems with my results : > > here is my p

Re: [R] splitting dataframe, assign to new dataframe, add new rows to new dataframe

2009-10-13 Thread hadley wickham
On Tue, Oct 13, 2009 at 6:57 AM, Ista Zahn wrote: > I'm sure there's a really cool way to do this with plyr, although I > don't know if my particular plyr version is much better. Anyway here > it is: > > cmbine <- read.csv(textConnection('names, mass, classes > apple,0.50,1 > tiger,100.00,2 > penc

Re: [R] "Use R" -- term and logo copyright?

2009-10-13 Thread hadley wickham
>> Can I use (a) the logo and/or (b) the slogan for the KCL R workshops? >> I think it is quite clear from "my" website that this is neither about >> the Springer book series nor about an R user conference. > > No, sorry, the logo/name should be used exclusively for the Springer series > and the R

Re: [R] lapply() reccursively

2009-10-13 Thread hadley wickham
> Neither a1 nor 2:100 are lists, so it would seem that sapply would be more > appropriate. The difference between lapply and sapply is the output, not the input. Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/m

Re: [R] ggplot2 scale_shape question

2009-10-14 Thread hadley wickham
> Is there a way to have some points solid and some points hollow? I have two > classes of points and there are so many points, that it's hard to see just > the difference in shapes. I'd like to have one of the classes be hollow in > addition to being a different shape. Any help would be grand. Yo

Re: [R] Cacheing computationally expensive getter methods for S4 objects

2009-10-14 Thread hadley wickham
Just a note: this technique is called memoisation. Hadley On Wed, Oct 14, 2009 at 3:42 PM, Benilton Carvalho wrote: > Thank you very much, Martin. :) > > b > > On Oct 14, 2009, at 5:23 PM, Martin Morgan wrote: > >> Steve Lianoglou wrote: >>> >>> Very clever, that looks to do the trick! >> >> I th

<    1   2   3   4   5   6   7   8   9   10   >