Displaying 20 results from an estimated 400 matches similar to: "Generalized cumsum?"
2010 May 02
2
Retrieve regular expression groups
I'm trying to figure out how to get the text captured by capturing
groups out of a regex match. For instance, let's say I have the pattern
"foo ([^ ]+)" and I match it against the string "This is a foo sentence
I am reading." The group in the pattern will match the word "sentence"
in the target string. How can I get access to this matched group? All
I
2009 Sep 16
1
Windows RGui line editing
I've been using Tinn-R with RGui on Windows for quite some time
now, but it's very irritating how the Windows RGui allows only very
rudimentary line-editing. I can't even use shift-arrow key to select
text!
I searched through the archives and found what seemed to be a few
people asking about this, but I couldn't find a clear answer. I saw
some references in the docs to
2009 Apr 19
1
ave returns wrong data type (PR#13664)
Full_Name: Brendan Barnwell
Version: 2.9.0
OS: Windows XP Pro
Submission from: (NULL) (71.102.131.29)
The ave() function returns an incorrect datatype. Specifically, ave(x, g, f)
always returns a vector with the same mode as x, rather than using the mode of
the vector returned by f. Observe:
> x
[1] "A" "B" "C" "A" "B" "C"
2009 Apr 15
0
ave returns wrong type
I've been using the ave function to compute some statistics on a
data frame. After a while I noticed that, for some reason, it was
returning numerical statistics as strings instead of numbers. I delved
into the code of the functions and traced the problem to the following
fact:
ave uses split<- to do its work. Specifically, it does "split(x,
g) <- lapply(split(x, g),
2017 Jan 20
1
NaN behavior of cumsum
Hi!
I noticed that cumsum behaves different than the other cumulative functions wrt. NaN values:
> values <- c(1,2,NaN,1)
> for ( f in c(cumsum, cumprod, cummin, cummax)) print(f(values))
[1] 1 3 NA NA
[1] 1 2 NaN NaN
[1] 1 1 NaN NaN
[1] 1 2 NaN NaN
The reason is that cumsum (in cum.c:33) contains an explicit check for ISNAN.
Is that intentional?
IMHO, ISNA would be better
2009 Feb 17
2
cumsum vs. sum
I recently traced a bug of mine to the fact that cumsum(s)[length(s)]
is not always exactly equal to sum(s).
For example,
x<-1/(12:14)
sum(x) - cumsum(x)[3] => 2.8e-17
Floating-point addition is of course not exact, and in particular is
not associative, so there are various possible reasons for this.
Perhaps sum uses clever summing tricks to get more accurate results?
In some
2009 Sep 22
3
Function similar to cumsum/cumprod
Hello, everyone
I wonder if there is in R somewhere a function similar to cumsum().
The function calculates a statistic (say mean or standard deviation)
buy adding consequtively one more data point.
So, say I have a timeseries of 100 observations.
I start by calculating mean of first 30 observations
Then I add one observation and calculate mean of 31 observations
Then I add one more observation
2009 Nov 11
2
partial cumsum
Hello,
I am searching for a function to calculate "partial" cumsums.
For example it should calculate the cumulative sums until a NA appears,
and restart the cumsum calculation after the NA.
this:
x <- c(1, 2, 3, NA, 5, 6, 7, 8, 9, 10)
should become this:
1 3 6 NA 5 11 18 26 35 45
any ideas?
thank you and best regards,
stefan
2008 Aug 18
2
matrix row product and cumulative product
I spent a lot of time searching and came up empty handed on the
following query. Is there an equivalent to rowSums that does product or
cumulative product and avoids use of apply or looping? I found a rowProd
in a package but it was a convenience function for apply. As part of a
likelihood calculation called from optim, I?m computing products and
cumulative products of rows of matrices with
2003 Mar 22
1
cumprod doesn't work with data frames (PR#2667)
Full_Name: J. Sisk
Version: 1.6.1
OS: Linux (RedHat 8)
Submission from: (NULL) (67.119.41.66)
Suppose you make a data-frame like so:
xxx <- data.frame(a=10,b=20,c=30,d=40)
Then
cumprod(xxx[1,])
returns
> cumprod(xxx[1,])
a b c d
1 10 20 30 40
The documentation for cumprod says that it should work on "numerical objects",
and this is a data-frame, but it
2011 Nov 27
1
generating a vector of y_t = \sum_{i = 1}^t (alpha^i * x_{t - i + 1})
Dear R-help,
I have been trying really hard to generate the following vector given
the data (x) and parameter (alpha) efficiently.
Let y be the output list, the aim is to produce the the following
vector(y) with at least half the time used by the loop example below.
y[1] = alpha * x[1]
y[2] = alpha^2 * x[1] + alpha * x[2]
y[3] = alpha^3 * x[1] + alpha^2 * x[2] + alpha * x[3]
.....
below are
2012 Feb 03
3
SPATIAL QUESTION: HOW TO MAKE POLYGONS AROUND CLUSTERS OF POINTS AND EXTRACT AREAS AND COORDINATES OF THESE POLYGONS?
Imagine that I have a large number of points (given by coordinates x and y) that vary in density per space. For the purpose of demonstration it could be generated like this: s <- data.frame(x=runif(10000,0,900),y=runif(10000,0,900)); plot(s)
I want to create polygons around the points where point density is greater than a selected threshold (for example, by using krieging or equivalent
2006 Feb 28
2
vector math: calculating a rolling 12 row product?
I have a dataframe of numeric values with 30 ?rows?
and 7 ?columns?.
For each column, beginning at ?row? 12 and down to
?row? 30, I wish to calculate the ?rolling 12 row
product?. I.e., within each column, I wish to
multiply all the values in row 1:12, 2:13,
19:30.
I wish to save the results as a new dataframe, which
will have 19 rows and 7 columns.
2011 Jan 27
1
How do I fix this ?
Just when I think I'm starting to learn ....
Statement z1 works, statement z doesn't. Why doesn't z work and what do I do
to fix it ? Clearly the problem is with the first NA, but I would think it's
handled through the loop vectorization.
y1 <- rnorm(20, 0, .013)
y1
[1] -0.0068630836 -0.0101106230 -0.0169663344 -0.0066314769 0.0075063818
[6] -0.0033548024 0.0015647863
2010 Jul 09
3
apply is slower than for loop?
I thought the "apply" functions are faster than for loops, but my most
recent test shows that apply actually takes a significantly longer than a
for loop. Am I missing something?
It doesn't matter much if I do column wise calculations rather than row wise
## Example of how apply is SLOWER than for loop:
#rm(list=ls())
## DEFINE VARIABLES
mu=0.05 ; sigma=0.20 ; dt=.25 ; T=50 ;
2009 Oct 13
7
lapply() reccursively
Hi all,
I was wondering whether it is possible to use the lapply() function
to alter the value of the input, something in the spirit of :
a1<-runif(100)
a2<-function(i){
a1[i]<-a1[i-1]*a1[i];a1[i]
}
a3<-lapply(2:100,a2)
Something akin to a for() loop, but using the lapply() infrastructure.
I haven't been able to get rapply() to do this.
The reason is that the "real"
2006 Aug 31
2
cumulative growth rates indexed to a common starting point over n series of observations
What is the R way of computing cumulative growth rates given a series of
discrete values indexed .
For instance, given a matrix of 20 observations for each of 5 series (zz),
what is the most straight forward technique in R for computing cumulative
growth (zzcum) ?
It seems for the solution I'm after might be imbedding the following cum
growth rate calc as a function into a function call
2009 Jul 31
1
what meaning missing value True /False needed
This is my code i don't understand the error message:
library(rgenoud)
rm(list=ls())
set.seed(666)
#########################################################
# As a first step, it is assumed that all input parameters are independent of ageingĀ :
#########################################################
InputDim <-20
# Max number of ageings in the inputs
CPIRate <- rep(0.02 , InputDim )
#
2012 May 25
1
Filling NA with cumprod?
Hello,
I need to build certain interpolation logic using R. Unfortunately, I just
started using R, and I'm not familiar with lots of advanced or just
convenient features of the language to make this simpler. So I struggled
for few days and pretty much reduced the whole exercise to the following
problem, which I cannot resolve:
Assume we have a vector of some values with NA:
a <- c(1,
2010 Feb 26
7
question to make a vector without loop
Hello all,
I want to define a vector like w[k+1]=w[k]*a/(b+k) for k=1,...,N-1 without
use loop. Is it posible to do in R?
Regards
khazaei