[R] `mapply(function(x) function() x, c(a, b))$a()' returns `b'

2012-05-03 Thread Casper Ti. Vector
As the title says, I want to apply a function (which itself returns a function) to a list (or vector), and get a list (or vector) of generated functions as the return value, but get unexpected result. Anyone with an idea about the reason of this phenomenon and a correct way to implement the

Re: [R] `mapply(function(x) function() x, c(a, b))$a()' returns `b'

2012-05-03 Thread Casper Ti. Vector
Thank you very much, though I still don't quite undertdand the explanation :) Nevertheless, I just found a seemingly simple (at least quiker to type) solution after try-and-error: eval(mapply(function(x) {x; function() x}, c(a, b))) Wish it may help future readers. On Thu, May 03, 2012 at

[R] ggplot2: behaviour with empty datasets

2011-12-23 Thread Casper Ti. Vector
For example, prepare like this df.0 - data.frame(x = 0, y = 0, note = 1) df.1 - subset(df.0, note == 1) df.2 - subset(df.0, note == 2) Then a call to ggplot() + aes(x = x, y = y) + geom_point(data = df.1) + geom_point(data = df.2) produces the error Error in eval(expr, envir, enclos) :

Re: [R] ggplot2: behaviour with empty datasets

2011-12-23 Thread Casper Ti. Vector
Thanks, I'll post to that list if the encountered problem is just about ggplot2. And from the date of the issue on GitHub it seems that I might need to manually work around the problem some more times :) On Fri, Dec 23, 2011 at 08:10:05AM -0600, Hadley Wickham wrote: See

Re: [R] ggplot2: expression() in legend labels?

2011-10-04 Thread Casper Ti. Vector
Hmm, that's my fault when composing this mail, but the problem was really encountered at that time. Nevertheless, neither can I reproduce the problem now, perhaps I just made another mistake at that time. Thanks all the same, and sorry for the disturbance anyway :| On Tue, Oct 04, 2011 at

[R] Problem with logarithmic nonlinear model using nls() from the `stats' package

2011-10-01 Thread Casper Ti. Vector
Example: f - function(x) { 1 + 2 * log(1 + 3 * x) + rnorm(1, sd = 0.5) } y - f(x - c(1 : 10)); y [1] 4.503841 5.623073 6.336423 6.861151 7.276430 7.620131 7.913338 8.169004 [9] 8.395662 8.599227 nls(x ~ a + b * log(1 + c * x), start = list(a = 1, b = 2, c = 3), trace = TRUE) 37.22954 : 1

Re: [R] Problem with logarithmic nonlinear model using nls() from the `stats' package

2011-10-01 Thread Casper Ti. Vector
Ah, now I see... Thanks very much :) On Sat, Oct 01, 2011 at 09:27:34AM -0400, Gabor Grothendieck wrote: On Sat, Oct 1, 2011 at 5:28 AM, Casper Ti. Vector caspervec...@gmail.com wrote: Its linear given c so calculate the residual sum of squares using lm (or lm.fit which is faster) given c

[R] ggplot2: expression() in legend labels?

2011-09-24 Thread Casper Ti. Vector
Is there any way to use expression() in legend labels with ggplot2? It seems that things like scale_shape_manual(value = c( x = expression(italic(x)), y = expression(italic(y)) )) don't work. Thanks very much :) -- Using GPG/PGP? Please get my current public key (ID: 0xAEF6A134,

[R] spline for implicit functions

2011-09-21 Thread Casper Ti. Vector
Hello list, is there any R function for generating spline for implicit functions, for example a spline for an two-column data frame where for one value for one variable there maybe several correspondent values for another? Many thanks. Currently I'm using this home-made one: spline2d -