In general doing vectorized calculations on larger data units is going to lead
to faster computation, so it would be better in the long run if your taste
could evolve to appreciate Jim's approach.
On October 30, 2018 10:03:15 PM PDT, Rolf Turner
wrote:
>
>On 10/31/18 3:47 PM, jim holtman wrote
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 Ed
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 -- man
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, eithe
> 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 the
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]]
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 wh
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)
## star
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 separ
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 in
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 wra
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 ab
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 a
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 <- func
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.
- Or
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,
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 per
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 defa
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(
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 fully
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 links
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 n
22 matches
Mail list logo