Re: [R] Display a very low p-value

2009-04-08 Thread hadley wickham
>  pnorm(37:39,lower.tail=FALSE) > [1] 5.725571e-300  0.00e+00  0.00e+00 > >  This is just a limitation of double precision floating-point arithmetic > ... > >  curve(pnorm(x,lower.tail=FALSE),from=30,to=40,log="y") > .Machine$double.xmin But note curve(pnorm(x,lower.tail=FALSE, log=T),fr

Re: [R] Help with postscript (huge file size)

2009-04-12 Thread hadley wickham
> I'm generating some images in R to put into a document that I'm producing > using Latex. This document in Latex is following a predefined model, which > does not accept compilation with pdflatex, so I have to compile with latex > -> dvi -> pdf. Because of that, I have to generate the images in R

Re: [R] Concatenation, was Re: Physical Units in Calculations

2009-04-13 Thread hadley wickham
On Mon, Apr 13, 2009 at 4:15 AM, Peter Dalgaard wrote: > Stavros Macrakis wrote: > >> It would of course be nice if the existing difftime class could be fit >> into this, as it is currently pretty much a second-class citizen.  For >> example, c of two time differences is currently a numeric vector

[R] Extending a vector to length n

2009-04-15 Thread hadley wickham
In general, how can I increase a vector of length m (< n) to length n by padding it with m - n missing values, without losing attributes? The two approaches I've tried, using length<- and adding missings with c, do not work in general: > a <- as.Date("2008-01-01") > c(a, NA) [1] "2008-01-01" NA >

[R] [R-pkgs] [ANN] plyr version 0.1.7

2009-04-15 Thread hadley wickham
plyr is a set of tools for a common set of problems: you need to break down a big data structure into manageable pieces, operate on each piece and then put all the pieces back together. For example, you might want to: * fit the same model to subsets of a data frame * quickly calculate summary

Re: [R] Extending a vector to length n

2009-04-16 Thread hadley wickham
> Levels: a >> > > R. Raubertas > Merck & Co > > >> -Original Message- >> From: r-help-boun...@r-project.org >> [mailto:r-help-boun...@r-project.org] On Behalf Of hadley wickham >> Sent: Wednesday, April 15, 2009 10:55 AM >> To: r-help &g

Re: [R] cast function in package reshape

2009-04-17 Thread hadley wickham
, namef) >      res <- c(res, get(namef)) >    } >    names(res) <- namesf >  } >  return(res) > } > > df <- data.frame(id = 1:50, x = sample(c(NA, 1), 50, T), y = sample(1:2, 50, > T), z = sample(letters[1:2], 50, T)) > >> freq1(df$x) > $freq_1 >

Re: [R] Create histogram from data matrix

2009-04-17 Thread hadley wickham
On Fri, Apr 17, 2009 at 9:59 AM, Paul Warren Simonin wrote: > Hello! >  Thanks for reading this request for assistance. I have a question regarding > creating a histogram-like figure from data that are not currently in the > correct format for the "hist" command. >  Specifically, my data have been

Re: [R] numbers loop in R

2009-04-17 Thread hadley wickham
On Fri, Apr 17, 2009 at 12:19 PM, jim holtman wrote: > try this: > >> matrixx<-function(A){ > +     B=matrix(NaN,nrow=(A+1),ncol=4) > +     k <- 1 > +     for (i in 3:A){ > +         for (j in i:A) { > +             B[k,] <- c(NaN, i-2, i-1, j) > +             k <- k + 1 > +         } > +     } >

Re: [R] ColorRamp different from ColorRampPalette

2009-04-17 Thread hadley wickham
Look at the output of pal.cr((0:40)/40) Hadley On Fri, Apr 17, 2009 at 2:42 PM, Etienne B. Racine wrote: > > I try to use ColorRamp as ColorRampPalette (i.e. with the same gradient), but > it seems there is a nuance that I've missed. > > pal.crp<-colorRampPalette( c("blue", "white", "red"), space

Re: [R] Create histogram from data matrix

2009-04-18 Thread hadley wickham
On Fri, Apr 17, 2009 at 2:07 PM, Paul Warren Simonin wrote: > Thank you all for your advice. >  I have received some good tips, but it was suggested I write back with a > small simulated data set to better illustrate my needs. So, currently my > data frame looks something like: > > ID (date)  Temp

Re: [R] AICs from lmer different with summary and anova

2009-04-19 Thread hadley wickham
> Am I doing something wrong, here? If not, which are the real AIC and logLik > values for the different models? I don't think it's reasonable to expect that the log-likelihood computed by different functions be should comparable. Are the constant terms included or dropped? Hadley -- http://ha

[R] [R-pkgs] [ANN] ggplot2 version 0.8.3

2009-04-20 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] bug when subtracting decimals?

2009-04-21 Thread hadley wickham
> "Have you read the posting guide and the FAQs? If you do not get a reply > within two days, you may want to look at both and think about reformulating > your query. Oh, and while you are at it, look through the archives, a lot of > questions have already been asked and answered before." As I say

Re: [R] conditional grouping of variables: ave or tapply or by or???

2009-04-23 Thread hadley wickham
On Thu, Apr 23, 2009 at 5:11 PM, ozan bakis wrote: > Dear R Users, > I have the following data frame: > > v1 <- c(rep(10,3),rep(11,2)) > v2 <- sample(5:10, 5, replace = T) > v3 <- c(0,1,2,0,2) > df <- data.frame(v1,v2,v3) >> df >  v1 v2 v3 > 1 10  9  0 > 2 10  5  1 > 3 10  6  2 > 4 11  7  0 > 5 11

Re: [R] Generalized 2D list/array/whatever?

2009-04-24 Thread hadley wickham
On Fri, Apr 24, 2009 at 5:50 AM, Duncan Murdoch wrote: > Toby wrote: >> >> I'm trying to figure out how I can get a generalized 2D >> list/array/matrix/whatever >> working.  Seems I can't figure out how to make the variables the right >> type.  I >> always seem to get some sort of error... out of

Re: [R] omit empty cells in crosstab?

2009-04-24 Thread hadley wickham
Hi Steve, The general answer is yes, but the specific will depend on your problem. Could you provide a small reproducible example to illustrate your problem? Hadley On Fri, Apr 24, 2009 at 1:19 PM, sjaffe wrote: > > Perhaps this is a common question but I haven't been able to find the answer.

Re: [R] omit empty cells in crosstab?

2009-04-24 Thread hadley wickham
On Fri, Apr 24, 2009 at 3:12 PM, sjaffe wrote: > > small example: > > a<-c(1.1, 2.1, 9.1) > b<-cut(a,0:10) > c<-data.frame(b,b) > d<-table(c) > dim(d) > ##result: c(10, 10) > > But only 9 of the 100 cells are non-zero. > If there were 10 columns, the table have 10 dimensions each of length 10, so

Re: [R] 3 questions regarding matrix copy/shuffle/compares

2009-04-26 Thread hadley wickham
>> I want to (1) create a deep copy of pop, > > I have already said *I* do not know how to create a "deep copy" in R. Creating a deep copy is easy, because all copies are "deep" copies. You need to try very hard to create a reference in R. Hadley -- http://had.co.nz/ _

Re: [R] 3 questions regarding matrix copy/shuffle/compares

2009-04-26 Thread hadley wickham
he original were changed; the sort of behavior that > might be seen  in a spreadsheet that had a copy "by reference". > > On Apr 26, 2009, at 11:28 AM, hadley wickham wrote: > >>>> I want to (1) create a deep copy of pop, >>> >>> I have already said *I*

Re: [R] eager to learn how to use "sapply", "lapply", ...

2009-04-26 Thread hadley wickham
Have a look at the plyr package and associated documentation - http://had.co.nz/plyr Hadley On Sun, Apr 26, 2009 at 12:42 PM, wrote: > After a year my R programming style is still very "C like". > I am still writing a lot of "for loops" and finding it difficult to recognize > where, in place o

Re: [R] Bumps chart in R

2009-04-26 Thread hadley wickham
In statistics, a bumps chart is more commonly called a parallel coordinates plot. Hadley On Sun, Apr 26, 2009 at 5:45 PM, Andreas Christoffersen wrote: > Hi there, > > I would like to make a 'bumps chart' like the ones described e.g. > here: http://junkcharts.typepad.com/junk_charts/bumps_chart/

Re: [R] Bumps chart in R

2009-04-27 Thread hadley wickham
] > library(ggplot2) > qplot(year,value, data=data,label=countries, geom=c("line","text"), > group=countries, col=countries) > > But I would like to have the text labels show only once - e.g. at 1990 > - and also control the size of the text. In my crude qplot, setting > size=2 e.g. changes not onl

Re: [R] gridding values in a data frame

2009-04-30 Thread hadley wickham
It's hard to check without a reproducible example, but the following code should give you a 3d array of lat x long x time: library(reshape) df$lat <- round_any(df$LATITUDE, 5) df$long <- round_any(df$LONGITUDE, 5) df$value <- df$TIME cast(df, lat ~ long ~ time, mean) On Thu, Apr 30, 2009 at 10

Re: [R] A beginner's question about ggplot

2009-05-01 Thread hadley wickham
On Fri, May 1, 2009 at 12:22 PM, MUHC-Research wrote: > > Dear R-users, > > I would have another question about the ggplot() function in the ggplot2 > package. > > All the examples I've read so far in the documentation make use of a single > neatly formatted data.frame. However, sometimes, one may

Re: [R] Reccomendation for graphics package

2009-05-01 Thread hadley wickham
> Is situation anything better with ggplot2?  It seems rather easy to get e.g. > line plots with error bars, provided that one feeds the data to some > modeling/regression function and passes the result over for plotting.. but > what > if I have generated my own error bar data?  This is almost tri

Re: [R] MCO: Timing using model.matrix method

2009-05-01 Thread hadley wickham
> My issue is self-evident:  using this method resulted in a 30 fold > increase in time.  My question is why?  If I time the individual > components separately, nothing is unusual.  My hunch is the > "interaction" between the model.matrix and nsga2 methods. > > Any ideas on how to speed this proces

Re: [R] Reccomendation for graphics package

2009-05-01 Thread hadley wickham
On Fri, May 1, 2009 at 2:38 PM, Zeljko Vrba wrote: > On Fri, May 01, 2009 at 01:06:34PM -0500, hadley wickham wrote: >> >> It should be trivial with ggplot2 too, but it's hard to provide >> concrete advice without a concrete problem. >> > Elementary prob

Re: [R] Last month on the Revolutions blog

2009-05-02 Thread hadley wickham
Hi David, I think the revolution blog is fantastic and a great service to the R community. Thanks for all your hard work! Hadley On Fri, May 1, 2009 at 4:54 PM, David M Smith wrote: > I write about R every weekday at http://blog.revolution-computing.com > . In case you missed them, here are so

Re: [R] Overlaying graphs from different datasets with ggplot

2009-05-03 Thread hadley wickham
On Thu, Apr 30, 2009 at 2:03 PM, MUHC-Research wrote: > > Dear R-users, > > I recently began using the ggplot2 package and I am still in the process of > getting used to it. > > My goal would be to plot on the same grid a number of curves derived from > two distinct datasets. The first dataset (ca

Re: [R] quick square root axes

2009-05-05 Thread hadley wickham
> If you do write your own, the hardest part will be picking the nice tick > marks.  They should be approximately evenly spaced, but at nice round values > of the original variable:  that's hard to do in general.  R has the pretty() > function for the linear scale, and doesn't do too badly on log a

Re: [R] re shape package - use one cast() instead of many

2009-05-05 Thread hadley wickham
On Tue, May 5, 2009 at 3:03 PM, jwg20 wrote: > > I have a data set that I'm trying to melt and cast in a specific way using > the reshape package. (I'll use the ff_d dataset from reshape so I don't have > to post a toy data set here. ) > > Lets say I'm looking for the interaction of treatment with

Re: [R] re shape package - use one cast() instead of many

2009-05-05 Thread hadley wickham
On Tue, May 5, 2009 at 3:55 PM, jwg20 wrote: > > Thanks for your help! I wasn't sure what the margins variable did, but I'm > beginning to understand. I'm almost there, but with my data (and with ff_d) > I tried to margin over two variable names, however it only does one of them. > So with ff_d I

Re: [R] Do you use R for data manipulation?

2009-05-06 Thread hadley wickham
> Take a look at plyr and reshape packages (http://had.co.nz/), I have a hunch > that they would have saved me a lot of headache had I found out about them > earlier :) As the author of these two packages, I'm admittedly biased, but I think R is unparalleled for data preparation, manipulation, and

Re: [R] Houston, TX Users Group

2009-05-06 Thread hadley wickham
Hi Robert, I'm organising one - sign up to the mailing list, http://groups.google.com/group/houston-r. I'm hoping to organise our first meeting this summer. Hadley On Wed, May 6, 2009 at 10:15 AM, Robert Sanford wrote: > I'm looking for a Users Group in or near Houston, TX. > > Many thanks! >

Re: [R] plyr: issue with column names when converting one element list to dataframe

2010-01-06 Thread hadley wickham
Hi Mark, Could you send a the results of dput(l)? It will make exploration easier. Hadley On Wed, Jan 6, 2010 at 8:07 AM, Mark Heckmann wrote: > > Hi, > > I have an issue concerning plyr. > I have a list l as output from dlply. > >> l > $`1` >     (0.5,1.5] (1.5,2.5] (2.5,3.5]  (3.5,4.5] > f5_

Re: [R] Building static HTML help pages in R 2.10.x on Windows

2010-01-07 Thread hadley wickham
> What I'd really like is for someone who has good taste to redesign the look > of the whole system.  I think one or two people are working on packages to > do this, and I'd much rather spend time providing whatever low level support > they need, rather than doing it myself. Have you looked at add

Re: [R] Building static HTML help pages in R 2.10.x on Windows

2010-01-07 Thread hadley wickham
>>  I have to close all the tabs and call help to open them >> again.  Also, the R-supplied java tool for searching help is ancient and >> underwhelming. > > Then contribute a new one. And this would be pretty easy to, since you can program it in R. There are heaps of possibilities - you could use

Re: [R] Building static HTML help pages in R 2.10.x on Windows

2010-01-08 Thread hadley wickham
> I see. Well, I never lacked any of these capabilities... Please understand > that people who use R to do their work may have different objectives than the > developers - and they form the majority of R users. Well how about a documentation system that could look back over your history and noti

[R] Online R documentation

2010-01-08 Thread Hadley Wickham
Dear list, Many people seem unhappy with the new documentation server because you need to have R running to access it, and it's not immediately obvious how to bookmark references so they work long-term. One solution to this problem is to have a globally available website that provides access to al

Re: [R] Online R documentation

2010-01-08 Thread Hadley Wickham
>> Many people seem unhappy with the new documentation server because you >> need to have R running to access it, and it's not immediately obvious >> how to bookmark references so they work long-term. One solution to >> this problem is to have a globally available website that provides >> access to

Re: [R] Online R documentation

2010-01-08 Thread Hadley Wickham
> http://pledgie.com/campaigns/7707 - here you can donate as much or as > little as you like to support this project.  You won't pay until the > total amount has been pledged. I misread the documentation - do you actually pay right away. If I don't reach the $1000, I'll pass on the money to a goo

Re: [R] plyr: issue with column names when converting one element list to dataframe

2010-01-08 Thread hadley wickham
y: > >> dput(l) > list(structure(c(0.182198327359618, 0.473715651135006, 0.29689366786141, > 0.0471923536439665), .Dim = c(1L, 4L), .Dimnames = list("f5_9", >    c("(0.5,1.5]", "(1.5,2.5]", "(2.5,3.5]", "(3.5,4.5]" > > Mark &

Re: [R] Can an object reference itself?

2010-01-15 Thread hadley wickham
On Fri, Jan 15, 2010 at 5:30 PM, Janko Thyson wrote: > Dear List, > > I am not really familiar with any other language than R, but I’ve heard that > in other languages there is something called “self referencing”. > > Here’s what I’m trying to get an answer for: > Suppose there is a function that

Re: [R] Help using Cast (Text) Version

2010-01-18 Thread hadley wickham
>> If you can point me towards a doc that explains this in simple terms I >> would be obliged. Don't expect you to have to provide the answer. > > Any of the introductory texts should explain the various forms of indexing > and the use of the apply family of functions. They are both central to > ef

Re: [R] How to convert character matrix or data.frame to numeric?

2010-01-18 Thread hadley wickham
> Ouch!   Hmmm.   From the "Value" section of the apply docs... "If each call > to FUN returns a vector of length n, then apply returns an array of > dimension c(n, dim(X)[MARGIN]) if n > 1."  Since I set MARGIN to 1, then I > was operating on rows where n  is 3. > >> c(n, dim(X)[MARGIN]) > [1] 3 2

Re: [R] problem of data manipulation

2010-01-19 Thread hadley wickham
On Mon, Jan 18, 2010 at 1:54 PM, Bert Gunter wrote: > One way to do it: > > 1. Convert your date column to the Date class using the as.Date() function. > This allows you to do the necessary arithmetic on the dates below. > dt <- as.Date(a[,4],"%d/%m/%Y") > > 2. Create a factor out of your first th

Re: [R] problem of data manipulation

2010-01-20 Thread hadley wickham
> Note that in the documentaton ?"[.data.table" where I say that 'by' is slow, > I mean relative to how fast it could be.  Its seems, in this specific > example anyway, and with the code posted so far, to be significantly faster > than sqldf and plyr. Of course the best of both worlds would be to

Re: [R] problem of data manipulation

2010-01-20 Thread hadley wickham
On Wed, Jan 20, 2010 at 8:43 AM, Matthew Dowle wrote: > Sounds like a good idea. Would it be possible to give an example of how to > combine plyr with data.table, and why that is better than a data.table only > solution ? Well, ideally, you'd do: adt <- data.table(a) ans2 <- ddply(a, c("var1", "

Re: [R] standardizing one variable by dividing each value by the mean - but within levels of a factor

2010-01-21 Thread hadley wickham
On Wed, Jan 20, 2010 at 4:37 PM, Dimitri Liakhovitski wrote: > Hello! > > I have a data frame with a factor and a numeric variable: > > x<-data.frame(factor=c("b","b","d","d","e","e"),values=c(1,2,10,20,100,200)) > > For each level of "factor" - I would like to divide each value of > "values" by t

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

2010-01-25 Thread hadley wickham
On Mon, Jan 25, 2010 at 4:43 AM, Paul Hiemstra wrote: > Brad Patrick Schneid wrote: >> >> ###  The following is very helpful # listOfFiles <- >> list.files(pattern= ".txt") d <- do.call(rbind, lapply(listOfFiles, >> read.table)) ### >> >> but what if each file c

Re: [R] Strange tick in ggplot geom_area; and ordering, again

2010-01-26 Thread hadley wickham
Hi Dieter, It looks like a bug: Order works fine with bars: qplot(factor(dur),weight=p,data=cf1, fill=score, geom = "bar", order = rev(score)) but not with areas: qplot(dur, p, data=cf1, fill=score, geom = "area", order = rev(score)) I'll add it to my to do list. Hadley On Tue, Jan 26, 2010 a

Re: [R] Strange tick in ggplot geom_area; and ordering, again

2010-01-26 Thread hadley wickham
> can you also reproduce the “triangles” problem? Is it just a trivial > corollary of the order-bug? The triangles are there because you have a layer of points (from the qplot default) and layer of areas. Setting geom = "area" in qplot fixes that. Hadley -- http://had.co.nz/

Re: [R] Strange tick in ggplot geom_area; and ordering, again

2010-01-26 Thread hadley wickham
> > In case you have a temporary workaround, it would be nice to have it. It’s a > show stopper for my report. Bars are not an option, because the curve looks > too jaggy. > I just remember that to work around the problem, you can just manually order the data frame: cf1 <- cf1[with(cf1, order(d

Re: [R] SemiPar/spm question

2010-01-30 Thread hadley wickham
Hi Chuck, It looks like a scoping bug in spmx to me: f <- function() { x <- data[data$id=="111",] print(spm(x$value ~ f(1:nrow(x } f() I'd suggest you contact the package maintainer directly. Hadley On Fri, Jan 29, 2010 at 1:34 PM, Chuck White wrote: > Hello -- I posted this question

Re: [R] Using apply function on duplicates in a data.frame

2010-01-31 Thread hadley wickham
On Sun, Jan 31, 2010 at 5:05 PM, Sunny Srivastava wrote: > Dear R-Helpers, > I have a data.frame (df) and the head of data.frame looks like > >     ProbeUID ControlType     ProbeName GeneName SystematicName > 1665     1577           0 pSysX_50_22_1 pSysX_50       pSysX_50 > 5422     5147          

Re: [R] typo in contrast package's vignettes

2010-02-03 Thread hadley wickham
> Really? Where exactly is the loophole in 'If the question relates to a > contributed package ... try contacting the package maintainer first.'? How about the general R philosophy that if you dare to mistakenly submit a bug report that turns out to be a "feature", not a bug, you shall be well and

Re: [R] tapply for function taking of >1 argument?

2010-02-03 Thread hadley wickham
On Wed, Feb 3, 2010 at 11:06 AM, David Freedman <3.14da...@gmail.com> wrote: > > also, > > library(plyr) > ddply(d,~grp,function(df) weighted.mean(df$x,df$w)) Or ddply(d, "grp", summarise, mean = weighted.mean(x, w)) which is convenient if you want more than one output Hadley -- http://had.

Re: [R] tapply for function taking of >1 argument?

2010-02-03 Thread hadley wickham
> It will of necessity be slower (because there's more machinery underlying > the sqldf package); but I doubt whether it would be noticeably slower than > the native R solution in most practical situations. The same would be true > for plyR's implementation (it relies on the proto package, which sl

Re: [R] ggplot2/qplot question regarding reducing the no. of x-axis labels

2010-02-03 Thread hadley wickham
Hi Thomas, Please provide a reproducible example. The most likely explanation is that after loading your data you haven't converted your "date" variable from a factor into a real date. Hadley On Wed, Feb 3, 2010 at 1:15 PM, Thomas Adams wrote: > All: > > I am using the command: qplot(date,MAE,

Re: [R] Calculating subsets "on the fly" with ddply

2010-02-03 Thread hadley wickham
> The ddply invocation would look like so: > > R> my <- ddply(iris, .(w=Sepal.Length < 5.5, Species), transform, > grmean=mean(Petal.Width)) > R> head(my) >      w Sepal.Length Sepal.Width Petal.Length Petal.Width    Species > grmean > 1 FALSE          5.8         4.0          1.2         0.2     s

Re: [R] String Manipulation- Extract numerical and alphanumerical segment

2010-02-05 Thread hadley wickham
On Fri, Feb 5, 2010 at 9:29 AM, jim holtman wrote: > Does this help: > >> x <- >> c("1234567.z3.abcdef-gh.12","1234567.z3.abcdef-gh.12","1234567.z3.abcdef-gh.12") >> y <- strsplit(x, '[.]') Here's another way with the stringr package: library(stringr) x <- c("1234567.z3.abcdef-gh.12","1234567.

Re: [R] melt on OSX ignores na.rm=T

2010-02-06 Thread hadley wickham
Hi Titus, The latest version of reshape is 0.8.3 - perhaps upgrading will fix your problem. Hadley On Sat, Feb 6, 2010 at 4:51 AM, Titus von der Malsburg wrote: > Hi list, > > I run R on Linux and OSX.  On both systems I use R version 2.9.2 (2009-08-24) > and reshape version: 0.8.2 (2008-11-04)

Re: [R] conditioned xyplot, many y variables

2010-02-07 Thread hadley wickham
On Sun, Feb 7, 2010 at 11:32 AM, Jacob Wegelin wrote: > > The example below creates parallel time-series plots of three different y > variables conditioned by a dichotomous factor. In the graphical layout, > >        •       Each y variable inhabits its own row and is plotted on its > own distinct

[R] Fast way to determine number of lines in a file

2010-02-08 Thread Hadley Wickham
Hi all, Is there a fast way to determine the number of lines in a file? I'm looking for something like count.lines analogous to count.fields. Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-he

Re: [R] Fast way to determine number of lines in a file

2010-02-08 Thread Hadley Wickham
> parser::nlines does it in C. Looks promising, but I need something that uses connections because I'm working with big bzipped files. Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEAS

Re: [R] Fast way to determine number of lines in a file

2010-02-08 Thread hadley wickham
Hi Ken, > How about something like > length(readLines(fname)) I'm trying to avoid the overhead of reading the file in twice. (I'm trying to preallocate a data structure for a chunked read) Hadley -- http://had.co.nz/ __ R-help@r-project.org mailin

Re: [R] data frames; matching/merging

2010-02-08 Thread hadley wickham
On Mon, Feb 8, 2010 at 10:39 AM, Jonathan wrote: > Hi all, >    I'm feeling a little guilty to ask this question, since I've > written a solution using a rather clunky for loop that gets the job > done.  But I'm convinced there must be a faster (and probably more > elegant) way to accomplish what

Re: [R] R ggplot2 legend text left justify

2010-02-09 Thread hadley wickham
Hi Paul, That's a bug in the current version of ggplot. I'm working on update for later this week. Hadley On Mon, Feb 8, 2010 at 5:56 PM, Paul Sutcliffe wrote: > > > In ggplot2 how do you justify the legend text ? > In the example below the opts(legend.text = theme_text(size = 9,hjust=0)) >  c

Re: [R] Fast way to determine number of lines in a file

2010-02-09 Thread hadley wickham
> I was looking for a fast line counter as well a while ago and ended up > writing a small function in R: > >  countLines() in the R.utils package > > At least at the time, it was faster than readLines() [for unknown > reasons].  It is also more memory efficient.  It supports connections. >  I don'

Re: [R] ggplot2 stacked line plot

2010-02-09 Thread hadley wickham
Hi Liam, Your syntax is a little off. You want: p <- ggplot2(~, aes(x = ~, y = ~, colour = Type)) + geom_area(aes(fill = Type), position = 'stack') Position isn't an aesthetic. Hadley On Sun, Feb 7, 2010 at 10:40 PM, Liam Blanckenberg wrote: > Hi all, > > I have been hunting around for hou

Re: [R] ggplot2 stacked line plot

2010-02-09 Thread hadley wickham
st like vertically summing an area chart). > Really all I'm after is a stacked area chart where the fill for each > 'Type' has been removed, leaving only a line for each (stacked) Type's > value... > > I hope this is somewhat clear! > > Many thanks,

Re: [R] How to understand the mentality behind tidyverse and ggplot2?

2020-11-18 Thread Hadley Wickham
I'd recommend two places to get started: * https://r4ds.had.co.nz/data-visualisation.html for a quick intro to ggplot2 (and the rest of the book explains the general tidyverse philosophy) * https://ggplot2-book.org for the full details of ggplot2. Hadley On Wed, Nov 18, 2020 at 11:37 AM C W wr

Re: [R] roxygen2 & markdown & math

2021-01-14 Thread Hadley Wickham
On Tuesday, January 12, 2021, Duncan Murdoch wrote: > On 12/01/2021 1:12 p.m., Sigbert Klinke wrote: > >> Hi, >> >> thanks a lot, but maybe I was to vague. >> >> I do not want to replace \eqn{...} and \deqn{...} by \mjseqn{...} and >> \mjsdeqn{...}. I would like to use $...$ and $$...$$ as in Rma

Re: [R] help finding a starting point to diagnose inability to install or update packages

2021-04-25 Thread Hadley Wickham
If this happens again in the future, you might try the development version of pak: install.packages("pak", repos = "https://r-lib.github.io/p/pak/dev/";) pak::pak("tidyverse") pak automatically diagnoses a number of common problems that causes install.packages() to fail. Hadley On Sun, Apr 25,

Re: [R] interval between specific characters in a string...

2022-12-04 Thread Hadley Wickham
On Sun, Dec 4, 2022 at 12:50 PM Hervé Pagès wrote: > > On 03/12/2022 07:21, Bert Gunter wrote: > > Perhaps it is worth pointing out that looping constructs like lapply() can > > be avoided and the procedure vectorized by mimicking Martin Morgan's > > solution: > > > > ## s is the string to be sear

Re: [R] interval between specific characters in a string...

2022-12-04 Thread Hadley Wickham
On Sun, Dec 4, 2022 at 1:22 PM wrote: > > This may be a fairly dumb and often asked question about some functions like > strsplit() that return a list of things, often a list of ONE thing that be > another list or a vector and needs to be made into something simpler.. > > The examples shown bel

Re: [R] Lazy-load corrupt?

2023-02-04 Thread Hadley Wickham
This often indicates you need to restart R. Hadley On Friday, February 3, 2023, Nick Wray wrote: > Hello When trying to call various packages eg > library(raster) > library(sp) > library(rgdal) > > I get this error message: > Loading required package: sp > Error: package or namespace load faile

Re: [R] R does not run under latest RStudio

2023-04-07 Thread Hadley Wickham
I'm not aware of widespread problems, but it's possible that some combination of OS, RStudio version, and R version might be causing problems. Unfortunately I don't think there's enough information in this thread for anyone to tell if that's the case. Hadley On Fri, Apr 7, 2023 at 1:18 PM Sorkin,

Re: [R] Supplying names to vars() in ggplot2.

2019-11-17 Thread Hadley Wickham
See this new vignette in dev ggplot2: https://ggplot2.tidyverse.org/dev/articles/ggplot2-in-packages.html Hadley On Saturday, November 16, 2019, Rolf Turner wrote: > > I need to call ggplot() from another function with the names of the > faceting variables supplied as arguments to the calling f

Re: [R] A better scales::dollar() ?

2019-12-09 Thread Hadley Wickham
You can get pretty close with label_number_si(): pounds <- scales::label_number_si(prefix = "£") pounds(10 ^ (0:7)) #> [1] "£1""£10" "£100" "£1K" "£10K" "£100K" "£1M" "£10M" Created on 2019-12-09 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0.9001) Hadley On Fri, Dec

Re: [R] Off-topic: ChatGPT Code Interpreter

2023-07-18 Thread Hadley Wickham
> I am not sure what your example means but text to image conversion can be > done quite easily in many programming environments and does not need an AI > unless you are using it to hunt for info. I mean you can open up many Paint > or Photo programs and look at the menus and often one allows you

Re: [R] Merge with closest (not equal) time stamps

2023-08-09 Thread Hadley Wickham
It sounds like you might want a rolling join, e.g. https://dplyr.tidyverse.org/reference/join_by.html#rolling-joins. (And data.table has similar functionality which inspired dplyr) Hadley On Mon, Aug 7, 2023 at 9:32 PM Naresh Gurbuxani wrote: > > > I have two dataframes, each with a column for

Re: [R] Book Recommendation

2023-08-28 Thread Hadley Wickham
You might find this chapter of R for Data Science helpful: https://r4ds.hadley.nz/databases Hadley On Tue, Aug 29, 2023 at 3:47 AM Stephen H. Dawson, DSL via R-help wrote: > > Good Morning, > > > I am doing some research to develop a new course where I teach. I am > looking for a book to use in

Re: [R] Book Recommendation

2023-08-28 Thread Hadley Wickham
These days I'd recommend duckdb (https://cran.r-project.org/web/packages/duckdb/index.html) instead. It's a similar design to RSQLite (i.e. you don't need a separate server) but it's designed for the needs of data science. Hadley On Tue, Aug 29, 2023 at 9:22 AM Martin Møller Skarbiniks Pedersen

Re: [R] how to get paste() to output \% so LaTeX will interpret it as a percent sign rather than a comment symbol

2023-09-08 Thread Hadley Wickham
You're getting confused between the contents of the string and the printed representation of the string. There's a little bit about this in R4DS: https://r4ds.hadley.nz/strings#escapes (or in brief, do writeLines(trailing.7.message)) Hadley On Fri, Sep 8, 2023 at 7:23 AM Christopher Ryan via R-h

Re: [R] devtools - bad credentials R4.4.1

2024-06-21 Thread Hadley Wickham
The place to start for such problems is always usethis::git_sitrep() Hadley On Thu, Jun 20, 2024 at 11:17 PM Robert Baer wrote: > I am trying to install a package from github which has worked fine in > the past, but now seems to be stuck on some new authentication issues. > Does anyone know how

Re: [R] Reorganize the data (dplyr or other packages?)

2020-08-17 Thread Hadley Wickham
features, and we believe that there are now better approaches to solving the same problem. Hadley On Mon, Aug 17, 2020 at 3:58 AM Eric Berger wrote: > > Thanks for this information Thierry. I was not aware. > The author of the packages is Hadley Wickham. He writes on Github that he > d

Re: [R] Reorganize the data (dplyr or other packages?)

2020-08-17 Thread Hadley Wickham
> | but they won't receive any new > | features, and we believe that there > | are now better approaches to solving > | the same problem. > > Is tidyr::pivot_longer this better > solution? It is an easier to understand > version of the now retired and confusing > (for me) tidyr::gather which at le

Re: [R] combine filter() and select()

2020-08-20 Thread Hadley Wickham
On Wed, Aug 19, 2020 at 10:03 AM Ivan Calandra wrote: > > Dear useRs, > > I'm new to the tidyverse world and I need some help on basic things. > > I have the following tibble: > mytbl <- structure(list(files = c("a", "b", "c", "d", "e", "f"), prop = > 1:6), row.names = c(NA, -6L), class = c("tbl_d

[R] The R Journal, Volume 5, Issue 1

2013-07-03 Thread Hadley Wickham
Dear all, The latest issue of The R Journal is now available at http://journal.r-project.org/archive/2013-1/ Many thanks to all contributors. Hadley -- Editor-in-chief, The R Journal ___ r-annou...@r-project.org mailing list https://stat.ethz.ch/mail

[R] Understanding S4 method dispatch

2013-08-13 Thread Hadley Wickham
Hi all, Any insight into the code below would be appreciated - I don't understand why two methods which I think should have equal distance from the call don't. Thanks! Hadley # Create simple class hierarchy setClass("A", "NULL") setClass("B", "A") a <- new("A") b <- new("B") setGeneric("f", f

Re: [R] Understanding S4 method dispatch

2013-08-13 Thread Hadley Wickham
> The class AB inherits from A and from B, but B already inherits from class A. > So actually you only have an object of class B in your object of class AB. > When you call the function f R looks for a method f for AB objects. It does > not find such a method and looks for a method of the object

Re: [R] Understanding S4 method dispatch

2013-08-14 Thread Hadley Wickham
> In my opinion the reason for the behavior lies in the specific multiple > inheritance structure between AB, B and A. So what if we don't make such a weird inheritance structure, and instead have A and B inherit from a common parent: setClass("A", contains = "list") setClass("B", contains = "li

Re: [R] Understanding S4 method dispatch

2013-08-14 Thread Hadley Wickham
On Wed, Aug 14, 2013 at 11:36 AM, Simon Zehnder wrote: > Because the signature is always (A,A) or (B,B). Then, as in AB we have A and > B and no relationship between A and B, R chooses the method > lexicographically. The result is as expected: f for A is chosen. It's not as expected, because it

Re: [R] Appropriateness of R functions for multicore

2013-08-20 Thread Hadley Wickham
> For tasks which don't involve I/O but fail with mclapply, how does one > work out where the problem is? The handy browser() function which > allows for interactive diagnosis won't work with parallel jobs. > > What other approaches can one use? ?dump.frames - interactive debugging after the fac

Re: [R] RCurl cookiejar

2013-08-25 Thread Hadley Wickham
Hi Earl, Have you read the libCurl documentation for CURLOPT_COOKIEJAR? : Pass a file name as char *, zero terminated. This will make libcurl write all internally known cookies to the specified file when curl_easy_cleanup(3)is called. If no cookies are known, no file will be created. Specify "-"

Re: [R] the inverse of assign()

2013-08-27 Thread Hadley Wickham
It's not really the inverse of assign (that's get), but I think you want substitute. See http://adv-r.had.co.nz/Computing-on-the-language.html for more details. Hadley On Tue, Aug 27, 2013 at 4:13 PM, Robert Lynch wrote: > I am looking for a way to extract the name of a variable that has been >

Re: [R] new.env() and attach for write?

2013-08-28 Thread Hadley Wickham
On Wed, Aug 28, 2013 at 4:32 PM, ivo welch wrote: > is it possible to temporarily change the destination environment where > objects are written to? I am thinking > > a <- new.env() > attach(a) > ### run some code, such as... > b <- function(x) x > detach(a) > a$b > > obviously, this

Re: [R] Should I wrap more package examples in \dontrun{} ?

2013-09-03 Thread Hadley Wickham
> As a user of your package, I would find it irritating if example(foo) didn't > run anything. It would be more irritating (and would indicate sloppiness > on your part) if the examples failed when I cut and pasted them. These both > suggest leaving the examples running. > > As the author of you

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