similar to: how to speed up this for loop?

Displaying 20 results from an estimated 400 matches similar to: "how to speed up this for loop?"

2008 Jul 09
2
rollmean()
Hello, I am trying to calculate a 31 day running mean in some temperature data along ROWS. Rollmean() works great along columns, but how do I perform this same action on my rows? The data is a matrix of 365 columns (days of the year) by 5,000 rows (lat/long coordinates). I would like to perform a 31 day running mean along the 365 days. I am new to R so any help would be greatly appreciated!
2008 Jul 15
2
Row Sum, exclude positive values
Hello, I'd like to sum the values of a row from the first negative number (FN) to the last negative number (LN), but not add any positive values to the sum. Then apply this to each row of the data frame. For example if I have a dataframe with Row 1 values DF = (4, 3, 2, 1, 0, -1, -2, -3, -2, 2, 1, -1, -2, -3, -2, -1, 1, 2) I would like to sum the numbers from column 6 to column 16, but not
2006 Jul 20
3
How do I modify an exported function in a locked environment?
Running R.app on Mac OS X 10.4 > version _ platform powerpc-apple-darwin8.6.0 arch powerpc os darwin8.6.0 system powerpc, darwin8.6.0 status major 2 minor 3.1 year 2006
2006 Jul 20
3
How do I modify an exported function in a locked environment?
Running R.app on Mac OS X 10.4 > version _ platform powerpc-apple-darwin8.6.0 arch powerpc os darwin8.6.0 system powerpc, darwin8.6.0 status major 2 minor 3.1 year 2006
2007 Jul 19
5
need help getting a word right
Hey all, I see examples showing up that look like this: describe Thing do before(:each) do @thing = Thing.new end it do @thing.should be_something end end This will produce output like this: Thing - should be something But "it do" is driving me mad :( We need a better word. Of course, ''specify'' has not been completely removed, so you can still do
2008 Jul 11
1
While loop
Hello, I am trying to loop through a matrix column and find the first value <=0 and store that matrix location in a variable called Start. I have tried the following: i <- 1 j <- 1 while (Matrix[i, j] > 0) i = (i + 1) #loop until matrix [i, j] value <= 0 #strore that row number in a variable Start <- i I am getting a scripting out of bounds error and I suspect maybe the loop
2008 Mar 14
2
Incremental file updates over a network, NFS?
Hi list, can anyone point me at some consise info on when rsync is capable of performing incremental updates of binary files? I need to rsync over a network, and currently I have this over an NFS share but I suppose that even if binary updates are possible there not going to do much good as reading the remote file over NFS to check what needs to be updated will use the same bandwidth as copying
2008 Jan 07
5
moving or running average
Hi all R users, Can anyone please let me know how to do the moving average with R? With regards, Abu _________________________________________________________________ Free games, great prizes - get gaming at Gamesbox.
2008 Feb 13
4
rolling sum (like in Rmetrics package)
Hello, I'm new to R and would like to know how to create a vector of "rolling sums". (I have seen the Rmetrics package and the rollMean function and I would like to do the same thing except Sum instead of Mean.) I imagine someone has done this, I just can't find it anywhere. Example: x <- somevector #where x is 'n' entries long #what I would like to do is: x1
2010 Jan 02
1
Question on Reduce + rollmean
Hello useRs, I'd like to perform a moving average on the dataset, xx. I've tried combining the functions Reduce and rollmean but it didn't work. > r <- function(n) rollmean(n, 2) # where 2 = averaging interval > output < - Reduce("r", x) Error in f(init, x[[i]]) : unused argument(s) (x[[i]]) Is there anything wrong with the code in the first place? where
2012 Mar 03
4
Sliding a Window in R
Dear all, I am having a vector of around 300.000 elements and I Want to slide fast a window from the first element until the last-Windowsize what I have so far is the following for statement:  for (i in 1:(length(data[,1]) - windowSize)) {         out[i] <- mean(data[i:(i + windowSize - 1), ])         elements[i]<-length(i:(i + windowSize - 1))       } but this of course takes ages to
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
2009 Dec 10
1
Moving Averages in ggplot2
Hello all, Have some time series data stored in a data.frame, and am plotting it with ggplot2 (which is totally awesome). I have explored the documentation and mailing list archives, and I can't see any way to plot a 'smoother' that is just the K-step moving average. For example, imagine I had a data.frame called 'sleep' with 'date' as the date (from as.Date()) and
2010 Jul 17
5
Help with a problem
Hello R users, I am a researcher at the University of Michigan looking for a solution to an R problem. I have loaded my data in from a mysql database and it looks like this > data ds c1 c2 1 2010-04-03 100 0 2 2010-04-30 11141 15 3 2010-05-01 3 16 4 2010-05-02 7615 14 5 2010-05-03 6910 17 6 2010-05-04
2010 Aug 20
3
rollmean help (or similar function)
I am working on a simple pilot project comparing the capability of SQL, SAS and R to perform a rolling mean per the following instructions. I have completed the SQL and SAS analysis, so now it's R's turn. Calculate mean values of x (x=count) for each date in the dataset where mean = the average count of days [t-9] through day [t-3] for each date/illness combination. Dataset aggpilot
2008 Jul 14
2
long data frame selection error
Hello, I am trying to select the following headers from a data frame but when I try and run the command it executes halfway through and give me an error at V188 and V359. Temp <- data.frame(V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15, V16, V17, V18, V19, V20, V21, V22, V23, V24, V25, V26, V27, V28, V29, V30, V31, V32, V33, V34, V35, V36, V37, V38, V39, V40, V41, V42, V43, V44, V45,
2002 Nov 11
2
R 1.6.1: help with debugging error in RunGenCollect(), R_gc_internal
Hi, [System info: R 1.6.1 compiled from source (no args to configure) on Redhat 7.1 Linux i/386] I have some spatial statistics programs that recently (since R 1.6.1) have generated SIGSEGV. These R programs use the splancs library as well as some C code of my own for Voronoi analysis. The program has a big loop to fit various model parameters against a spatial distribution of biological
2010 Jan 04
3
Extract vector elements until cumsum <= x
Hi All, I have a vector n, and for each n[i] I want to extract n[i], n[i+1], n[i+2]..., until the cumulative sum of n[i] and subsequent elements exceeds a CheckValue, whereupon I move to the next index and repeat. I am trying to find a Vectorized approach, and have seen similar posts where filter{stat} and rollmean{zoo} were suggested, but, I haven't been able to figure a way to use them
2011 Jun 25
1
Moving average in a data table
Hi, I'm trying to figure out common approach on calculating MA on a dataset that contains column "time". After digging around, I believe functions rollmean and rollaply should be used. However I don't quite understand the requirements for the underlying data. Should it be zoo object type? Formatted in a special way? As an example, I'm looking to get calculated
2008 Jul 22
1
rollmean and stl
I need to investigate how rollmean and the trend returned from stl differ. I am trying to find out exactly what the trend part of stl is (I have just started coding in R and do not know fortran). I need to extract this because it will be used in further calculations, and it needs to be verified to make sure that I am using the right process. I would like to use this to remove the seasonal