Re: [R] matrix manipulation -solved

2015-07-16 Thread Therneau, Terry M., Ph.D.
Yes it is obvious --- once someone else pointed it out. Thanks for the hint. Terry T. On 07/16/2015 12:52 PM, Peter Langfelder wrote: Hi Terry, maybe I'm missing something, but why not define a matrix BB = V'B; then t(B) %*% V = t(BB), then your problem reduces to finding A such that t(BB) %*

Re: [R] matrix manipulation

2015-07-16 Thread Peter Langfelder
Hi Terry, maybe I'm missing something, but why not define a matrix BB = V'B; then t(B) %*% V = t(BB), then your problem reduces to finding A such that t(BB) %*% A = 0? Peter On Thu, Jul 16, 2015 at 10:28 AM, Therneau, Terry M., Ph.D. wrote: > This is as much a mathematics as an R question, in t

Re: [R] Matrix Manipulation R

2015-07-04 Thread David Winsemius
> On Jul 4, 2015, at 3:09 AM, Alex Kim wrote: > > Hi guys, > > Suppose I have an extremely large data frame with 2 columns and .5 mil > rows. For example, the last 6 rows may look like this: > . > .. > ... > 89 100 > 93 120 > 95 125 > 101NA > 115NA > 123

Re: [R] matrix manipulation question

2015-03-31 Thread Stéphane Adamowicz
Many thanks, Stéphane Le 30 mars 2015 à 10:42, peter dalgaard a écrit : > >> On 30 Mar 2015, at 09:59 , Stéphane Adamowicz >> wrote: >> >> >> However, in order to help me understand, would you be so kind as to give me >> a matrix or data.frame example where « complete.cases(X)== T » or «

Re: [R] matrix manipulation question

2015-03-30 Thread peter dalgaard
> On 30 Mar 2015, at 09:59 , Stéphane Adamowicz > wrote: > > > However, in order to help me understand, would you be so kind as to give me a > matrix or data.frame example where « complete.cases(X)== T » or « > complete.cases(X)== TRUE » would give some unwanted result ? The standard proble

Re: [R] matrix manipulation question

2015-03-30 Thread Berend Hasselman
> On 30-03-2015, at 09:59, Stéphane Adamowicz > wrote: > > > Le 27 mars 2015 à 18:01, David Winsemius a écrit : > >> >> On Mar 27, 2015, at 3:41 AM, Stéphane Adamowicz wrote: >> >>> Well, it seems to work with me. >>> >> >> No one is doubting that it worked for you in this instance. What

Re: [R] matrix manipulation question

2015-03-30 Thread Stéphane Adamowicz
Le 27 mars 2015 � 18:01, David Winsemius a �crit : > > On Mar 27, 2015, at 3:41 AM, St�phane Adamowicz wrote: > >> Well, it seems to work with me. >> > > No one is doubting that it worked for you in this instance. What Peter D. was > criticizing was the construction : > > complete.cases(t(

Re: [R] matrix manipulation question

2015-03-27 Thread Henric Winell
On 2015-03-27 11:41, Stéphane Adamowicz wrote: Well, it seems to work with me. Y <- as.matrix(airquality) head(Y, n=8) Ozone Solar.R Wind Temp Month Day [1,]41 190 7.4 67 5 1 [2,]36 118 8.0 72 5 2 [3,]12 149 12.6 74 5 3 [4,]18 313

Re: [R] matrix manipulation question

2015-03-27 Thread Jatin Kala
Thanks Richard, This works, rather obvious now that i think of it! =) On 27/03/2015 4:30 pm, Richard M. Heiberger wrote: just reverse what you did before. newdata <- data newdata[] <- NA newdata[,!apply(is.na(data), 2, any)] <- myfunction(data_no_NA) On Fri, Mar 27, 2015 at 1:13 AM, Jatin Kala

Re: [R] matrix manipulation question

2015-03-27 Thread David Winsemius
On Mar 27, 2015, at 3:41 AM, Stéphane Adamowicz wrote: > Well, it seems to work with me. > No one is doubting that it worked for you in this instance. What Peter D. was criticizing was the construction : complete.cases(t(Y))==T ... and it was on two bases that it is "wrong". The first is tha

Re: [R] matrix manipulation question

2015-03-27 Thread Stéphane Adamowicz
> >> example. Furthermore in my example no unwanted format occurred. You can > > Yes because data.frame was (luckily) numeric. > Luck has nothing to do with this. I Chose this example on purpose … Stéphane __ R-help@r-project.org mailing list -- To

Re: [R] matrix manipulation question

2015-03-27 Thread PIKAL Petr
Hi > -Original Message- > From: Stéphane Adamowicz [mailto:stephane.adamow...@avignon.inra.fr] > Sent: Friday, March 27, 2015 1:26 PM > To: PIKAL Petr > Cc: peter dalgaard; r-help@r-project.org > Subject: Re: [R] matrix manipulation question > > > Le 27 mars

Re: [R] matrix manipulation question

2015-03-27 Thread Stéphane Adamowicz
Le 27 mars 2015 à 12:34, PIKAL Petr a écrit : > Very, very, very bad solution. > > as.matrix can change silently your data to unwanted format, > complete.cases()==T is silly as Peter already pointed out. > > Perhaps, but it happens that in the original message, the question dealt with a

Re: [R] matrix manipulation question

2015-03-27 Thread PIKAL Petr
: [R] matrix manipulation question Well, it seems to work with me. Y <- as.matrix(airquality) head(Y, n=8) Ozone Solar.R Wind Temp Month Day [1,]41 190 7.4 67 5 1 [2,]36 118 8.0 72 5 2 [3,]12 149 12.6 74 5 3 [4,]18 313 11.5 62

Re: [R] matrix manipulation question

2015-03-27 Thread Stéphane Adamowicz
Well, it seems to work with me. Y <- as.matrix(airquality) head(Y, n=8) Ozone Solar.R Wind Temp Month Day [1,]41 190 7.4 67 5 1 [2,]36 118 8.0 72 5 2 [3,]12 149 12.6 74 5 3 [4,]18 313 11.5 62 5 4 [5,]NA NA 14.3 56

Re: [R] matrix manipulation question

2015-03-27 Thread peter dalgaard
On 27 Mar 2015, at 09:58 , Stéphane Adamowicz wrote: > data_no_NA <- data[, complete.cases(t(data))==T] Ouch! logical == TRUE is bad, logical == T is worse: data[, complete.cases(t(data))] -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 200

Re: [R] matrix manipulation question

2015-03-27 Thread Stéphane Adamowicz
Why not use complete.cases() ? data_no_NA <- data[, complete.cases(t(data))==T] Le 27 mars 2015 à 06:13, Jatin Kala a écrit : > Hi, > I've got a rather large matrix of about 800 rows and 60 columns. > Each column is a time-series 800 long. > > Out of these 60 time series, some have mi

Re: [R] matrix manipulation question

2015-03-26 Thread Richard M. Heiberger
just reverse what you did before. newdata <- data newdata[] <- NA newdata[,!apply(is.na(data), 2, any)] <- myfunction(data_no_NA) On Fri, Mar 27, 2015 at 1:13 AM, Jatin Kala wrote: > Hi, > I've got a rather large matrix of about 800 rows and 60 columns. > Each column is a time-series 800 lon

Re: [R] matrix manipulation with its rows

2013-01-16 Thread arun
HI, You could also do this:  lapply(sample1,function(x) {mat1<-cbind(matrix(0,nrow=2,ncol=3),x); mat1[cbind(rep(1,3),1:3)]<- mat1[cbind(rep(1,3),4:6)]; mat1[cbind(rep(1,3),4:6)]<-0; mat1}) A.K. - Original Message - From: Kathryn Lord To: r-help@r-project.org Cc: Sent: Wednesday, Janu

Re: [R] matrix manipulation with its rows

2013-01-16 Thread Patrick Burns
Not a great solution, I don't think, but: > kronecker(diag(2), matrix(1:6, 2, byrow=TRUE))[c(1,4),] [,1] [,2] [,3] [,4] [,5] [,6] [1,]123000 [2,]000456 So using a function that does this in 'lapply' should solve the problem you state. I'm gue

Re: [R] matrix manipulation with its rows

2013-01-16 Thread PIKAL Petr
Hi with your specific example you can use remat<-function(mat) { mt<-t(mat) mt<-c(mt[1:3], rep(0,6), mt[4:6]) matrix(mt, 2,6, byrow=TRUE) } lapply(sample, remat) Regards Petr > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf O

Re: [R] matrix manipulation

2012-06-14 Thread Petr Savicky
On Thu, Jun 14, 2012 at 02:24:20PM -0400, cowboy wrote: > thank you, Petr. > This is exactly what I'm looking for in my post. > An related question can be how to get an arbitrary weight, say if row1 > and row 2 have 1 common value 1, then assign a weight 10, if row 1 and > row 2 have 2 common value

Re: [R] matrix manipulation

2012-06-14 Thread cowboy
thank you, Petr. This is exactly what I'm looking for in my post. An related question can be how to get an arbitrary weight, say if row1 and row 2 have 1 common value 1, then assign a weight 10, if row 1 and row 2 have 2 common value 1, then assign a weight 12. I'm not so sure how to expand your me

Re: [R] matrix manipulation

2012-06-14 Thread Petr Savicky
On Thu, Jun 14, 2012 at 01:11:45PM +, G. Dai wrote: > Dear Rlisters, > I'm writing to ask how to manipulate a matrix or dataframe in a specific way. > > To elaborate, let's consider an example. Assume we have the following > 3 by 4 matrix A with elements either 0 or 1, > 0 1 1 0 > 1 0 1

Re: [R] matrix Manipulation...

2011-05-25 Thread Sarah Goslee
It's very easy to do in two steps: > testmat <- matrix(c(.2, .3, 1, -1, 3, .2, .4, 5, .5, -1), byrow=TRUE, nrow=2) > testmat [,1] [,2] [,3] [,4] [,5] [1,] 0.2 0.31 -1.03 [2,] 0.2 0.45 0.5 -1 > testmat[testmat >= 1] <- 1 > testmat[testmat < 0] <- 0 > testmat [,1] [,2] [,

Re: [R] matrix Manipulation...

2011-05-25 Thread Jim Silverton
Hello everyone, I have a 2 x 5 matrix: say 0.2 0.3 1 -1 3 0.2. 0.4 5 0.5 -1 I want to replace all the values greater than or equal to 1 with 1 and those less than or equal to 0 with 0. So I should end up with a mtrix looking like: 0.2 0.3 1 0 1 0.2. 0.4 1 0.5 0 An

Re: [R] Matrix manipulation in for loop

2011-05-16 Thread jm_jem
hello I think if you try this: for(j in 1: length(nsample)){ MEANS[,]<-create.means.one.size(j,var,nboot) } it will work -- View this message in context: http://r.789695.n4.nabble.com/Matrix-manipulation-in-for-loop-tp3525849p3525888.html Sent from the R help mailing list arc

Re: [R] Matrix manipulation

2011-04-01 Thread andrija djurovic
HI, here is another solution: int <- sample(1:20,10) int [1] 10 4 5 2 14 17 9 11 16 13 mat<-matrix(11:30,ncol=4) mat [,1] [,2] [,3] [,4] [1,] 11 16 21 26 [2,] 12 17 22 27 [3,] 13 18 23 28 [4,] 14 19 24 29 [5,] 15 20 25 30 mat[apply(mat,1, funct

Re: [R] Matrix manipulation

2011-04-01 Thread Dennis Murphy
Hi: Here' s one approach: > int <- sample(1:20,10) > m <- matrix(sample(1:40, 20), nrow = 10) > int [1] 7 12 4 6 1 19 17 20 15 5 > m [,1] [,2] [1,]9 15 [2,] 23 32 [3,] 40 14 [4,] 19 38 [5,] 286 [6,] 26 18 [7,] 34 22 [8,]7 35 [9,] 21

Re: [R] Matrix Manipulation

2010-11-04 Thread emj83
Many thanks-its worked a treat :-) Emma -- View this message in context: http://r.789695.n4.nabble.com/Matrix-Manipulation-tp3027266p3027307.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://st

Re: [R] Matrix Manipulation

2010-11-04 Thread jim holtman
try this: > x V2 V3 V4 [1,] 1 1 1 [2,] 2 2 2 [3,] 3 3 3 [4,] 4 4 4 [5,] 5 NA 5 [6,] NA NA 6 [7,] NA NA NA > offset <- c(0,2,1) > # add the control to the data and make two copies so we can offset > x.new <- rbind(offset, x, x) > result <- apply(x.new, 2, function(.col){ + .

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

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

Re: [R] Matrix manipulation

2009-06-11 Thread Payam Minoofar
On 6/11/09 2:13 PM, "William Dunlap" wrote: > -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

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

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 met

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 wrote: > Hello everyone, > > I have a couple of fairly simple questions (I hope) the answers to which I > cannot find through the documentati

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