similar to: cumprod doesn't work with data frames (PR#2667)

Displaying 20 results from an estimated 5000 matches similar to: "cumprod doesn't work with data frames (PR#2667)"

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,
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
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
2009 Sep 16
2
Generalized cumsum?
Is there anything like cumsum and cumprod but which allows you to apply an arbitrary function instead of sum and product? In other words, I want a function cumfunc(x, f) that returns a vector, so that for all n up to the length of x cumapply(x,f)[n] = f(x[1:n]) This would give cumsum and cumprod as special cases when f=sum or f=prod. I could write such a function, but I can't see
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
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 ) #
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 ;
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
2003 Apr 29
1
Shafer's MIX: Query on code
Thanks to Fernando Tusell and especially to Brian Ripley for their work on 'mix', leading to an apparently good package mow available on CRAN. Going through the R code for the function prelim.mix, I am wondering why the following method of calculation is used at one point: umd <- as.integer(round(exp(cumsum(log(d))))) (d is a vector containing, in effect, the numbers of levels of
2009 Oct 29
2
fast cumulative matrix multiplication
Hi all, I am looking for a function like cumprod() that works for matrix multiplication. In other words, I have matrices [M1, M2, ..., Mn], and I want to calculate [M1, M1%*%M2, M1%*%M2%*%M3, ..., M1%*%...%*%Mn] as quickly as possible. Right now I'm using a for() loop but it seems like there should be a faster way. Any help is appreciated! Thanks, Todd Schneider todd.w.schneider@gmail.com
2013 Jul 31
1
[Announcement] Linux Plumbers ACPI/PM, PCI Microconference
On Wednesday, July 31, 2013 10:35:05 AM Shuah Khan wrote: > On Wed, Jul 31, 2013 at 5:40 AM, Rafael J. Wysocki <rjw at sisk.pl> wrote: > > Hi All, > > > > The original announcement didn't go to linux-pm, so again: > > > > On Tuesday, July 16, 2013 08:21:26 PM Myron Stowe wrote: > >> Linux Plumbers has approved an ACPI/PM, PCI microconference. The
2013 Jul 31
1
[Announcement] Linux Plumbers ACPI/PM, PCI Microconference
On Wednesday, July 31, 2013 10:35:05 AM Shuah Khan wrote: > On Wed, Jul 31, 2013 at 5:40 AM, Rafael J. Wysocki <rjw at sisk.pl> wrote: > > Hi All, > > > > The original announcement didn't go to linux-pm, so again: > > > > On Tuesday, July 16, 2013 08:21:26 PM Myron Stowe wrote: > >> Linux Plumbers has approved an ACPI/PM, PCI microconference. The
2010 Dec 19
2
Replacing the for loop for time series buid-up
Hi, is there a function that replaces the following code? n=200 boot.x[1]=odhad+boot.res[1] #(boot.x[0]=1) for (j in 1:(n-1)) { boot.x[j+1]=odhad*boot.x[j]+boot.res[j+1] } This is nested in two other loops, and I am looking for some way to improve code performance I tried sapply and cumprod but no success. Thanks Jan -- View this message in context:
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
2012 Apr 01
1
Possibly more coefficients?
Hi there, I have this code: Prepared_Data <- na.omit(read.csv("Prepared_Data.csv", header=TRUE)) pd <- Prepared_Data[,-3] ## data minus response variable lev <- sapply(pd,function(x) length(unique(x))) ## total parameters for n variables par(las=1,bty="l") plot(cumprod(lev),log="y") library(Matrix) m <- sparse.model.matrix(~.^2,data=pd) ncol(m)
2010 May 05
1
testInstalledBasic question
Hi, I'm currently in the process of writing an R-installation SOP for my company. As part of that process I'm using the recommendations from the 'R Installation and Administration' document, section 3.2, "Testing an installation". This is done on an XP machine, using the latest binary of 2.11.0. The binary is downloaded and then installed from the installer. I then
2010 Mar 01
1
function odiag(): assigning values to off-diagonal
hi I'm trying to use the function odiag(x) for matrix calculations. I would like to assign new values to an off-diagonal in a matrix. When I use the diag (x) function I could write something like p<-matrix(seq(1:12),ncol=4) p.new<-matrix(rep(0,12),ncol=4) diag(p.new)<-diag(p) p.new But this won't work with odiag. How can I turn odiag (x) into something like diag (x) in order
2012 Jul 27
1
C code validation
Dear R-devel, I'm trying to validate the results from a C function, against a (trial and tested) older R function. For reasons unknown to me, the C function seems to give different result sometimes at each trial, even with the very same data. These are the relevant outputs from R: > library(QCA) Loading required package: lpSolve > benchmark <- function(x, y) { + index <- 0
2012 Dec 17
2
Suggestion: 'method' slot for format.ftable()
Dear R-developers, I would like to suggest a 'method' slot for format.ftable() (see an adjusted 'format.ftable()' below, taken from the source of R-2.15.2). At the moment, format.ftable() contains several empty cells due to the way the row and column labels are printed. This creates problems (= unwanted empty columns/rows) when converting an ftable to a LaTeX table; see an
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.