similar to: product of successive rows

Displaying 20 results from an estimated 11000 matches similar to: "product of successive rows"

2008 Aug 12
7
ignoring zeros or converting to NA
Hi everyone, I have a matrix that has a combination of zeros and NAs. When I perform certain calculations on the matrix, the zeros generate "Inf" values. Is there a way to either convert the zeros in the matrix to NAs, or only perform the calculations if not zero (i.e. like using something similar to an !all(is.na() construct)? Thanks, rcoder -- View this message in context:
2008 Aug 13
2
missing TRUE/FALSE error in conditional construct
Hi everyone, I posted something similar to this in reply to another post, but there seems to be a problem getting it onto the board, so I'm starting a new post. I am trying to use conditional formatting to select non-zero and non-NaN values from a matrix and pass them into another matrix. The problem is that I keep encountering an error message indicating the ":missing value where
2008 Aug 13
3
conditional IF with AND
Hi everyone, I'm trying to create an "if" conditional statement with two conditions, whereby the statement is true when condition 1 AND condition 2 are met: code structure: if ?AND? (a[x,y] <condition1>, a[x,y] <condition2>) I've trawled through the help files, but I cannot find an example of the syntax for incorporating an AND in a conditional IF statement.
2008 Aug 13
2
merging data sets to match data to date
Hi everyone, I want to extract data from a data set according to dates specified in a vector. I have created a blank matrix with row names (dates) that I want to extract from the full data set. I have then performed a merge to try to o/p rows corresponding to common dates to a results matrix, but the operation did not fill the results matrix. Coulc anyone offer any advice to assist with this
2008 Jul 29
1
rolling regression between adjacent columns
Hi everyone, I am trying to apply linear regression to adjacent columns in a matrix (i.e. col1~col2; col3~col4; etc.). The columns in my matrix come with identifiers at the top of each column, but when I try to use these identifiers to reference the columns in the regression function using rollapply(), the columns are not recognised and the regression breaks down. Is there a more robust way to
2008 Jul 31
1
rollapply() to portions of a matrix
Hi everyone, I have a rollapply statement that applies a function, in steps, over a data matrix as follows: #Code start testm<-rollapply(mat, 100, by=100, min, na.rm=F) #Code end This moves down matrix 'mat' and calculates the minimum value over a 100 row range, every 100 rows (i.e. no overlaps). NAs are not removed. I want to modify this statement somehow so that the rollapply()
2012 Mar 17
3
rtriang using ifelse statement
Hi All, I want to draw samples (n=4) from one of 2 triangular distributions for each value in a matrix. I am using an ifelse statement to try to define which distribution to draw from. >From the output, I can see that the ifelse statement is choosing the correct distribution, however, my n=4 simulations aren't occurring. Is there a way to adjust the ifelse statement to fix this, or must
2008 Jul 09
2
shifting data in matrix by n rows
Hi everyone, I have some data in a matrix, and I want to shift it down by one row. The matrix in question has a date column. Does anyone know of a way to shift the data by one row, whilst preserving the date column in the matrix - i.e. shift the data and leave the date column in the current location? Thanks, rcoder -- View this message in context:
2006 Aug 16
5
How to remove similar successive objects from a vector?
Is there some (much) more efficient way to do this? VECTOR=c(3,2,4,5,5,3,3,5,1,6,6); NEWVECTOR=VECTOR[1]; for(i in 1:(length(VECTOR)-1)) { if((identical(VECTOR[i], VECTOR[i+1]))==FALSE){ NEWVECTOR=c(NEWVECTOR,VECTOR[i+1])} } > VECTOR [1] 3 2 4 5 5 3 3 5 1 6 6 > NEWVECTOR [1] 3 2 4 5 3 5 1 6 _______________________________ Atte Tenkanen University of Turku, Finland
2008 May 08
2
speeding up a special product of three arrays
I am struggling with R code optimization, a recurrent topic on this list. I have three arrays, say A, B and C, all having the same number of columns. I need to compute an array D whose generic element is D[i, j, k] <- sum_n A[i, n]*B[j, n]*C[k, n] Cycling over the three indices and subsetting the columns won't do. Is there any way to implement this efficiently in R or should I resign to
2006 Aug 22
4
Successive subsets from a vector?
I'd like to pick every imbricated five character long subsets from a vector. I guess there is some efficient way to do this without loops... Here is a for-loop-version and a model for output: VECTOR=c(1,4,2,6,5,0,11,10,4,3,6,8,6); ADDRESSES=c(); for(i in 1:(length(VECTOR)-4)){ ADDRESSES[i]=paste(VECTOR[i:(i+4)],collapse="") } > ADDRESSES [1] "14265"
2006 Jun 16
1
Assignemt problem ,,,,,,,,,,,,,,,
  Hello list, i have a very simple question about matrix assignment. i did like this. res<-1:30 dim(res)<-c(5,6) ind<-1:6 now i want to assign the value of this variable ind to first coloumn in matrix res. like res[,1]<-ind but this code is giving error , Actualy i have a for loop and value of ind variable is changing every time ,,total 6 times,,i want to assign every vlaue
2005 Nov 23
2
vector of permutated products
Given an x-vector with, say, 3 elements, I would like to compute the following vector of permutated products (1-x1)*(1-x2)*(1-x3) (1-x1)*(1-x2)*x3 (1-x1)*x2*(1-x3) x1*(1-x2)*(1-x3) (1-x1)*x2*x3 x1*(1-x2)*x3 x1*x2*(1-x3) x1*x2*x3 Now, I already have the correctly sorted matrix of permutations! So, the input looks something like: #input x<-c(0.3,0.1,0.2) Nx<-length(x) Ncomb<-2^Nx
2009 Aug 10
2
matrix power
Hi, All, If I have a symmetric matrix, how can I get the negative square root of the matrx, ie. X^(-1/2) ? Thanks, Cindy [[alternative HTML version deleted]]
2008 Aug 15
2
cor() btwn columns in two matrices - no complete element pairs
Hi everyone, I'm trying to calculate correlation coefficients between corresponding columns in two matrices with identical dimensions but different data. The problem is that the matrices contain NAs in different locations. I am using the following code to try to calculate correlations between complete sets of data: #Code start maxcol<-ncol(mat1) for (i in 1:maxcol) {
2008 Aug 08
1
increment size in for loop
Hi everyone, Is there a way to vary the increment size in a for loop? For e.g. when incrementing in steps greater than unity. Thanks, rcoder -- View this message in context: http://www.nabble.com/increment-size-in-for-loop-tp18893893p18893893.html Sent from the R help mailing list archive at Nabble.com.
2008 Jul 29
1
correlation between matrices - both with some NAs
Hi everyone, I'm having trouble applying the Cor() function to two matrices, both of which contain NAs. I am doing the following: a<-cor(m1, m2, use="complete.obs") ... and I get the following error message: Error in cor(m1, m2, use = "complete.obs") : no complete element pairs Does anyone know how I can apply a correlation, ignoring any NAs? Thanks, rcoder --
2008 Aug 02
1
problem with nested loop for regression
Hi everyone, I'm experiencing difficulty getting the results I want when I use a nested for loop. I have a data set to which I perform some calculations, and then try to apply a regression over a rolling window. The code runs, but the regression results I am getting (intercept and slope) are simply the same, repeated again and again in the results matrix. The regression does not seem to be
2008 Aug 07
1
long run time for loop operation & matrix fill
Hi everyone, I'm running some code containing an outer and inner loop, to fill cells in a 2500x1500 results matrix. I left my program running overnight, and it was still running when I checked 17 hours later. I have tested the operation on a smaller matrix and it executes fine, so I believe there is nothing wrong with the code. I was just wondering if this is normal program execution speed
2011 Mar 18
1
points() rendering points outside of input
As a followup to pi-day, I attempted to make a .gif of a simulation based estimation of pi by plotting points inside a single quadrant of a circle (a la?http://www.drewconway.com/zia/?p=2667 ). ?When rendering the individual x,y pairs with points() I intermittently see points crop up around (2,0.5) but the input values for x and y are bounded between 0 and 1. square<-structure(c(0, 0, 1, 1, 0,