Re: [R] matrix indexing/subset error

2016-05-30 Thread Jeff Newmiller
z %% 2 == 1 has 12 logical values. What do you expect R to do with it worth respect to 4 rows? -- Sent from my phone. Please excuse my brevity. On May 30, 2016 11:38:46 AM PDT, Carl Sutton via R-help wrote: >Hi Guru's >In my quest to understand R I have what I thought was a simple exercise

[R] matrix indexing/subset error

2016-05-30 Thread Carl Sutton via R-help
Hi Guru's In my quest to understand R I have what I thought was a simple exercise that now has me baffled.  Why the error message after running this code?  I am totally baffled by the error message.  I was expecting rows 1 and 3 of the x matrix to be returned, and have not a clue as to why this

Re: [R] matrix indexing (igraph ?)

2011-08-18 Thread Gábor Csárdi
This is not an igraph issue, I believe. You need to go over your indices and update the matrix, i.e. for (i in seq_along(t.list)) { temp[t.list[i], c.list[i]] <- temp[t.list[i], c.list[i]] + 1 } Best, Gabor On Tue, Aug 2, 2011 at 4:50 PM, Robinson, David G wrote: > I realize that matrix indexin

[R] matrix indexing (igraph ?)

2011-08-02 Thread Robinson, David G
I realize that matrix indexing has been addressed in various flavors, but I'm stumped and didn't find anything in the archives. It's not clear if it is an igraph issue or a more general problem. Thanks in advance for your patience. I am using igraph to read a gml file (http://www-personal.umic

Re: [R] matrix indexing in 'for' loop?

2010-12-22 Thread govindas
Thank you all once again .. Yeah, its working now. -- Regards, Mahalakshmi Graduate Student #20, Department of Geography Michigan State University East Lansing, MI 48824 Quoting Liviu Andronic : > On Wed, Dec 22, 2010 at 6:39 PM,  wrote: >> Thank you both for your suggestions. I have anothe

Re: [R] matrix indexing in 'for' loop?

2010-12-22 Thread Bert Gunter
Have you consulted R's extensive documentation? -- in particular, "An Introduction to R," which would seem like an obvious place for R newbies to start. If you had done so, you would have found your question answered there in section 6.1 on lists. -- Bert Gunter On Wed, Dec 22, 2010 at 9:39 AM,

Re: [R] matrix indexing in 'for' loop?

2010-12-22 Thread Liviu Andronic
On Wed, Dec 22, 2010 at 6:39 PM, wrote: > Thank you both for your suggestions. I have another question - is there a > specific way to access the individual elements of a 'list' variable? i.e. > > dmi = matrix(rnorm(20),4,5) > soi = matrix(rnorm(20),4,5) > pe = matrix(rnorm(20),4,5) > y <- list(dm

Re: [R] matrix indexing in 'for' loop?

2010-12-22 Thread govindas
Thank you both for your suggestions. I have another question - is there a specific way to access the individual elements of a 'list' variable? i.e.  dmi = matrix(rnorm(20),4,5) soi = matrix(rnorm(20),4,5) pe = matrix(rnorm(20),4,5) y <- list(dmi, soi, pe) y[[1]]   gives [,1]       [,2

Re: [R] matrix indexing in 'for' loop?

2010-12-22 Thread Liviu Andronic
On Wed, Dec 22, 2010 at 2:57 AM, Phil Spector wrote: > To make your loop work, you need to learn about the get function. > I'm not going to give you the details because there are better > approaches available. > First, let's make some data that will give values which can be verified. >  (All the c

Re: [R] matrix indexing in 'for' loop?

2010-12-21 Thread Phil Spector
To make your loop work, you need to learn about the get function. I'm not going to give you the details because there are better approaches available. First, let's make some data that will give values which can be verified. (All the correlations of the data you created are exactly equal to 1.)

[R] matrix indexing in 'for' loop?

2010-12-21 Thread govindas
Hi, I am having trouble with matrices. I have 2 matrices as given below, and I am interested in using these matrices inside "for" loops used to calculate correlations. I am creating a list with the names of the matrices assuming this list could be indexed inside the 'for' loop to retrieve the

Re: [R] matrix indexing and update

2008-11-05 Thread Jorge Ivan Velez
Dear Murali, Here is one way: set.seed(123) a <- matrix(abs(rnorm(100)), 10) b <- rnorm(10) apply(a,2,function(x) ifelse(b>quantile(b,probs=0.75),-x,x)) HTH, Jorge On Wed, Nov 5, 2008 at 11:30 AM, <[EMAIL PROTECTED]> wrote: > Folks, > > I have a matrix: > > set.seed(123) > a <- matrix(rn

Re: [R] matrix indexing and update

2008-11-05 Thread Dimitris Rizopoulos
you almost have it, e.g., check the following: set.seed(123) a <- matrix(rnorm(100), 10) b <- rnorm(10) ind <- b > quantile(b, 0.75) a[ind, ] <- -a[ind, ] a I hope it helps. Best, Dimitris [EMAIL PROTECTED] wrote: Folks, I have a matrix: set.seed(123) a <- matrix(rnorm(100), 10) And a v

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

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

[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