Re: [R] [FORGED] Re: Using apply

2018-10-30 Thread Rolf Turner
On 10/31/18 3:47 PM, jim holtman wrote: s2 <- apply(x*x, 2, sum) s2 [1] 55 330 It seems to me to be more "natural" (and perhaps more amenable to generalisation) to do: s2 <- apply(x,2,function(v){sum(v^2)}) But it's probably just a matter of taste. cheers, Rolf -- Technical

Re: [R] Using apply

2018-10-30 Thread Bert Gunter
Indeed. But perhaps it's also worth noting that if such statistics are calculated as implementations of (e.g. anova) formulae still found (sadly) in many statistics texts, then they shouldn't be calculated at all. Rather, the appropriate matrix methods (e.g. QR decompositions ) built into R --

Re: [R] Using apply

2018-10-30 Thread Peter Langfelder
It should be said that for many basic statistics, there are faster functions than apply, for example here you want sum = colSums(x) As already said, for sum of squares you would do colSums(x^2). Many useful functions of this kind are implemented in package matrixStats. Once you install it,

Re: [R] Using apply

2018-10-30 Thread jim holtman
> s2 <- apply(x*x, 2, sum) > s2 [1] 55 330 Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. On Tue, Oct 30, 2018 at 10:28 PM Steven Yen wrote: > > I need help with "apply". Below, I have no problem getting

[R] Using apply

2018-10-30 Thread Steven Yen
I need help with "apply". Below, I have no problem getting the column sums. 1. How do I get the sum of squares? 2. In general, where do I look up these functions? Thanks. x<-matrix(1:10,nrow=5); x sum <- apply(x,2,sum); sum [[alternative HTML version deleted]]

Re: [R] Question about function scope

2018-10-30 Thread Neal Fultz
I'm going to n-th Duncan's recommendations to try to keep your functions small and try not to mess with environments. ... So I'm ashamed that I wrote the following - I apologize in advance. But as an intellectual exercise, we can cannibalize the code for `dynGet` and create a `dynSet` function

Re: [R] [FORGED] grid.grab(): strange behavior of "wrap" argument when working with lattice output

2018-10-30 Thread Paul Murrell
Hi Mostly these are bugs. One source of confusion: wrap=FALSE is NOT doing better than wrap=TRUE, which you can see if you start a new page before drawing the grabbed grob ... xyplot(1:5 ~ 1:5) trellis.focus() panel.abline(h = 3) panel.abline(h = 5) myGrob <- grid.grab(wrap = FALSE) ##

Re: [R-es] X Jornadas de Usuarios de R en Murcia. Últimos días de precio reducido

2018-10-30 Thread Antonio Maurandi López
Nota, precios reducidos par alas Xjur hasta el 1/nov: "Reducida: Estudiantes, Socios/as de Rhispano o UMUR . General: Resto de colectivos" *Hacerse socio o socia de Rhispano* es tan sencillo como escribir a la secretaria de Rhispano:

Re: [R] Question about function scope

2018-10-30 Thread Duncan Murdoch
On 30/10/2018 4:18 PM, Sebastien Bihorel wrote: Thanks Duncan for your quick reply. Ideally, I would want bar1 and bar2 to be independent functions, because they are huge in actuality and, as the actual foo function grows, I may end up with 10 different bar# functions. So I would like to

Re: [R] MSE Cross-validation with factor interactions terms MARS regression

2018-10-30 Thread varin sacha via R-help
Dear Prof. Dalgaard, I really thank you lots for your comments and responses. It perfectly works ! Many thanks. Le mardi 30 octobre 2018 à 00:30:11 UTC+1, peter dalgaard a écrit : The two lines did the same thing, so little wonder... More likely, the culprit is that a is assigned

[R] grid.grab(): strange behavior of "wrap" argument when working with lattice output

2018-10-30 Thread John G. Bullock
grid.grab() captures all of the current viewports and stores them as a grob. In theory, and often in practice, you can use grid.grab() to store an image now for drawing later on. But I have noticed some odd behavior of grid.grab() when working with lattice output. It is all related to the

Re: [R] Question about function scope

2018-10-30 Thread Sebastien Bihorel
Thanks a lot Eric, I think you are on the same page as Duncan (at least with his 2nd option). I will definitively explore this. From: "Eric Berger" To: "Duncan Murdoch" Cc: "Sebastien Bihorel" , "R mailing list" Sent: Tuesday, October 30, 2018 4:17:30 PM Subject: Re: [R] Question

Re: [R] Question about function scope

2018-10-30 Thread Sebastien Bihorel
That's cool! I think this solution would fit better with what my intended setup. Thanks a lot - Original Message - From: "Duncan Murdoch" To: "Sebastien Bihorel" , r-help@r-project.org Sent: Tuesday, October 30, 2018 4:18:51 PM Subject: Re: [R] Question about function scope Here's

Re: [R] Question about function scope

2018-10-30 Thread Sebastien Bihorel
Thanks Duncan for your quick reply. Ideally, I would want bar1 and bar2 to be independent functions, because they are huge in actuality and, as the actual foo function grows, I may end up with 10 different bar# functions. So I would like to separate them from foo as much as possible. -

Re: [R] Question about function scope

2018-10-30 Thread Duncan Murdoch
Here's another modification to your code that also works. It's a lot uglier, but will allow bar1 and bar2 to be used in multiple functions, not just foo. bar1 <- function(env){ env$x <- 1 env$y <- 1 env$z <- 1 with(env, cat(sprintf('bar1: x=%d, y=%d, z=%d\n', x, y, z))) } bar2 <-

Re: [R] Question about function scope

2018-10-30 Thread Eric Berger
Hi Sebastien, I like Duncan's response. An alternative approach is to pass around environments, as in the following: bar1 <- function(e) { e$x <- e$y <- e$z <- 1 cat(sprintf('bar1: x=%d, y=%d, z=%d\n', e$x, e$y, e$z)) } bar2 <- function(e) { e$x <- e$y <- e$z <- 2 cat(sprintf('bar2: x=%d,

Re: [R] Question about function scope

2018-10-30 Thread Duncan Murdoch
On 30/10/2018 3:56 PM, Sebastien Bihorel wrote: Hi, From the R user manual, I have a basic understanding of the scope of function evaluation but have a harder time understanding how to mess with environments. My problem can be summarized by the code shown at the bottom: - the foo function

[R] Question about function scope

2018-10-30 Thread Sebastien Bihorel
Hi, >From the R user manual, I have a basic understanding of the scope of function >evaluation but have a harder time understanding how to mess with environments. My problem can be summarized by the code shown at the bottom: - the foo function performs some steps including the assignment of

Re: [R] date and time data on x axis

2018-10-30 Thread snowball0916
Hi, Don I got it, I will try and study . Thanks very much. From: MacQueen, Don Date: 2018-10-30 00:01 To: snowball0916; r-help Subject: Re: [R] date and time data on x axis Here's an example of 24 hours of data at one second intervals. npts <- 24*60*60 df <- data.frame(

Re: [R] date and time data on x axis

2018-10-30 Thread snowball0916
Hi, Rui Thank you . I will try later. Thanks again. From: Rui Barradas Date: 2018-10-30 00:38 To: snowball0916; r-help Subject: Re: [R] date and time data on x axis Hello, Inline. Às 14:03 de 29/10/2018, snowball0916 escreveu: > Hi, Rui > Thanks for your code, even though I'm not

Re: [R] Should package be reinstalled when exterbal library is changed

2018-10-30 Thread Eric Berger
Hi Marc, Normally updating external libraries would not require re-installing an R package that uses it. The R package will be able to "find" the new one, because the updated library would be in the same place (sort of) as the previous library. On a linux system this is handled by system soft

[ESS] Building 18.10-1 from source

2018-10-30 Thread Nicky Chorley via ESS-help
Hi all, I'm trying to build the latest version from source on Linux. Per the readme, I run "make", which completes successfully and generates the compiled Emacs Lisp files under the lisp directory. The problem is then with "make install": $ make install cd lisp; make install make[1]: Entering

[R] Should package be reinstalled when exterbal library is changed

2018-10-30 Thread Marc Girondot via R-help
Dear R-experts, Some packages need external libraries to be installed. For example ncdf4 needs netcdf library or flextable need pandoc. When there is new version of external library, should the R package be installed again to use the new external version, or do the package finds itself the

[R-es] X Jornadas de Usuarios de R en Murcia. Últimos días de precio reducido

2018-10-30 Thread Antonio Maurandi López
¡Últimos días de precio reducido para asistir a las “X Jornadas de Usuarios de R” en Murcia! * *Fechas* : 22-23/nov de 2017 * *Lugar*: Universidad de Murcia * Precios reducidos para socios y socias de RHispano y UMUR 35€ , resto de colectivos 45€. * Precios a partir del 1