[R] Matrix

2009-02-02 Thread Shruthi Jayaram
Hi, I have a very basic question on merging two matrices by alternating the rows. For illustration, assume two matrices - A looks like: 10 10 10 10 B looks like: 20 20 20 20 How do I combine them such that I get alternating rows from A and B? My final result should be C which looks like: 1

[R] matrix

2008-06-17 Thread Paul Adams
Hello everyone,I am having a difficult time understanding what commands are used to add and remove elements froma matrix or data frame.For ex ample if I want to remove element=[1,50] or elements [1,50:63] or elements  [2:4,20:35]from a matrix and replace with NA or any number what command must I

[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 0.102

[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 barplot

2008-07-25 Thread Andreas Tille
Hi, as a bloody R beginner I failed to solve the probably simple problem to create a barplot of the following data read from a file Year A BC 2000 4 30 2001 2 13 2002 1 25 The Barplot should look like 5 |

[R] Matrix multiplication

2008-08-06 Thread Zhang Yanwei - Princeton-MRAm
Hi all, Is there an easy way to do cumulative matrix multipliation in R? What's the syntex? Thanks. Sincerely, Yanwei Zhang Department of Actuarial Research and Modeling Munich Re America Tel: 609-275-2176 Email: [EMAIL PROTECTED] [[alternative HTML version

[R] matrix question

2008-08-19 Thread Altaweel, Mark R.
Hi, I have a vector and a list, with data I would like to multiply together. So for instance I have a vector s: [[1]] [1] 44308 [[2]] [1] 4371 Also, I have a list d: [[1]] [1] 1201 6170 2036 2927 1625 1391 2074 1453 3172 3027 4691 3719 1185 320 2071 1027 1046 1186 1403 580 1382 4408

[R] matrix graph

2007-12-11 Thread threshold
Hi All, simple question: do you know how to graph the following object/matrix in a 'surface manner': [,1] [,2] [,3][,4] [,5][,6] [1,] -0.154 -0.065 0.129 0.637 0.780 0.221 [2,] 0.236 0.580 0.448 0.729 0.859 0.475 [3,] 0.401 0.506 0.310 0.650 0.822 0.448 [4,] 0.54

[R] Matrix Inversion

2007-12-12 Thread Wang Chengbin
I got the following error: a = read.csv("mat.csv") b = as.matrix(a) tb = t(b) bb = tb %*% b dim(bb) ibb = solve(bb) bb %*% ibb > ibb = solve(bb) Error in solve.default(bb) : system is computationally singular: reciprocal condition number = 1.77573e-19 > Are there any ways to find more informati

[R] matrix creation

2008-01-28 Thread Michelle DePrenger-Levin
Hello, I am trying to create multiple matrices (to run a PVA) but can't import all of them from a .csv without the numbers treated as labels and not factors. I can enter the matrix slowly: Site05_96 <- matrix(c(0.07,0,0.03,0.00,NA,0.00, 0.09,0.16667,0.31,0.42,NA,0.00, 0.00,0,0.00,0.0

Re: [R] Matrix

2009-02-02 Thread Gabor Grothendieck
Try this: matrix(rbind(x, y), nc = 2, byrow = TRUE) On Mon, Feb 2, 2009 at 10:52 AM, Shruthi Jayaram wrote: > > Hi, > > I have a very basic question on merging two matrices by alternating the > rows. For illustration, assume two matrices - > > A looks like: > > 10 10 > 10 10 > > B looks like: >

Re: [R] Matrix

2009-02-02 Thread Gabor Grothendieck
Sorry, there was an error. Try this: x <- matrix(1:4, 2) y <- 10 * x matrix(t(cbind(x, y)), nc = 2, byrow = TRUE) On Mon, Feb 2, 2009 at 12:32 PM, Gabor Grothendieck wrote: > Try this: > > matrix(rbind(x, y), nc = 2, byrow = TRUE) > > > On Mon, Feb 2, 2009 at 10:52 AM, Shruthi Jayaram > wrote:

Re: [R] Matrix

2009-02-02 Thread Shruthi Jayaram
Thanks this is very helpful. Shruthi On Tue, Feb 3, 2009 at 1:36 AM, Gabor Grothendieck wrote: > Sorry, there was an error. Try this: > > x <- matrix(1:4, 2) > y <- 10 * x > matrix(t(cbind(x, y)), nc = 2, byrow = TRUE) > > > On Mon, Feb 2, 2009 at 12:32 PM, Gabor Grothendieck > wrote: > > Try t

[R] Matrix Multiplication

2009-02-06 Thread Maithili Shiva
Hi R helpers, I have two matrices A and B of the order (4 * 5) and (5 * 3) respectively. How to multiply these two matrices to obtain resultant matrix of the order (4 * 3). Thanks in advance With regards Maithili __ R-help@r-project.org mailing

[R] Matrix Indexing

2008-04-12 Thread Rory Winston
Hi Does anyone know how I might pick out diagonal elements of a matrix using a vector? If I create a matrix a: a <- matrix(c(1:16), 4, byrow=TRUE) and I want to pick out the elements (1,1),(2,2),(3,3), or another arbitrary diagonal (upper or lower), is there any way I can use a vector to do thi

[R] matrix problem

2008-04-21 Thread William Simpson
Hi Everyone, I am running into a problem with matrices. I use R version 2.4.1 and an older version. The problem is this: m<-matrix(ncol=3,nrow=4) m[,1:3]<-runif(n=4) That does what I expect; it fills up the rows of the matrix with the data vector > m [,1] [,2] [,3] [1,] 0.208

Re: [R] matrix

2008-06-18 Thread Uwe Ligges
Read the help page or better the manuals! And before posting, please read the posting guide. You get the help page for indexing by, e.g.: help("[") Uwe Ligges Paul Adams wrote: Hello everyone,I am having a difficult time understanding what commands are used to add and remove elements

[R] matrix loop

2008-02-06 Thread mohamed nur anisah
Dear list, I'm trying to make a loop of a (5x10) matrix and below are my codes. Could anybody help me figure out why my loop is not working. Thanks in advance!! m<-1:5 n<-1:10 for(i in 1:length(m)) { for(j in 1:length(n)) { y[i,j]=sum(i,j) y<-as.matrix(y[i,j]) } } cheer

[R] Matrix inversion

2008-02-18 Thread Ben Domingue
Howdy, I am trying to invert a matrix for the purposes of least squares. I have tried a number of things, and the variety of results has me confused. 1. When I try solve() I get the following: >Error in solve.default(t(X) %*% X) : system is computationally singular: reciprocal condition number = 3

[R] Matrix addition

2008-02-19 Thread Marlin Keith Cox
Matt, I know you are probably busy with work, but I cannot help buy asking you these R questions. If it is bothersome, please let me know and I will stick with the R help... but I have two matrices X [,1] [,2] [,3] [,4] [,5] [,6] [1,] 660 693.00 726.0 759.00 792.0 825.00 [2,] 548

[R] Matrix manipulation

2007-10-22 Thread yiferic
Hi everyone, suppose I have a 2D matrix, is there a command to snip out a specific row/column and then remerge the remaining columns/rows back into a contiguous matrix? I will need to repeat this operation quite a bit(reverse selection). Thanks for any insights you can offer. Yifei

[R] matrix transpose

2009-02-15 Thread Roger
This is supposed to be an easy operation, but R 2.8.1 on Mac OS X gives me a lot trouble. the t() function simply does not work properly. What I mean is it works sometimes but does not work at the most of the time, even with the same matrix. this is an example taken from R help > a <- matrix(1:3

[R] matrix output

2009-02-17 Thread phoebe kong
Hi friends, I have questions about printing a pretty big size matrix. As you could see from below, the matrix wasn't showed in R at full size (11X11), but it was cut partly into three smaller matrices (11X4,11X4,11X3). I'm wondering if there is a way to show the whole matrix with dimension 11X11,

[R] matrix computation???

2009-02-18 Thread Kutlwano Ramaboa
Hello Can anyone tell me what I am doing wrong below? My Y and y_hat are the same. A<-scale(stackloss) n1<- dim(A)[1];n2<-dim(A)[2] X<-svd(A) Y<- matrix(A[,"stack.loss"],nrow=n1) Y y_hat <-matrix((X$u%*% t(X$u))%*%Y,nrow=n1,byrow=T) y_hat [[alternative HTML version deleted]] __

[R] Matrix manipulation

2009-04-28 Thread Tammy Ma
From: metal_lical...@live.com To: r-help@r-project.org Subject: About Matrix Date: Tue, 28 Apr 2009 11:28:43 +0300 Hi, Dear R users, I have a question: I have A matrix which is 11519X14 and B matrix which is 1764X14, How do I get C matrix which is The remaining matrix after removing

[R] Matrix sum

2009-05-21 Thread daniele riggi
Someone knows the existence of a function to sum the elements of the same place A[i,j] B[i,j] of a matrix?thank you -- Dr. Daniele Riggi, PhD student University of Milano-Bicocca Department of Statistics Building U7, Via Bicocca degli Arcimboldi, 8 20126 Milano, Italy cell. +39 328 3380690 mailt

[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 h

[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

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

[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 the

[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 P

[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).

[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 e

[R] matrix multiplication question

2008-07-17 Thread Murali K
Hello, I am a newcomer to R and therefore apologize for posting such a basic question. I am trying to multiply 2 matrices t(X1)%*%X1, where t(X1) is: 1 2 3 4 5 8 12 13 20 24 26 27 31 33 34 36 37 40 41 42 45 46 47 48 49 ones 1 1 1 1 1 1 1 1 1 11 1 1 1

Re: [R] Matrix barplot

2008-07-25 Thread Nutter, Benjamin
RUE) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Andreas Tille Sent: Friday, July 25, 2008 8:14 AM To: r-help@r-project.org Subject: [R] Matrix barplot Hi, as a bloody R beginner I failed to solve the probably simple problem to create a barplot of the

Re: [R] Matrix barplot

2008-07-25 Thread Jim Lemon
On Fri, 2008-07-25 at 14:13 +0200, Andreas Tille wrote: > Hi, > > as a bloody R beginner I failed to solve the probably simple problem > to create a barplot of the following data read from a file > > Year A BC > 2000 4 30 > 2001 2 13 >

Re: [R] Matrix barplot

2008-07-25 Thread Andreas Tille
On Fri, 25 Jul 2008, Nutter, Benjamin wrote: data <- data.frame(Year=c(2000,2001,2002), A=c(4,2,1), B=c(3,1,2), C=c(0,3,5)) data.mat <- as.matrix(data)[,2:4] rownames(data.mat) <- data$Year data.mat <- t(data.mat) barplot(data.mat,be

Re: [R] Matrix barplot

2008-07-25 Thread ajay ohri
As a beginner also try downloading the rattle GUI , with all dependecies =true , or R Cmdr GUI.. these are both packages go to rattle.togaware.com for the rattle instructions and installations .its very very user friendly even though the purists think its infra dig.(kidding- Friday humour) Reg

Re: [R] Matrix barplot

2008-07-25 Thread Andreas Tille
On Fri, 25 Jul 2008, Jim Lemon wrote: library(plotrix) Well, if I try this in the example of the previous poster I get nicely rendered fonts - which is the only difference I noticed. # barp groups data in columns, not rows, so transpose barp(t(atdat[,2:4]),names.arg=atdat[,1],col=2:4) Whil

Re: [R] Matrix barplot

2008-07-25 Thread Andreas Tille
lot(data.mat,beside=TRUE) As I said this works great - but now I would like to use the table heading as legend - and have no idea how to access the header (see below) -Original Message- On Behalf Of Andreas Tille Sent: Friday, July 25, 2008 8:14 AM To: r-help@r-project.org Subject: [R] Ma

[R] Matrix from List

2008-07-25 Thread Nelson Villoria
Hello, I have a list in which each element is a list. I want to create a matrix indexed by the two indices of the list. I have been using do.call, but I am not getting what I want. Let me show you: > l.intercepts #the list that nests another list $`1995` $`1995`$`31` (Intercept) 25.37164 $`199

Re: [R] Matrix multiplication

2008-08-06 Thread Ling, Gary (Electronic Trading)
238 -7.953889 -6.130237 -9.717463 # [4,] -0.7801092 3.003660 1.104163 -5.834807 ### end demo ### So, they are the same. Cheers! -gary -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Zhang Yanwei - Princeton-MRAm Sent: Wednesday, August 06, 2008 5:02 PM

Re: [R] Matrix multiplication

2008-08-07 Thread Zhang Yanwei - Princeton-MRAm
:42 PM To: Zhang Yanwei - Princeton-MRAm; r-help@r-project.org Subject: RE: [R] Matrix multiplication Hi, Yes. this is a way, and relatively easy ... Using "Reduce". Note: in order to use "Reduce", you need an update-to-date version of R. I'm using 2.6.2. First you have

Re: [R] matrix question

2008-08-19 Thread Rolf Turner
On 20/08/2008, at 10:08 AM, Altaweel, Mark R. wrote: Hi, I have a vector and a list, with data I would like to multiply together. No you haven't. You have two ***lists***. Lists and vectors are not the same thing. If you don't distinguish between them you will co

[R] matrix to list

2008-09-17 Thread Pinder, Adrian
Hi, can someone please tell me how to convert a square matrix to a list in R? i.e. I want to convert from: a b c a 1 1 1 b 2 2 2 c 3 3 3 to: a a 1 a b 1 a c 1 b a 2 b

Re: [R] matrix graph

2007-12-11 Thread Dylan Beaudette
On Tuesday 11 December 2007, threshold wrote: > Hi All, simple question: > do you know how to graph the following object/matrix in a 'surface manner': > > [,1] [,2] [,3][,4] [,5][,6] > [1,] -0.154 -0.065 0.129 0.637 0.780 0.221 > [2,] 0.236 0.580 0.448 0.729 0.859 0.47

Re: [R] matrix graph

2007-12-11 Thread Tony Plate
Try these: > x <- matrix(rnorm(100), ncol=10) > persp(x) > contour(x) Also, look at the R graph gallery: http://addictedtor.free.fr/graphiques/ -- Tony Plate threshold wrote: > Hi All, simple question: > do you know how to graph the following object/matrix in a 'surface manner': > >

Re: [R] Matrix Inversion

2007-12-12 Thread Robin Hankin
Hello Wang matrix bb is symmetric positive semidefinite, so algebraically the eigenvalues are nonnegative. I would use bb <- crossprod(b) to calculate bb (faster and possibly more accurate) Look at eigen(bb,TRUE,TRUE)$values (see ?eigen for the meaning of the arguments) to see how many very s

Re: [R] Matrix Inversion

2007-12-12 Thread Peter Dalgaard
Wang Chengbin wrote: > I got the following error: > > a = read.csv("mat.csv") > b = as.matrix(a) > tb = t(b) > bb = tb %*% b > dim(bb) > ibb = solve(bb) > bb %*% ibb > > >> ibb = solve(bb) >> > Error in solve.default(bb) : > system is computationally singular: reciprocal condition number

Re: [R] matrix graph

2007-12-12 Thread Julian Burgos
The basic functions you need are image() contour() although I like better the plot.surface() function in the 'fields' package. Julian threshold wrote: > Hi All, simple question: > do you know how to graph the following object/matrix in a 'surface manner': > > [,1] [,2] [,3]

Re: [R] matrix creation

2008-01-28 Thread Gavin Simpson
hits=-2.6 tests=BAYES_00 X-USF-Spam-Flag: NO Hi Michelle, You don't show your read.csv or read.table call, nor the output of str(obj) where obj is the name of the object you read the data into. I notice that you have explicit 0 and NA. Is there a chance that you have entered NA into the cells th

Re: [R] matrix creation

2008-01-28 Thread Michelle DePrenger-Levin
I was asked for the following information and hope it might help those who could answer my question... To import the table I used: AsMi05test=read.csv("C:/AsMi_Site05_1998.csv") > str(AsMi05test) `data.frame': 12 obs. of 8 variables: $ X : Factor w/ 6 levels

Re: [R] matrix creation

2008-01-28 Thread Gavin Simpson
hits=-2.6 tests=BAYES_00 X-USF-Spam-Flag: NO On Mon, 2008-01-28 at 12:17 -0700, Michelle DePrenger-Levin wrote: > I was asked for the following information and hope it might help those who > could answer my question... That looks fine to me Michelle. You will have problems with as.matrix on thi

Re: [R] Matrix Multiplication

2009-02-06 Thread Jorge Ivan Velez
Dear Maithili, A<-matrix(1:20,4,5)B<-matrix(10:24,5,3) A %*% B See ?"%*%" for more information. HTH, Jorge On Fri, Feb 6, 2009 at 7:57 AM, Maithili Shiva wrote: > Hi R helpers, > > > > I have two matrices A and B of the order (4 * 5) and (5 * 3) respectively. > How to multiply these two mat

Re: [R] Matrix Multiplication

2009-02-06 Thread Gavin Simpson
On Fri, 2009-02-06 at 04:57 -0800, Maithili Shiva wrote: > Hi R helpers, > > > > I have two matrices A and B of the order (4 * 5) and (5 * 3) > respectively. How to multiply these two matrices to obtain resultant > matrix of the order (4 * 3). ?`%*%` E.g.: > A <- matrix(runif(4*5), nrow = 4)

Re: [R] Matrix Indexing

2008-04-12 Thread Chuck Cleland
On 4/12/2008 5:56 AM, Rory Winston wrote: > Hi > > Does anyone know how I might pick out diagonal elements of a matrix using a > vector? > > If I create a matrix a: > > a <- matrix(c(1:16), 4, byrow=TRUE) > > and I want to pick out the elements (1,1),(2,2),(3,3), or another arbitrary > diagonal

Re: [R] Matrix Indexing

2008-04-12 Thread Gavin Simpson
On Sat, 2008-04-12 at 10:56 +0100, Rory Winston wrote: > Hi > > Does anyone know how I might pick out diagonal elements of a matrix using a > vector? > > If I create a matrix a: > > a <- matrix(c(1:16), 4, byrow=TRUE) Not sure if this does all that you describe below, but: diag(a) and you can

Re: [R] Matrix Indexing

2008-04-12 Thread Duncan Murdoch
Rory Winston wrote: > Hi > > Does anyone know how I might pick out diagonal elements of a matrix using a > vector? > > If I create a matrix a: > > a <- matrix(c(1:16), 4, byrow=TRUE) > > and I want to pick out the elements (1,1),(2,2),(3,3), or another arbitrary > diagonal (upper or lower), is ther

Re: [R] matrix problem

2008-04-21 Thread Chuck Cleland
On 4/21/2008 5:54 AM, William Simpson wrote: > Hi Everyone, > > I am running into a problem with matrices. I use R version 2.4.1 and > an older version. > > The problem is this: > m<-matrix(ncol=3,nrow=4) > m[,1:3]<-runif(n=4) > > That does what I expect; it fills up the rows of the matrix with

Re: [R] matrix problem

2008-04-21 Thread Rolf Turner
On 21/04/2008, at 9:54 PM, William Simpson wrote: > Hi Everyone, > > I am running into a problem with matrices. I use R version 2.4.1 and > an older version. > > The problem is this: > m<-matrix(ncol=3,nrow=4) > m[,1:3]<-runif(n=4) > > That does what I expect; it fills up the rows of the matrix w

Re: [R] matrix problem

2008-04-21 Thread William Simpson
Thanks very much Petr and Rold for your helpful replies. Cheers 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, mi

[R] matrix from list

2008-04-24 Thread Olivier Lefevre
Another possibly simple thing that I cannot get right is how to extract the data part of a list as a matrix. The data were read from xls, with labels, and thus are of list mode, e.g., col1 col2 1 0.1 1.1 2 0.2 1.2 I want to extract from that just the numeric data part, i.e., (in this case

[R] Matrix transformation problem

2008-06-11 Thread stefan . petersson
ng, I have a matrix (x) with binary content. Each row of the matrix holds exactly one 1, and the rest of the row is zeros. The thing is that I need to 'collapse' the matrix to one column where each row holds the original column index of the 1's (y). Sometimes, the matrix is quite large, so I h

Re: [R] matrix loop

2008-02-06 Thread jim holtman
What exactly are you intending the loop to do? Why do you have the 'as.matrix' in the middle of the loop? Where was 'y' defined? Does this do what you want? > outer(1:5, 1:10, "+") [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,]23456789 1011 [

Re: [R] matrix loop

2008-02-08 Thread John Kane
You are trying to create a matrix in the loop Try creating the matrix before the loop m <- 1:5 n<-1:10 y <- matrix(rep(NA, 50), nrow=m) for(i in 1:length(m)) { for(j in 1:length(n)) { y[i,j]=sum(i,j) } } However as Jim Holtman points out you can do this particular matrix by outer

Re: [R] matrix loop

2008-02-09 Thread David Winsemius
John Kane <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > You are trying to create a matrix in the loop > > Try creating the matrix before the loop > m <- 1:5 > n<-1:10 > y <- matrix(rep(NA, 50), nrow=m) # I think that this might actually work: y <- matrix(rep(NA, 50), nrow=max(m))

Re: [R] Matrix inversion

2008-02-18 Thread Bill.Venables
Ben Domingue asks: > I am trying to invert a matrix for the purposes of least squares. I > have tried a number of things, and the variety of results has me > confused. Don't be. > 1. When I try solve() I get the following: > >Error in solve.default(t(X) %*% X) : system is computationally > sing

[R] Matrix bar plot

2007-10-04 Thread Todd A. Gibson
Hello, Does R have any facility to create a plot that looks similar to this: http://www.augustcouncil.com/~tgibson/barmatrix.jpg Thank you, -TAG Todd A. Gibson __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do re

Re: [R] Matrix manipulation

2007-10-22 Thread Tim Calkins
use the '-' feature. >mat <- matrix(rnorm(100), nrow = 10) #snip the second row >mat[-2,] #snip the third column >mat[,-3] #snip rows 5 and 7 >mat[-c(5,7),] cheers tc On 10/23/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hi everyone, > > suppose I have a 2D matrix, is there a command to

Re: [R] Matrix manipulation

2007-10-22 Thread Julian Burgos
Matrices are not made of paper! :) If you index a matrix with negative numbers, you'll get back that matrix minus that column or row. A quick example: >a<-matrix(c(1:9),ncol=3) # Create a sample matrix >a# Display it [,1] [,2] [,3] [1,]147 [2,]2

Re: [R] matrix transpose

2009-02-15 Thread Rolf Turner
On 16/02/2009, at 8:36 AM, Roger wrote: This is supposed to be an easy operation, but R 2.8.1 on Mac OS X gives me a lot trouble. the t() function simply does not work properly. What I mean is it works sometimes but does not work at the most of the time, even with the same matrix. this

Re: [R] matrix transpose

2009-02-15 Thread Wacek Kusnierczyk
Roger wrote: > This is supposed to be an easy operation, but R 2.8.1 on Mac OS X gives me a > lot trouble. the t() function simply does not work properly. What I mean is > it works sometimes but does not work at the most of the time, even with the > same matrix. > > this is an example taken from R

Re: [R] matrix transpose

2009-02-15 Thread Daniel Viar
Here's one way that seems to work: a <- matrix(1:30,5,6) # Create a target for the transpose b <- matrix(1:(nrow(a)*ncol(a)),ncol(a),nrow(a)) # populate b with the transpose of a for (i in 1:ncol(a)) { b[i,1:(nrow(a))] <- a[1:(nrow(a)),i]} # Check: Did it work? all.equal(b,t(a)) I'm sure there's

Re: [R] matrix transpose

2009-02-15 Thread Wacek Kusnierczyk
Rolf Turner wrote: > > On 16/02/2009, at 8:36 AM, Roger wrote: > >> This is supposed to be an easy operation, but R 2.8.1 on Mac OS X >> gives me a >> lot trouble. the t() function simply does not work properly. What I >> mean is >> it works sometimes but does not work at the most of the time, eve

Re: [R] matrix output

2009-02-17 Thread Duncan Murdoch
On 17/02/2009 5:31 PM, phoebe kong wrote: Hi friends, I have questions about printing a pretty big size matrix. As you could see from below, the matrix wasn't showed in R at full size (11X11), but it was cut partly into three smaller matrices (11X4,11X4,11X3). I'm wondering if there is a way to

Re: [R] matrix output

2009-02-18 Thread Jim Lemon
phoebe kong wrote: Hi friends, I have questions about printing a pretty big size matrix. As you could see from below, the matrix wasn't showed in R at full size (11X11), but it was cut partly into three smaller matrices (11X4,11X4,11X3). I'm wondering if there is a way to show the whole matrix

Re: [R] matrix computation???

2009-02-19 Thread Greg Snow
p-boun...@r- > project.org] On Behalf Of Kutlwano Ramaboa > Sent: Wednesday, February 18, 2009 10:43 PM > To: r-help@r-project.org > Subject: [R] matrix computation??? > > Hello > > Can anyone tell me what I am doing wrong below? My Y and y_hat are the > same. > > &

[R] Matrix multiplication multivariate

2009-02-20 Thread MarcioRibeiro
Hi listers... I am trying to do a matrix multiplication... Suppose my data has 100 obs and 2 variables... I calculated the estimateurs of location and dispersion... So now I would like to do the following... t(Xi-location)%*%solve(dispersion)%*%(Xi-location) My code is... Z<-rep(2,200) Z<-matrix(Z

Re: [R] matrix computation???

2009-02-24 Thread Kutlwano Ramaboa
-- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Kutlwano Ramaboa > Sent: Wednesday, February 18, 2009 10:43 PM > To: r-help@r-project.org > Subject: [R] matrix computation??? > > Hello > > Can anyone tell me what I am doing wr

Re: [R] matrix computation???

2009-02-24 Thread Greg Snow
ailto:r-help-boun...@r- > project.org] On Behalf Of Kutlwano Ramaboa > Sent: Tuesday, February 24, 2009 1:02 AM > To: Greg Snow; r-help@r-project.org > Subject: Re: [R] matrix computation??? > > Hi Greg > > Thanks for responding. > > When I scale stackloss and compute

Re: [R] matrix computation???

2009-02-24 Thread Kutlwano Ramaboa
Healthcare greg.s...@imail.org 801.408.8111 > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Kutlwano Ramaboa > Sent: Tuesday, February 24, 2009 1:02 AM > To: Greg Snow; r-help@r-project.org > Subject: Re: [R]

[R] Matrix Construction; Subdiagonal

2009-03-11 Thread Stu Field
I'm trying to enter a vector into the subdiagonal of a matrix but cannot find a command in R which corresponds to the MatLab version of diag(vec, k), where vec = the vector of interest, and k = the diagonal (k=0 for the diagonal; k=-1 for the subdiagonal; k=1 for superdiagonal, etc.) Is the

[R] matrix merge problem

2009-04-14 Thread Juan Pablo Fededa
Dear r-help contributors, I have two questions: first: I have a matrix A and a vector B. I want to make a new matrix C, which is made of the rows of A having a value included in B. Second: I have two matrixes A and B, of different dimensions. B has unique values in column 2 and A has not uniqu

Re: [R] Matrix sum

2009-05-21 Thread Jorge Ivan Velez
Dear Daniele, Try this: A <- matrix(1:10,ncol=2) B <- matrix(10:20,ncol=2) A+B #[,1] [,2] #[1,] 11 21 #[2,] 13 23 #[3,] 15 25 #[4,] 17 27 #[5,] 19 29 HTH, Jorge On Thu, May 21, 2009 at 11:11 AM, daniele riggi wrote: > Someone knows the existence of a function to sum the el

Re: [R] Matrix sum

2009-05-21 Thread Uwe Ligges
daniele riggi wrote: Someone knows the existence of a function to sum the elements of the same place A[i,j] B[i,j] of a matrix?thank you Yes: + Uwe Ligges __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEAS

Re: [R] Matrix sum

2009-05-21 Thread Jorge Ivan Velez
For this, you might want to take a look at the first example in ?Reduce. HTH, Jorge On Thu, May 21, 2009 at 11:21 AM, daniele riggi wrote: > Ok, I know this waybut if i have a lot of matrix, does a function exist to > sum all of them elements by elements? > > > 2009/5/21 Jorge Ivan Velez > > >

Re: [R] Matrix sum

2009-05-21 Thread daniele riggi
Ok, I know this waybut if i have a lot of matrix, does a function exist to sum all of them elements by elements? 2009/5/21 Jorge Ivan Velez > > Dear Daniele, > Try this: > > A <- matrix(1:10,ncol=2) > B <- matrix(10:20,ncol=2) > A+B > #[,1] [,2] > #[1,] 11 21 > #[2,] 13 23 > #[3,] 15

[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

[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

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

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 i

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( from=

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 < william.a

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), n

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 Velez wrote: > D

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 wrote: > Doesn't wor

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, reproducib

[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 using

  1   2   3   >