[R] matrix manipulation

2015-07-16 Thread Therneau, Terry M., Ph.D.
This is as much a mathematics as an R question, in the this should be easy but I don't see it category. Assume I have a full rank p by p matrix V (aside: V = (X'X)^{-1} for a particular setup), a p by k matrix B, and I want to complete an orthagonal basis for the space with distance function

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. thern...@mayo.edu wrote: This is as much a mathematics as an

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 R

2015-07-04 Thread David Winsemius
On Jul 4, 2015, at 3:09 AM, Alex Kim dumboisveryd...@gmail.com 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 115

[R] Matrix Manipulation R

2015-07-04 Thread Alex Kim
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 123NA 124NA I would like to manipulate this data frame to

[R] Matrix Manipulation R

2015-07-04 Thread Alex Kim
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 123NA 124NA I would like to manipulate this data frame to

[R] Matrix Manipulation

2015-07-04 Thread Alex Kim via R-help
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 123NA 124NA I would like to manipulate this data frame to

Re: [R] matrix manipulation question

2015-03-31 Thread Stéphane Adamowicz
Many thanks, Stéphane Le 30 mars 2015 à 10:42, peter dalgaard pda...@gmail.com a écrit : On 30 Mar 2015, at 09:59 , Stéphane Adamowicz stephane.adamow...@avignon.inra.fr wrote: However, in order to help me understand, would you be so kind as to give me a matrix or data.frame example

Re: [R] matrix manipulation question

2015-03-30 Thread Berend Hasselman
On 30-03-2015, at 09:59, Stéphane Adamowicz stephane.adamow...@avignon.inra.fr wrote: Le 27 mars 2015 à 18:01, David Winsemius dwinsem...@comcast.net 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

Re: [R] matrix manipulation question

2015-03-30 Thread peter dalgaard
On 30 Mar 2015, at 09:59 , Stéphane Adamowicz stephane.adamow...@avignon.inra.fr 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

Re: [R] matrix manipulation question

2015-03-30 Thread Stéphane Adamowicz
Le 27 mars 2015 � 18:01, David Winsemius dwinsem...@comcast.net 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 :

Re: [R] matrix manipulation question

2015-03-27 Thread peter dalgaard
On 27 Mar 2015, at 09:58 , Stéphane Adamowicz stephane.adamow...@avignon.inra.fr 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

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 5

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 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 jatin.kala...@gmail.com 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

Re: [R] matrix manipulation question

2015-03-27 Thread Stéphane Adamowicz
Le 27 mars 2015 à 12:34, PIKAL Petr petr.pi...@precheza.cz 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

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 2015 à 12:34, PIKAL Petr petr.pi

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

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

[R] matrix manipulation question

2015-03-26 Thread Jatin Kala
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 missing values (NA). I want to strip out all columns that have one or more NA values, i.e., only want full time series. This should do the

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 jatin.kala...@gmail.com wrote: Hi, I've got a rather large matrix of about 800 rows and 60 columns. Each column is a

[R] matrix manipulation with its rows

2013-01-16 Thread Kathryn Lord
Dear R users, I have a question about matrix manipulation with its rows. Plz see the simple example below sample - list(matrix(1:6, nr=2,nc=3), matrix(7:12, nr=2,nc=3), matrix(13:18,nr=2,nc=3)) sample [[1]] [,1] [,2] [,3] [1,]135 [2,]246 [[2]] [,1] [,2]

Re: [R] matrix manipulation with its rows

2013-01-16 Thread PIKAL Petr
Of Kathryn Lord Sent: Wednesday, January 16, 2013 9:00 AM To: r-help@r-project.org Subject: [R] matrix manipulation with its rows Dear R users, I have a question about matrix manipulation with its rows. Plz see the simple example below sample - list(matrix(1:6, nr=2,nc=3), matrix(7:12, nr

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

Re: [R] matrix manipulation with its rows

2013-01-16 Thread arun
: Sent: Wednesday, January 16, 2013 2:59 AM Subject: [R] matrix manipulation with its rows Dear R users, I have a question about matrix manipulation with its rows. Plz see the simple example below sample - list(matrix(1:6, nr=2,nc=3), matrix(7:12, nr=2,nc=3), matrix(13:18,nr=2,nc=3)) sample

[R] matrix manipulation

2012-06-14 Thread G. Dai
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 1 0 0 0 1 From the original matrix A, I'd like to generate a new

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

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

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

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

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] [,3] [,4]

[R] Matrix manipulation in for loop

2011-05-16 Thread clips10
Hi all, I have a problem with getting my code to do what I want! This is the code I have: create.means.one.size-function(nsample,var,nboot){ mat.x-matrix(0,nrow=nboot,ncol=nsample) for(i in 1:nboot){ mat.x[i,]-sample(var,nsample,replace=T) } mean.mat-rep(0,nboot) for(i in

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

Re: [R] Matrix manipulation

2011-04-02 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,

[R] Matrix manipulation

2011-04-01 Thread Joseph N. Paulson
Hi all! I have a vector, let's say for example int - sample(1:20,10); for now: now I have a matrix... M = m x n where the first column is a feature column and most likely shares at least one of the int (interesting) numbers. I want to extract the rows where int[] = M[,1] I thought:

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,] 213

[R] Matrix Manipulation

2010-11-04 Thread emj83
Hi, Is there a quick way to go from this matrix: A [,1] [,2] [,3] [1,]111 [2,]222 [3,]333 [4,]444 [5,]5 NA5 [6,] NA NA6 [7,] NA NA NA to this matrix: B [,1] [,2] [,3] [1,]1 NA NA [2,]2 NA1 [3,]

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

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

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

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