[R] Matrix in a Reverse order

2010-02-18 Thread Amelia Livington
Dear 'R' friends I have a sort of stupid question to ask. I have a matrix say of the order 4 X 3 as 83    98    90 21    83    84 70    39    56 65    29    38 Is there any command in R which will reverse the order i.e. I need to have same 4 X 3 matrix but as given below 65    29    38 70   

Re: [R] Matrix in a Reverse order

2010-02-18 Thread Benilton Carvalho
x[nrow(x):1,] b On Thu, Feb 18, 2010 at 11:45 AM, Amelia Livington amelia_living...@yahoo.com wrote: Dear 'R' friends I have a sort of stupid question to ask. I have a matrix say of the order 4 X 3 as 83    98    90 21    83    84 70    39    56 65    29    38 Is there any command in

[R] matrix columns

2010-02-01 Thread ogbos okike
Hello. I am working with a set of variables which are in columns. Three of them are of the same length while one has a different length. Typing 'data-matrix(c(ca$value, mo$value,b2$value, y1), ncol = 3)' appears to read any three columns out of the four, though I can say exactly which of these

Re: [R] matrix columns

2010-02-01 Thread Jim Lemon
On 02/01/2010 07:52 PM, ogbos okike wrote: Hello. I am working with a set of variables which are in columns. Three of them are of the same length while one has a different length. Typing 'data-matrix(c(ca$value, mo$value,b2$value, y1), ncol = 3)' appears to read any three columns out of the

[R] matrix to a C function

2010-01-23 Thread Christophe Genolini
Hi the list, Is there a way to give a matrix to a C function, and then to use it as a matrix ? I write a function to print a matrix, but I use it as a vector : 1. void printMatrix(double *mTraj,int *nbCol, int *nbLigne){ 2. int i=0,j=0; 3. for(i=0 ; i *nbLigne ; i++){ 4. for(j=0

Re: [R] matrix to a C function

2010-01-23 Thread Romain Francois
Christophe, That's another question for the R-devel mailing list. A few things however. Short answer : no it is not possible. I don't think x[i,j] is even syntactically valid in C or C++. I'd suggest you to give a go at the .Call interface that lets you manipulate R objects directly. So in

[R] Matrix to list object

2009-12-28 Thread Ron_M
let consider following matrix : mat - matrix(rnorm(45), 15) Now I want to convert it to a list object mat_list, which will have 15 elements and each element will again be a matrix with 3 rows and 3 columns. How can I do that? Thanks, -- View this message in context:

Re: [R] Matrix to list object

2009-12-28 Thread Henrique Dallazuanna
Try this: mat_list - lapply(split(mat, seq(nrow(mat))), matrix, ncol = 3) On Mon, Dec 28, 2009 at 9:20 AM, Ron_M ron_michae...@yahoo.com wrote: let consider following matrix : mat - matrix(rnorm(45), 15) Now I want  to convert it to a list object mat_list, which will have 15 elements and

[R] matrix^(-1/2)

2009-12-04 Thread Greg Dropkin
re [R] matrix^(-1/2) re the discussion in November on this thread. I don't know about expm but the problem must be equivalent to solve(B^(1/2)) and a solution will exist iff B is invertible and has a square root A with A%*%A = B. For 2x2 matrices necessary and sufficient conditions for B to have

[R] matrix data appears corrupted.. appears to be pairs of decimal numbers glommed together

2009-12-03 Thread Stephen Grubb
Hello, We are occasionally getting matrix results that appear to be corrupted... here are the last several rows of an example, copy-pasted out of the R command window. These are supposed to be floating point numbers. [25015,] 1.820848e-01-3.2090e-06i [25016,] 2.178046e-01-4.8140e-06i

Re: [R] matrix data appears corrupted.. appears to be pairs of decimal numbers glommed together

2009-12-03 Thread David Winsemius
On Dec 3, 2009, at 3:02 PM, Stephen Grubb wrote: Hello, We are occasionally getting matrix results that appear to be corrupted... here are the last several rows of an example, copy- pasted out of the R command window. These are supposed to be floating point numbers. [25015,]

Re: [R] matrix^(-1/2)

2009-11-01 Thread David Winsemius
On Oct 31, 2009, at 9:33 PM, David Winsemius wrote: On Oct 31, 2009, at 4:39 PM, Kajan Saied wrote: Dear R-Help Team, as a R novice I have a (maybe for you very simple question), how do I get the following solved in R: Let R be a n x n matrix: \mid R\mid^{-\frac{1}{2}} solve(A) gives

Re: [R] matrix^(-1/2)

2009-11-01 Thread spencerg
A question, a comment, and an alternative answer to matrix^(-1/2): QUESTION: What's the status of the expm package, mentioned in the email you cited from Martin Maechler, dated Apr 5 19:52:09 CEST 2008? I tried both install.packages('expm') and

Re: [R] matrix^(-1/2)

2009-11-01 Thread Charles C. Berry
On Sun, 1 Nov 2009, spencerg wrote: A question, a comment, and an alternative answer to matrix^(-1/2): QUESTION: What's the status of the expm package, mentioned in the email you cited from Martin Maechler, dated Apr 5 19:52:09 CEST 2008? I tried both install.packages('expm') and

Re: [R] matrix^(-1/2)

2009-11-01 Thread spencerg
Hi, Chuck: Thanks very much, but why do I get package 'expm' is not available from install.packages(expm,repos=http://R-Forge.R-project.org;)? Best Wishes, Spencer Graves Charles C. Berry wrote: On Sun, 1 Nov 2009, spencerg wrote: A question, a comment, and an

Re: [R] matrix^(-1/2)

2009-11-01 Thread David Winsemius
On Nov 1, 2009, at 1:46 PM, spencerg wrote: Hi, Chuck: Thanks very much, but why do I get package 'expm' is not available from install.packages(expm,repos=http://R-Forge.R-project.org )? In my case I think it was it is because there is no 2.10 branch to either the:

Re: [R] matrix^(-1/2)

2009-11-01 Thread Charles C. Berry
On Sun, 1 Nov 2009, David Winsemius wrote: On Nov 1, 2009, at 1:46 PM, spencerg wrote: Hi, Chuck: Thanks very much, but why do I get package 'expm' is not available from install.packages(expm,repos=http://R-Forge.R-project.org;)? In my case I think it was it is because there is no

Re: [R] matrix^(-1/2)

2009-11-01 Thread David Winsemius
On Nov 1, 2009, at 3:12 PM, Charles C. Berry wrote: On Sun, 1 Nov 2009, David Winsemius wrote: On Nov 1, 2009, at 1:46 PM, spencerg wrote: Hi, Chuck: Thanks very much, but why do I get package 'expm' is not available from install.packages(expm,repos=http://R-Forge.R-

[R] matrix^(-1/2)

2009-10-31 Thread Kajan Saied
Dear R-Help Team, as a R novice I have a (maybe for you very simple question), how do I get the following solved in R: Let R be a n x n matrix: \mid R\mid^{-\frac{1}{2}} solve(A) gives me the inverse of the matrix R, however not the ^(-1/2) of the matrix... Thank you very much in advance!

Re: [R] matrix^(-1/2)

2009-10-31 Thread David Winsemius
On Oct 31, 2009, at 4:39 PM, Kajan Saied wrote: Dear R-Help Team, as a R novice I have a (maybe for you very simple question), how do I get the following solved in R: Let R be a n x n matrix: \mid R\mid^{-\frac{1}{2}} solve(A) gives me the inverse of the matrix R, however not the

[R] matrix exponential

2009-09-30 Thread Kon Knafelman
Hi Guys, Im trying to find the exponential of a matrix. Can someone please help me do this? Thanks a lot _ View photos of singles in your area Click Here

Re: [R] matrix exponential

2009-09-30 Thread David Winsemius
On Sep 30, 2009, at 9:18 PM, Kon Knafelman wrote: Hi Guys, Im trying to find the exponential of a matrix. Can someone please help me do this? Didn't we just do this one? -- David Winsemius, MD Heritage Laboratories West Hartford, CT __

Re: [R] matrix exponential

2009-09-30 Thread cls59
Kon Knafelman wrote: Hi Guys, Im trying to find the exponential of a matrix. Can someone please help me do this? Thanks a lot There was actually a very recent discussion of this, and related operations. See:

Re: [R] matrix exponential

2009-09-30 Thread spencerg
RSiteSearch('exponential of a matrix') produced 982 matches. RSiteSearch('{exponential of a matrix}') produced 13. David Winsemius wrote: On Sep 30, 2009, at 9:18 PM, Kon Knafelman wrote: Hi Guys, Im trying to find the exponential of a matrix. Can someone please help

Re: [R] matrix exponential

2009-09-30 Thread David Winsemius
On Sep 30, 2009, at 10:14 PM, spencerg wrote: RSiteSearch('exponential of a matrix') produced 982 matches. RSiteSearch('{exponential of a matrix}') produced 13. Yes, I know. David Winsemius wrote: On Sep 30, 2009, at 9:18 PM, Kon Knafelman wrote: Hi Guys, Im trying to

[R] matrix operations on grobs and grid units

2009-09-19 Thread baptiste auguie
Dear list, As a minimal test of a more complex grid layout, I'm trying to find a clean and efficient way to arrange text grobs in a rectangular layout. The labels may be expressions, or text with a fontsize different of the default, which means that the cell sizes should probably be calculated

Re: [R] matrix operations on grobs and grid units

2009-09-19 Thread baptiste auguie
A few amendments might make this improved code more readable, e = expression(alpha,testing very large width, hat(beta), integral(f(x)*dx, a, b)) library(grid) rowMax.units - function(u, nrow){ # rowMax with a fake matrix of units  matrix.indices - matrix(seq_along(u), nrow=nrow)  

Re: [R] Matrix multiplication and random numbers

2009-09-11 Thread RFish
Hi Sorry I don't seem to have explained what I'm trying to do very clearly. The piece of code below multiplies the two matrices together a number of times based on the value in the matmult(InitialPop,1) term in this case one (year), this gives me the end population for the analysis.

Re: [R] Matrix multiplication and random numbers

2009-09-11 Thread Henrique Dallazuanna
If I understand you can use replicate: replicate(10, matmult(InitialPop, 1)) On Fri, Sep 11, 2009 at 1:11 PM, RFish tomworthing...@talk21.com wrote: Hi Sorry I don't seem to have explained what I'm trying to do very clearly. The piece of code below multiplies the two matrices together a

[R] Matrix multiplication and random numbers

2009-09-09 Thread RFish
Dear All I new to using R and am struggling with some matrix multiplication. I have two matrices, one containing random numbers, these are multiplied together to get another matrix which is different each time. When I put in another for loop to repeat this process a multiple times the matrices

Re: [R] Matrix multiplication and random numbers

2009-09-09 Thread jim holtman
I am not sure what you mean by being the same each time. If I make successive calls to the function, I get different results: z [,1] [1,] 0. [2,] 0. [3,] 201.6382 [4,] 0. [5,] 0. [6,] 0. [7,] 0. matmult(InitialPop,1) [,1] [1,] 0.000 [2,]

Re: [R] Matrix multiplication and random numbers

2009-09-09 Thread Chris Stubben
RFish wrote: I new to using R and am struggling with some matrix multiplication. I'm not sure what you're trying to print, but you could place this vector in an expression

Re: [R] Matrix multiplication and random numbers

2009-09-09 Thread RFish
Sorry I probably wasn't clear with my description. The reason i put for loop in was that I want to do the matrix multiplication about 1000 times to get a 1000 different matrices. Therefore I was hoping the for loop would be able to automate this then use write.table to write to an external

[R] Matrix regression

2009-09-07 Thread Corrado
Dear friends, I would like to solve the following regression problem: y=c1 x1 + c2 x2 + + cn xn where the y, xi are all matrices and the ci are constants that need to be determined. The y, xi are distance matrices (symmetric). ci should be forced to positive or null (i.e. non negative).

Re: [R] Matrix as input to xyplot {lattice} - proper extended formula syntax

2009-09-06 Thread Gabor Grothendieck
For the example df below this also works: library(lattice); library(zoo) xyplot(zoo(df[1:4], df$x), type = p) On Sun, Sep 6, 2009 at 12:51 AM, David Winsemiusdwinsem...@comcast.net wrote: I'm not exactly sure what structure df has. Here's my effort to duplicate it: df -

Re: [R] Matrix as input to xyplot {lattice} - proper extended formula syntax

2009-09-06 Thread Deepayan Sarkar
On Sat, Sep 5, 2009 at 10:43 PM, Bryan Hansonhan...@depauw.edu wrote: Thanks David, your way of constructing df is much more compact than what I was using, so I've incorporated it.  I also had my rows and columns transposed relative to how xyplot wanted them (though I had tested for that,

Re: [R] Matrix as input to xyplot {lattice} - proper extended formula syntax

2009-09-06 Thread David Winsemius
On Sep 6, 2009, at 12:51 AM, David Winsemius wrote: I'm not exactly sure what structure df has. Here's my effort to duplicate it: df - data.frame(y=matrix(rnorm(24), nrow=6), x=1:6) df y.1y.2y.3y.4 x 1 0.1734636 0.2348417 -1.2375648 -1.3246439 1 2

[R] Matrix as input to xyplot {lattice} - proper extended formula syntax

2009-09-05 Thread Bryan Hanson
Hello R Folks... I have a list with the following structure: str(df) List of 3 $ y: num [1:4, 1:1242] -0.005379 0.029874 -0.023274 0.000655 -0.004537 .. $ x: num [1:1242] 501 503 505 507 509 ... $ names: Factor w/ 4 levels PC Loading 1,..: 1 2 3 4 I want to plot each row of df$y

Re: [R] Matrix as input to xyplot {lattice} - proper extended formula syntax

2009-09-05 Thread David Winsemius
I'm not exactly sure what structure df has. Here's my effort to duplicate it: df - data.frame(y=matrix(rnorm(24), nrow=6), x=1:6) df y.1y.2y.3y.4 x 1 0.1734636 0.2348417 -1.2375648 -1.3246439 1 2 1.9551669 -1.1027262 -0.7307332 0.3953752 2 3 -0.7645778

Re: [R] Matrix as input to xyplot {lattice} - proper extended formula syntax

2009-09-05 Thread Bryan Hanson
Thanks David, your way of constructing df is much more compact than what I was using, so I've incorporated it. I also had my rows and columns transposed relative to how xyplot wanted them (though I had tested for that, other problems interfered). In my case, I may have varying numbers of y

[R] matrix manipulation problem

2009-09-01 Thread Gregory Gentlemen
Dear fellow R-users, Say we have a matrix x, defined as follows set.seed(50) x - matrix(rbinom(100*5,1, p=0.75),nrow=100, ncol=5) Now the interpretation of x is that each for of x is actually a sequence of length 5, and i would like to transform x in such a way that I can describe the

Re: [R] matrix manipulation problem

2009-09-01 Thread Charles C. Berry
On Tue, 1 Sep 2009, Gregory Gentlemen wrote: Dear fellow R-users, Say we have a matrix x, defined as follows set.seed(50) x - matrix(rbinom(100*5,1, p=0.75),nrow=100, ncol=5) Now the interpretation of x is that each for of x is actually a sequence of length 5, and i would like to transform

[R] Matrix addition function

2009-08-13 Thread Lina Rusyte
Hello,   What function can I use for matrices addition? I couldn’t find any information about it in the manual or in the internet. (A+B suits, when the number of matrixes is small, function sum() doesn’t suit for matrices addition, because it sums all variables in the matrices and produces

Re: [R] Matrix addition function

2009-08-13 Thread Michael Knudsen
On Thu, Aug 13, 2009 at 11:35 AM, Lina Rusyteliner...@yahoo.co.uk wrote: Hi Lina, What function can I use for matrices addition? I couldn’t find any information about it in the manual or in the internet. (A+B suits, when the number of matrixes is small, function sum() doesn’t suit for

Re: [R] Matrix addition function

2009-08-13 Thread Gabor Grothendieck
If A, B and C are matrices then: L - list(A, B, C) Reduce(+, L) On Thu, Aug 13, 2009 at 5:35 AM, Lina Rusyteliner...@yahoo.co.uk wrote: Hello, What function can I use for matrices addition? I couldn’t find any information about it in the manual or in the internet. (A+B suits, when the

Re: [R] Matrix addition function

2009-08-13 Thread Vitalie S.
On Thu, 13 Aug 2009 15:11:03 +0200, Michael Knudsen micknud...@gmail.com wrote: On Thu, Aug 13, 2009 at 11:35 AM, Lina Rusyteliner...@yahoo.co.uk wrote: Hi Lina, What function can I use for matrices addition? I couldn’t find any information about it in the manual or in the internet.

Re: [R] Matrix Integral

2009-08-12 Thread Moshe Olshansky
Hi, Is your matrix K symmetric? If yes, there is an analytical solution. --- On Sat, 1/8/09, nhawrylyshyn nichlas.hawrylys...@gmail.com wrote: From: nhawrylyshyn nichlas.hawrylys...@gmail.com Subject: [R] Matrix Integral To: r-help@r-project.org Received: Saturday, 1 August, 2009, 12:15 AM

Re: [R] matrix power

2009-08-11 Thread Nordlund, Dan (DSHS/RDA)
[mailto:cindy.g...@gmail.com] Sent: Monday, August 10, 2009 7:05 PM To: Nordlund, Dan (DSHS/RDA) Cc: r-help@r-project.org Subject: Re: [R] matrix power Hi, Dan, Yes, this is what I want. Is there better way to solve this? Cindy On Mon, Aug 10, 2009 at 2:52 PM, Nordlund, Dan (DSHS/RDA) nord

[R] matrix power

2009-08-10 Thread cindy Guo
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]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help

Re: [R] matrix power

2009-08-10 Thread Nordlund, Dan (DSHS/RDA)
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of cindy Guo Sent: Monday, August 10, 2009 2:32 PM To: r-help@r-project.org Subject: [R] matrix power Hi, All, If I have a symmetric matrix, how can I get the negative square

Re: [R] matrix power

2009-08-10 Thread Ted Harding
On 10-Aug-09 21:31:30, cindy Guo wrote: 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 X - matrix(c(2,1,1,2),nrow=2) X # [,1] [,2] # [1,]21 # [2,]12 E - eigen(X) V - E$values Q -

Re: [R] matrix power

2009-08-10 Thread cindy Guo
Hi, Ted, Thanks for the sample code. It is exactly what I want. But can I ask another question? The matrix for which I want the negative square root is a covariance matrix. I suppose it should be positive definite, so I can do 1/sqrt(V) as you wrote. But the covariance matrix I got in R using the

[R] Matrix addition and multiplication

2009-08-10 Thread Marlin Keith Cox
I posted this earlier, but am not certain that it was in fact posted, so I will try again. Hi, I have an equation Xcp and would like to look at errors affecting it. I am applying errors of -.58 to .1 to R and -.45 to .47 to Xc. I would like to look at all combinations. I set up a matrix

Re: [R] matrix power

2009-08-10 Thread Ted Harding
On 10-Aug-09 22:36:03, cindy Guo wrote: Hi, Ted, Thanks for the sample code. It is exactly what I want. But can I ask another question? The matrix for which I want the negative square root is a covariance matrix. I suppose it should be positive definite, so I can do 1/sqrt(V) as you wrote.

Re: [R] matrix power

2009-08-10 Thread cindy Guo
Hi, Ted, Now I understand the problem. Thank you for the explanation. It's very helpful. I appreciate it. Cindy On Mon, Aug 10, 2009 at 3:58 PM, Ted Harding ted.hard...@manchester.ac.ukwrote: On 10-Aug-09 22:36:03, cindy Guo wrote: Hi, Ted, Thanks for the sample code. It is exactly what I

Re: [R] matrix power

2009-08-10 Thread Gabor Grothendieck
If its not important which of many solutions you use then the generalized inverse can be used, say. Just use 0 for each small eigenvalue and 1/sqrt(x) for the others. On Mon, Aug 10, 2009 at 6:36 PM, cindy Guocindy.g...@gmail.com wrote: Hi, Ted, Thanks for the sample code. It is exactly what

Re: [R] matrix power

2009-08-10 Thread cindy Guo
Sent: Monday, August 10, 2009 2:32 PM To: r-help@r-project.org Subject: [R] 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 Cindy, Just to be sure we are all on the same page

Re: [R] matrix power

2009-08-10 Thread cindy Guo
I think it may be important, but I am not sure. Actually I am trying to program the adaptive nearest neighbor method proposed by Hastie and Tibshirani. I am following the steps in the book 'The elements of statistical learning' by Hastie, Tibshirani and Friedman, in which the local metric is

[R] Matrix function

2009-08-06 Thread Marlin Keith Cox
Hi, I have an equation Xcp and would like to look at errors affecting it. I am applying errors of -.58 to .1 to R and -.45 to .47 to Xc. I would like to look at all combinations. I set up a matrix function as follows and it does not work. On the last line, when it run, it does not seem like

[R] matrix

2009-08-04 Thread Ismail, Riyad
Hi I have dataset that consists of two columns AB0.102 AC -0.002 BA -0.102 BC 0.270 CA 0.002 CB -0.270 I wish to create a matrix so that I can eventually plot the data. A B C A 1

Re: [R] matrix

2009-08-04 Thread ONKELINX, Thierry
: [R] matrix Hi I have dataset that consists of two columns AB0.102 AC -0.002 BA -0.102 BC 0.270 CA 0.002 CB -0.270 I wish to create a matrix so that I can eventually plot the data. A B C A 1 0.102

Re: [R] matrix

2009-08-04 Thread Henrique Dallazuanna
You can try something about like this: merge(transform(x, V1 = gsub(^[A-Z], , x$V1), V3 = gsub([A-Z]$, , x$V1)), data.frame(V1 = LETTERS[1:3], V3 = LETTERS[1:3], V2 = 1), by = c(V1, V3), all = TRUE) On Tue, Aug 4, 2009 at 8:35 AM,

[R] matrix

2009-08-04 Thread Ismail, Riyad
My apologies, to elaborate I carried out a correlation analysis and I want to plot the data (similar to the graphs available in the corrplot package. However, the results are as follows (I have many more combinations): AB0.102 AC -0.002 BA -0.102 BC

[R] Matrix Integral

2009-07-31 Thread nhawrylyshyn
Hi, Any help on this would be appreciated: I need to integrate where K is a 4x4 matrix, and SIGMA is a 4x4 matrix from say a to b, i.e. 0 to 5: integral MatrixExp(-K * s) %*% SIGMA %*% t(SIGMA) %*% MatrixExp(t(-K) s) ds t is tranpose , %*% : matrix mult , MatrixExp : matrix exponential I've

[R] matrix subsetting assignment with logical mask

2009-07-16 Thread Ross Boylan
If m is a matrix and s is a logical matrix of the same dimensions, I'd like to be able to update m with m[s] - 0 If m2 is another matrix, I'd also like to be able to do m[s] - m2 where elements of m for which s is TRUE get the corresponding element of m2. However, this doesn't work in R 2.7.1.

Re: [R] matrix subsetting assignment with logical mask

2009-07-16 Thread David Winsemius
On Jul 16, 2009, at 6:41 PM, Ross Boylan wrote: If m is a matrix and s is a logical matrix of the same dimensions, I'd like to be able to update m with m[s] - 0 If m2 is another matrix, I'd also like to be able to do m[s] - m2 where elements of m for which s is TRUE get the corresponding

Re: [R] Matrix multiplication precision

2009-07-15 Thread Douglas Bates
On Wed, Jul 15, 2009 at 3:42 AM, Nair, Murlidharan Tmn...@iusb.edu wrote: Hi!! I am trying to multiply 5 matrices and then using the inverse of that matrix for further computation. I read about precision problems from the archives and the suggestion was to use as.numeric while computing the

Re: [R] Matrix multiplication precision

2009-07-15 Thread Steve Lianoglou
Hi Douglas, And the big lesson, of course, is the first rule of numerical linear algebra., Just because a formula is written in terms of the inverse of a matrix doesn't mean that is a good way to calculate the result; in fact, it is almost inevitably the worst way of calculating the result.

Re: [R] Matrix multiplication precision

2009-07-15 Thread roger koenker
A good discussion of this is provided by Gill, Murray and Wright Num Lin Alg and Opt, section 4.7.2. url:www.econ.uiuc.edu/~rogerRoger Koenker emailrkoen...@uiuc.eduDepartment of Economics vox: 217-333-4558University of Illinois fax:

Re: [R] Matrix multiplication precision

2009-07-15 Thread Nair, Murlidharan T
-Original Message- From: dmba...@gmail.com [mailto:dmba...@gmail.com] On Behalf Of Douglas Bates Sent: Wednesday, July 15, 2009 7:29 AM To: Nair, Murlidharan T Cc: r-help@r-project.org Subject: Re: [R] Matrix multiplication precision On Wed, Jul 15, 2009 at 3:42 AM, Nair, Murlidharan Tmn

[R] Matrix multiplication precision

2009-07-14 Thread Nair, Murlidharan T
Hi!! I am trying to multiply 5 matrices and then using the inverse of that matrix for further computation. I read about precision problems from the archives and the suggestion was to use as.numeric while computing the products. I am still having problems with the results. Here is how I am

Re: [R] matrix problem

2009-07-05 Thread William Simpson
Thanks everyone for your help! Bill __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained,

[R] matrix problem

2009-07-04 Thread William Simpson
Can anybody please tell me a good way to do the following? Given a vector, number of rows and number of columns, return a matrix as follows. Easiest to give an example: x=c(1,2), nrow=5, ncol=4 return the matrix: 1 0 0 0 2 1 0 0 0 2 1 0 0 0 2 1 0 0 0 2 Thanks very much for any

Re: [R] matrix problem

2009-07-04 Thread Henrique Dallazuanna
Try this: m - matrix(0, nrow = 5, ncol = 4) diag(m) - x[1] diag(m[-1,]) - x[2] On Sat, Jul 4, 2009 at 12:17 PM, William Simpson william.a.simp...@gmail.com wrote: Can anybody please tell me a good way to do the following? Given a vector, number of rows and number of columns, return a matrix

Re: [R] matrix problem

2009-07-04 Thread David Winsemius
On Jul 4, 2009, at 11:17 AM, William Simpson wrote: Can anybody please tell me a good way to do the following? Given a vector, number of rows and number of columns, return a matrix as follows. Easiest to give an example: x=c(1,2), nrow=5, ncol=4 You ought to separate those assignments with

Re: [R] matrix problem

2009-07-04 Thread William Simpson
Thanks everyone for the help. I should have said that I want to do this generally, not as a one-off. So I want a function to do it. Like this tp-function(x, nr, nc) { matrix( c(x,rep(0, nr-length(x)+1)), nrow=nr, ncol=nc) } tp(x=c(1,2), nr=5, nc=4) This one looks good -- the warning message

Re: [R] matrix problem

2009-07-04 Thread Charles C. Berry
On Sat, 4 Jul 2009, William Simpson wrote: Can anybody please tell me a good way to do the following? Not sure how you want cases like x = 1:3, nrow=2 , ncol=7 to be handled, but for the example you give, this works: mat - matrix(0,nr=nrow,nc=ncol) indx - outer( seq(

Re: [R] matrix problem

2009-07-04 Thread Jorge Ivan Velez
Dear William, Here is one way using Henrique's solution: Make - function(x, nR, nC){ m - matrix(0, nrow = nR, ncol = nC) diag(m) - x[1] diag(m[-1,]) - x[2] m } Make(x = c(1,2), nR = 5, nC = 4) HTH, Jorge On Sat, Jul 4, 2009 at 11:59 AM, William Simpson

Re: [R] matrix problem

2009-07-04 Thread David Winsemius
On Jul 4, 2009, at 11:59 AM, William Simpson wrote: Thanks everyone for the help. I should have said that I want to do this generally, not as a one-off. So I want a function to do it. Like this tp-function(x, nr, nc) { matrix( c(x,rep(0, nr-length(x)+1)), nrow=nr, ncol=nc) } tp(x=c(1,2),

Re: [R] matrix problem

2009-07-04 Thread William Simpson
Doesn't work: Make(x=c(2,1,1,1),nR=5,nC=2) [,1] [,2] [1,]20 [2,]12 [3,]01 [4,]00 [5,]00 should be [,1] [,2] [1,]20 [2,]12 [3,]11 [4,]11 [5,]01 On Sat, Jul 4, 2009 at 5:04 PM, Jorge Ivan

Re: [R] matrix problem

2009-07-04 Thread Henrique Dallazuanna
Try this: foo - function(x, nrow, ncol){ m - matrix(0, nrow = nrow, ncol = ncol) m[cbind(unlist(lapply(0:(ncol - 1), `+`, seq(x))),rep(1:ncol, each = length(x)))] - x m } foo(c(2, 1, 1, 1), nrow = 5, ncol = 2) On Sat, Jul 4, 2009 at 1:26 PM, William Simpson

Re: [R] Matrix inversion-different answers from LAPACK and LINPACK

2009-06-18 Thread Avraham . Adler
, r-help@r-project.org Subject RE: [R] Matrix inversion-different answers from LAPACK and LINPACK

Re: [R] Matrix inversion-different answers from LAPACK and LINPACK

2009-06-18 Thread Ravi Varadhan
- Original Message - From: avraham.ad...@guycarp.com Date: Thursday, June 18, 2009 10:54 am Subject: RE: [R] Matrix inversion-different answers from LAPACK and LINPACK To: Ravi Varadhan rvarad...@jhmi.edu Cc: r-help@r-project.org Thank you. One question, though. In the case where I have closed

[R] Matrix inversion-different answers from LAPACK and LINPACK

2009-06-17 Thread Avraham . Adler
Hello. I am trying to invert a matrix, and I am finding that I can get different answers depending on whether I set LAPACK true or false using qr. I had understood that LAPACK is, in general more robust and faster than LINPACK, so I am confused as to why I am getting what seems to be invalid

Re: [R] Matrix inversion-different answers from LAPACK and LINPACK

2009-06-17 Thread Ravi Varadhan
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of avraham.ad...@guycarp.com Sent: Wednesday, June 17, 2009 11:38 AM To: r-help@r-project.org Subject: [R] Matrix inversion

Re: [R] Matrix inversion-different answers from LAPACK and LINPACK

2009-06-17 Thread Ravi Varadhan
: Wednesday, June 17, 2009 11:38 AM To: r-help@r-project.org Subject: [R] Matrix inversion-different answers from LAPACK and LINPACK Hello. I am trying to invert a matrix, and I am finding that I can get different answers depending on whether I set LAPACK true or false using qr. I had understood

Re: [R] Matrix inversion-different answers from LAPACK and LINPACK

2009-06-17 Thread Avraham . Adler
cc Subject RE: [R] Matrix inversion-different

Re: [R] Matrix inversion-different answers from LAPACK and LINPACK

2009-06-17 Thread Ravi Varadhan
-Original Message- From: avraham.ad...@guycarp.com [mailto:avraham.ad...@guycarp.com] Sent: Wednesday, June 17, 2009 1:10 PM To: Ravi Varadhan Cc: r-help@r-project.org Subject: RE: [R] Matrix

Re: [R] Matrix inversion-different answers from LAPACK and LINPACK

2009-06-17 Thread Avraham . Adler
Subject RE: [R] Matrix inversion-different answers from LAPACK and LINPACK

Re: [R] Matrix inversion-different answers from LAPACK and LINPACK

2009-06-17 Thread Albyn Jones
As you seem to be aware, the matrix is poorly conditioned: kappa(PLLH,exact=TRUE) [1] 115868900869 It might be worth your while to think about reparametrizing. albyn On Wed, Jun 17, 2009 at 11:37:48AM -0400, avraham.ad...@guycarp.com wrote: Hello. I am trying to invert a matrix, and I

Re: [R] Matrix inversion-different answers from LAPACK and LINPACK

2009-06-17 Thread Douglas Bates
On Wed, Jun 17, 2009 at 2:02 PM, Albyn Jonesjo...@reed.edu wrote: As you seem to be aware, the matrix is poorly conditioned: kappa(PLLH,exact=TRUE) [1] 115868900869 It might be worth your while to think about reparametrizing. Also, if it is to be a variance-covariance matrix then it must be

Re: [R] Matrix inversion-different answers from LAPACK and LINPACK

2009-06-17 Thread Avraham . Adler
cc avraham.ad...@guycarp.com, r-help@r-project.org 06/17/2009 05:55 Subject PMRe: [R] Matrix

Re: [R] Matrix inversion-different answers from LAPACK and LINPACK

2009-06-17 Thread Ravi Varadhan
-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of avraham.ad...@guycarp.com Sent: Wednesday, June 17, 2009 6:11 PM To: Douglas Bates Cc: dmba...@gmail.com; r-help@r-project.org Subject: Re: [R] Matrix inversion-different answers from LAPACK and LINPACK I will be the first one to admit I

Re: [R] Matrix inversion-different answers from LAPACK and LINPACK

2009-06-17 Thread Ravi Varadhan
-project.org] On Behalf Of avraham.ad...@guycarp.com Sent: Wednesday, June 17, 2009 6:11 PM To: Douglas Bates Cc: dmba...@gmail.com; r-help@r-project.org Subject: Re: [R] Matrix inversion-different answers from LAPACK and LINPACK I will be the first one to admit I may be doing something stupid

[R] Matrix manipulation

2009-06-11 Thread Payam Minoofar
Hello everyone, I have a couple of fairly simple questions (I hope) the answers to which I cannot find through the documentation at the moment. 1. I would like to delete the a row from a matrix if a certain elimination criterion is met. I am familiar with x - x[-7,] (to remove row 7, for

Re: [R] Matrix manipulation

2009-06-11 Thread Henrique Dallazuanna
Try this: For the first and the second question: transform(subset(d, row.names(d) != 2), row.names=NULL) On Thu, Jun 11, 2009 at 3:53 PM, Payam Minoofar payam.minoo...@meissner.com wrote: Hello everyone, I have a couple of fairly simple questions (I hope) the answers to which I cannot

Re: [R] Matrix manipulation

2009-06-11 Thread David Winsemius
On Jun 11, 2009, at 2:53 PM, Payam Minoofar wrote: Hello everyone, I have a couple of fairly simple questions (I hope) the answers to which I cannot find through the documentation at the moment. 1. I would like to delete the a row from a matrix if a certain elimination criterion is

Re: [R] Matrix manipulation

2009-06-11 Thread William Dunlap
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of David Winsemius Sent: Thursday, June 11, 2009 1:49 PM To: Payam Minoofar Cc: r-help@r-project.org Subject: Re: [R] Matrix manipulation On Jun 11, 2009, at 2:53 PM, Payam

Re: [R] Matrix manipulation

2009-06-11 Thread Gabor Grothendieck
Or perhaps: M10[rowSums(M10 == 63) == 0, ] On Thu, Jun 11, 2009 at 4:49 PM, David Winsemiusdwinsem...@comcast.net wrote: On Jun 11, 2009, at 2:53 PM, Payam Minoofar wrote: Hello everyone, I have a couple of fairly simple questions (I hope) the answers to which I cannot find through the

[R] matrix to vector

2009-05-29 Thread Ian Coe
Hi, Is there a way to convert a matrix into a vector representing all permutations of values and column/row headings with native R functions? I did this with 2 nested for loops and it took about 25 minutes to run on a ~700x700 matrix. I'm assuming there must be a smarter way to do this with

<    2   3   4   5   6   7   8   9   10   >