Displaying 20 results from an estimated 2000 matches similar to: "code for sum function"
2019 Feb 19
4
code for sum function
The algorithm does make a differece. You can use Kahan's summation
algorithm (https://en.wikipedia.org/wiki/Kahan_summation_algorithm) to
reduce the error compared to the naive summation algorithm. E.g., in R
code:
naiveSum <-
function(x) {
s <- 0.0
for(xi in x) s <- s + xi
s
}
kahanSum <- function (x)
{
s <- 0.0
c <- 0.0 # running compensation for lost
2019 Feb 20
3
code for sum function
Dear Tomas,
Where do I find these files? Do they contain the code for the sum function?
What do you mean exactly with your point on long doubles? Where can I find
documentation on this?
Cheers, Rampal
On Mon, Feb 18, 2019, 15:38 Tomas Kalibera <tomas.kalibera at gmail.com wrote:
> See do_summary() in summary.c, rsum() for doubles. R uses long double
> type as accumulator on systems
2019 Feb 20
0
code for sum function
Someone said it used a possibly platform-dependent
higher-than-double-precision type.
By the way, in my example involving rep(1/3, n) I neglected to include the
most precise
way to calculate the sum: n%/%3 + (n%%3)/3.
Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Wed, Feb 20, 2019 at 2:45 PM Rampal Etienne <rampaletienne at gmail.com>
wrote:
> Dear Will,
>
> This is exactly
2019 Feb 20
0
code for sum function
Dear Will,
This is exactly what I find.
My point is thus that the sum function in R is not a naive sum nor a
Kahansum (in all cases), but what algorithm is it using then?
Cheers, Rampal
On Tue, Feb 19, 2019, 19:08 William Dunlap <wdunlap at tibco.com wrote:
> The algorithm does make a differece. You can use Kahan's summation
> algorithm
2019 Feb 21
1
code for sum function
Specifically: https://svn.r-project.org/R/trunk/src/main/summary.c
And if you don't want to deal with Subversion, you can look at the
read-only github mirror:
https://github.com/wch/r-source/blob/e5b21d0397c607883ff25cca379687b86933d730/src/main/summary.c#L115-L131
On Thu, Feb 21, 2019 at 11:57 AM David Winsemius <dwinsemius at comcast.net> wrote:
>
>
> On 2/20/19 2:55 PM,
2019 Feb 19
0
code for sum function
This SO question may be of interest:
https://stackoverflow.com/questions/38589705/difference-between-rs-sum-and-armadillos-accu/
which points out that sum() isn't doing anything fancy *except* using
extended-precision registers when available. (Using Kahan's algorithm
does come at a computational cost ...)
On 2019-02-19 2:08 p.m., William Dunlap via R-devel wrote:
> The algorithm
2019 Feb 21
0
code for sum function
Dear Rampal,
you can download R source code in form of a tarball or from subversion,
please see
https://cran.r-project.org/doc/manuals/R-admin.html#Obtaining-R
https://cran.r-project.org/doc/manuals/R-admin.html#Using-Subversion-and-rsync
There is also a web access to subversion, so specifically the sum is
available in
https://svn.r-project.org/R/trunk/src/main/summary.c
The definition of
2019 Feb 21
0
code for sum function
On 2/20/19 2:55 PM, Rampal Etienne wrote:
> Dear Tomas,
>
> Where do I find these files? Do they contain the code for the sum function?
Yes.
https://svn.r-project.org/R/trunk/
David
>
> What do you mean exactly with your point on long doubles? Where can I find
> documentation on this?
>
> Cheers, Rampal
>
> On Mon, Feb 18, 2019, 15:38 Tomas Kalibera
2019 Feb 19
0
code for sum function
(I didn't see anyone else answer this, so ...)
You can probably find the R code in src/main/ but I'm not sure. You are
talking about a very simple calculation, so it seems unlike that the
algorithm is the cause of the difference. I have done much more
complicated things and usually get machine precision comparisons. There
are four possibilities I can think of that could cause (small)
2008 Jul 23
3
sum each row and output results
Hello,
I have the following data frame (DF):
V5 V5.1 V5.2 V5.3 V5.4 V5.5
2 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183
3 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183
4 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183
5 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677
2010 Aug 23
1
Speeding up sum and prod
Looking for more ways to speed up R, I've found that large
improvements are possible in the speed of "sum" and "prod" for long
real vectors.
Here is a little test with R version 2.11.1 on an Intel Linux system
> a <- seq(0,1,length=1000)
> system.time({for (i in 1:1000000) b <- sum(a)})
user system elapsed
4.800 0.010 4.817
> system.time({for (i
2010 Mar 04
1
Regarding SPICE
Hi,
I have set up KVM on FC12.
I was wondering if its possible to Display the VM using spice + libvirt?
As in, if I can define my domain with graphics like:
<graphics type='spice' port='-1' autoport='yes' listen='0.0.0.0'/>
or
<graphics type='spice' port='5903' '
2005 Jun 04
2
[PATCH] line endings fix
The replay gain code has dos line endings in CVS, which causes problems
for the Sun compiler, among others. Attached is a patch for the lazy,
but it's probably easier to fix locally and commit.
-r
2007 Mar 24
1
frequency tables and sorting by rowSum
Dear list,
I have some trouble generating a frequency table over a number of vectors.
Creating these tables over simple numbers is no problem with table()
> table(c(1,1,1,3,4,5))
1 3 4 5
3 1 1 1
, but how can i for example turn:
0 1 0
0 0 1
0 1 0
1 0 0
0 1 0
1 0 0
into
0 0 1 1
1 0 0 2
0 1 0 3
My second problem is, sorting rows and columns of a matrix by the rowSums/colSums.
I did it
2004 Nov 20
1
sum and partial argument name matching
"sum" (and perhaps other functions?) allows partial argument
name matching after its three-dots argument:
> sum(1:4, NA, n=78, na.rm=FALSE)
[1] 10
> sum(1:4, NA, n=78, na.rm=TRUE)
[1] 11
I can see there could be a discussion about whether or not this is
a bug, but I think all will agree that it's a might peculiar.
This is done in 2.0.1 but the same behavior is in 1.8.1.
2013 Jun 27
3
using "rollapply" to calculate a moving sum or running sum?
#using "rollapply" to calculate a moving sum or running sum?
#I am tryign to use rollapply to calcualte a moving sum? #I tried
rollapply and get the error message
#"Error in seq.default(start.at, NROW(data), by = by) :
# wrong sign in 'by' argument"
#example:
mymatrix <- ( matrix(data=1:100, nrow=5, ncol=20) )
mymatrix_cumsum <- ( matrix(data=NA, nrow=5,
2004 May 27
2
block diagonal matrix function
Hello List
I have just written a little function that takes two matrices as
arguments and returns a large matrix that is composed of the two input
matrices in upper-left position and lower-right position with a padding
value everywhere else. (function definition and toy example below). I
need nonsquare matrices and rowname() and colname() inherited appropriately.
Two questions:
(1) Is there a
2004 Apr 25
2
nonparametric multiple sample comparison
Hello all,
Here goes one of my first functions.
I want to make a nonparametric multiple sample comparison with unequal sample
sizes (see Zar?s Biostatistical Analysis, 3rd. Ed., pg. 201 Example 10.11, pg.
288 Example 11.10). In the real world, I want to compare samples of fish
length captured with different fishing gears.
After using the Kruskal-Wallis test I want to check the differences
2013 Jul 25
2
What algorithm is R using to calculate mean?
I am curious to know what algorithm R's mean function uses. Is there
some reference to the numerical properties of this algorithm?
I found the following C code in summary.c:do_summary():
case REALSXP:
PROTECT(ans = allocVector(REALSXP, 1));
for (i = 0; i < n; i++) s += REAL(x)[i];
s /= n;
if(R_FINITE((double)s)) {
for (i = 0; i < n; i++) t += (REAL(x)[i] -
2015 Jun 01
2
sum(..., na.rm=FALSE): Summing over NA_real_ values much more expensive than non-NAs for na.rm=FALSE? Hmm...
I'm observing that base::sum(x, na.rm=FALSE) for typeof(x) == "double"
is much more time consuming when there are missing values versus when
there are not. I'm observing this on both Window and Linux, but it's
quite surprising to me. Currently, my main suspect is settings in on
how R was built. The second suspect is my brain. I hope that someone
can clarify the below