[R] display matrix on graphics device

2008-12-09 Thread murali . menon
Folks, Is there a way to print a matrix in tabular form onto the graphics device? I want to create a display consisting of graphs and tables, so that I can do something like: windows() opar = par(mfrow = c(3, 2)) library(plotrix) library(PerformanceAnalytics) radial.plot(...) radial.plot(...)

[R] matrix indexing and update

2008-11-05 Thread murali . menon
Folks, I have a matrix: set.seed(123) a <- matrix(rnorm(100), 10) And a vector: b <- rnorm(10) Now, I want to switch the signs of those rows of a corresponding to indices in b whose values exceed the 75 %-ile of b which(b > quantile(b)[4]) [1] 2 6 10 so I want, in effect: a[2, ] <- -a[2,

[R] price returns conversion

2008-08-06 Thread Murali Menon
folks, is there a better way to convert a daily series of price returns to a monthly one than as follows: library(xts) a <- xts(rnorm(100) / 100, order.by = as.Date(1:100)) am <- diff(to.monthly(cumsum(a))[, 4]) # [, 4] for Close levels the problem with this is that the entire first month of

Re: [R] multiplication question

2008-07-03 Thread Murali Menon
iplication questionCC: [EMAIL PROTECTED] example ...x <- 1:5 ; y<- 6:8(m <- x %o% y) # is this what you mean by product of two vectors?sum(m[row(m)!=col(m)]) # or ...sum(m)-sum(diag(m)) On Wed, Jul 2, 2008 at 7:30 PM, Murali Menon <[EMAIL PROTECTED]> wrote: folks,is there a clev

[R] multiplication question

2008-07-02 Thread Murali Menon
folks, is there a clever way to compute the sum of the product of two vectors such that the common indices are not multiplied together? i.e. if i have vectors X, Y, how can i compute Sum (X[i] * Y[j]) i != j where i != j also, what if i wanted Sum (X[i] * Y[j] * R[i, j]) i != j w

[R] manipulation of list of matrices

2007-12-07 Thread murali . menon
Folks, I have a list of correlation matrices of equities, say, and I need to manipulate each matrix: I weight each equity by its median absolute correlation against all the other equities, such that the equity with the least such correlation gets the highest weight. Something like min(over all

[R] Row-by-row regression on matrix

2007-09-19 Thread murali . menon
Folks, I have a 3000 x 4 matrix (y), which I need to regress row-by-row against a 4-vector (x) to create a matrix lm.y of intercepts and slopes. To illustrate: y <- matrix(rnorm(12000), ncol = 4) x <- c(1/12, 3/12, 6/12, 1) system.time(lm.y <- t(apply(y, 1, function(z) lm(z ~ x)$coefficient)))