Your message doesn't help us very much. You haven't said what kind of calculation it is you want to do, and that certainly matters. For example, for some kinds of computations the solution you started below would work fine:> M <- matrix(1:16, 4, 4) > is.na(diag(M)) <- TRUE > M[,1] [,2] [,3] [,4] [1,] NA 5 9 13 [2,] 2 NA 10 14 [3,] 3 7 NA 15 [4,] 4 8 12 NA> rowSums(M, na.rm = TRUE)[1] 27 26 25 24> colSums(M, na.rm = TRUE)[1] 9 20 31 42 You can also use apply( ) with functions that will accept missing values (and ignore them) for computations on either the rows or the columns. Hoping for a general mechanism that would somehow signal the diagonal values as values to be "ignored" in a general way is not a possibility. Just as a curiosity, what were you hoping that na.omit(M) would do? V. -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Asha Jayanthi Sent: Thursday, 31 March 2005 11:22 AM To: r-help at stat.math.ethz.ch Subject: [R] NA's? I have a large matrix of data . The size of the matrix ranges from 100 x 100 to 1000 x 1000 Now i have to do computations on that. And should not consider the diagonal elements. I tried setting diag(M) = NA and M = na.omit(M). But this omits all the rows. I only want to omit that diagonal elements only but consider the whole row. diag(M) = 0 seems like a good option but this will affect my result. How to proceed with this. How to just ignore some specific values. what if i want to consider only the upper / lower triangular matrix Asha http://adfarm.mediaplex.com/ad/ck/4686-26272-10936-31?ck=RegSell Start your business. ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
See upper.tri and lower.tri. I think that you might also look for specific packages that function using matrices, from what I have seen these often have the capacity to ignore the diagonal or use just the upper or lower triangle. This is not an area that I use very much, but I have seen various posts about different types of matrices and there appears to be quite a lot of code that deals with the range of types and uses. Obvious candidates include the Matrix package, but a search for matrix in all of the CRAN packages brings up a bewildering variety of matrix related functions. You may find it useful to search for the specific type of manipulation that you are attempting. Tom> -----Original Message----- > From: Asha Jayanthi [mailto:ashajayanthi at hotmail.com] > Sent: Thursday, 31 March 2005 9:22 AM > To: r-help at stat.math.ethz.ch > Subject: [R] NA's? > > > I have a large matrix of data . > > The size of the matrix ranges from 100 x 100 to 1000 x 1000 > > Now i have to do computations on that. And should not > consider the diagonal > elements. > > I tried setting diag(M) = NA and M = na.omit(M). > > But this omits all the rows. I only want to omit that > diagonal elements only > but consider the whole row. > > diag(M) = 0 seems like a good option but this will affect my result. > > How to proceed with this. How to just ignore some specific > values. what if i > want to consider only the upper / lower triangular matrix > > Asha > > > http://adfarm.mediaplex.com/ad/ck/4686-26272-10936-31?ck=RegSell Start your business. ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
I am sorry about that. I like to do column mean, sd, var as well as kmeans on the matrix does this na.rm = TRUE work for such fuctions and only the diagonal is ignored?>From: <Bill.Venables at csiro.au> >To: <ashajayanthi at hotmail.com>,<r-help at stat.math.ethz.ch> >Subject: RE: [R] NA's? >Date: Thu, 31 Mar 2005 11:42:05 +1000 > >Your message doesn't help us very much. You haven't said what kind of >calculation it is you want to do, and that certainly matters. For >example, for some kinds of computations the solution you started below >would work fine: > > > M <- matrix(1:16, 4, 4) > > is.na(diag(M)) <- TRUE > > M > [,1] [,2] [,3] [,4] >[1,] NA 5 9 13 >[2,] 2 NA 10 14 >[3,] 3 7 NA 15 >[4,] 4 8 12 NA > > rowSums(M, na.rm = TRUE) >[1] 27 26 25 24 > > colSums(M, na.rm = TRUE) >[1] 9 20 31 42 > >You can also use apply( ) with functions that will accept missing values >(and ignore them) for computations on either the rows or the columns. > >Hoping for a general mechanism that would somehow signal the diagonal >values as values to be "ignored" in a general way is not a possibility. >Just as a curiosity, what were you hoping that na.omit(M) would do? > >V. > >-----Original Message----- >From: r-help-bounces at stat.math.ethz.ch >[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Asha Jayanthi >Sent: Thursday, 31 March 2005 11:22 AM >To: r-help at stat.math.ethz.ch >Subject: [R] NA's? > > >I have a large matrix of data . > >The size of the matrix ranges from 100 x 100 to 1000 x 1000 > >Now i have to do computations on that. And should not consider the >diagonal >elements. > >I tried setting diag(M) = NA and M = na.omit(M). > >But this omits all the rows. I only want to omit that diagonal elements >only >but consider the whole row. > >diag(M) = 0 seems like a good option but this will affect my result. > >How to proceed with this. How to just ignore some specific values. what >if i >want to consider only the upper / lower triangular matrix > >Asha > > >http://adfarm.mediaplex.com/ad/ck/4686-26272-10936-31?ck=RegSell Start >your >business. > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! >http://www.R-project.org/posting-guide.htmlhttp://ads.mediaturf.net/event.ng/Type=click&FlightID=17307&AdID=44925&TargetID=9763&Targets=9763&Values=414,868,1093,2385&Redirect=http:%2F%2Fwww.icicibanknripromotions.com%2Fm2i_feb%2Fnri_M2I_feb.jsp%3Fadid%3D44925%26siteid%3D1093%26flightid%3D17307 Get a FREE 30 minute India Calling Card.
i have not answered your query in the last mail. I hoped na.omit(M) will just ingnore the diagonal elements. i learnt by practice that it removes the whole row which has atleast one NA!! (that is not the case in Perl) Since I am bit new to R, i did not knew how to just ignore those elements in R>From: <Bill.Venables at csiro.au> >To: <ashajayanthi at hotmail.com>,<r-help at stat.math.ethz.ch> >Subject: RE: [R] NA's? >Date: Thu, 31 Mar 2005 11:42:05 +1000 > >Your message doesn't help us very much. You haven't said what kind of >calculation it is you want to do, and that certainly matters. For >example, for some kinds of computations the solution you started below >would work fine: > > > M <- matrix(1:16, 4, 4) > > is.na(diag(M)) <- TRUE > > M > [,1] [,2] [,3] [,4] >[1,] NA 5 9 13 >[2,] 2 NA 10 14 >[3,] 3 7 NA 15 >[4,] 4 8 12 NA > > rowSums(M, na.rm = TRUE) >[1] 27 26 25 24 > > colSums(M, na.rm = TRUE) >[1] 9 20 31 42 > >You can also use apply( ) with functions that will accept missing values >(and ignore them) for computations on either the rows or the columns. > >Hoping for a general mechanism that would somehow signal the diagonal >values as values to be "ignored" in a general way is not a possibility. >Just as a curiosity, what were you hoping that na.omit(M) would do? > >V. > >-----Original Message----- >From: r-help-bounces at stat.math.ethz.ch >[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Asha Jayanthi >Sent: Thursday, 31 March 2005 11:22 AM >To: r-help at stat.math.ethz.ch >Subject: [R] NA's? > > >I have a large matrix of data . > >The size of the matrix ranges from 100 x 100 to 1000 x 1000 > >Now i have to do computations on that. And should not consider the >diagonal >elements. > >I tried setting diag(M) = NA and M = na.omit(M). > >But this omits all the rows. I only want to omit that diagonal elements >only >but consider the whole row. > >diag(M) = 0 seems like a good option but this will affect my result. > >How to proceed with this. How to just ignore some specific values. what >if i >want to consider only the upper / lower triangular matrix > >Asha > > >http://adfarm.mediaplex.com/ad/ck/4686-26272-10936-31?ck=RegSell Start >your >business. > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! >http://www.R-project.org/posting-guide.htmlhttp://creative.mediaturf.net/creatives/citibankrca/rca_msntagofline.htm Without minimum balance for 20 yrs!
is.na(diag(M)) <- TRUE cmeans <- colMeans(M, na.rm = TRUE) csd <- apply(M, 2, sd, na.rm = TRUE) cvar <- csd ^2 (or cvar <- apply(M, 2, var, na.rm = TRUE) ) Using 'kmeans' on a matrix but 'ignoring the diagonal entries' just doesn't make sense as it stands, so I can't help you there. V. -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Asha Jayanthi Sent: Thursday, 31 March 2005 3:48 PM To: r-help at stat.math.ethz.ch Subject: RE: [R] NA's? I am sorry about that. I like to do column mean, sd, var as well as kmeans on the matrix does this na.rm = TRUE work for such fuctions and only the diagonal is ignored?>From: <Bill.Venables at csiro.au> >To: <ashajayanthi at hotmail.com>,<r-help at stat.math.ethz.ch> >Subject: RE: [R] NA's? >Date: Thu, 31 Mar 2005 11:42:05 +1000 > >Your message doesn't help us very much. You haven't said what kind of >calculation it is you want to do, and that certainly matters. For >example, for some kinds of computations the solution you started below >would work fine: > > > M <- matrix(1:16, 4, 4) > > is.na(diag(M)) <- TRUE > > M > [,1] [,2] [,3] [,4] >[1,] NA 5 9 13 >[2,] 2 NA 10 14 >[3,] 3 7 NA 15 >[4,] 4 8 12 NA > > rowSums(M, na.rm = TRUE) >[1] 27 26 25 24 > > colSums(M, na.rm = TRUE) >[1] 9 20 31 42 > >You can also use apply( ) with functions that will accept missingvalues>(and ignore them) for computations on either the rows or the columns. > >Hoping for a general mechanism that would somehow signal the diagonal >values as values to be "ignored" in a general way is not a possibility. >Just as a curiosity, what were you hoping that na.omit(M) would do? > >V. > >-----Original Message----- >From: r-help-bounces at stat.math.ethz.ch >[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Asha Jayanthi >Sent: Thursday, 31 March 2005 11:22 AM >To: r-help at stat.math.ethz.ch >Subject: [R] NA's? > > >I have a large matrix of data . > >The size of the matrix ranges from 100 x 100 to 1000 x 1000 > >Now i have to do computations on that. And should not consider the >diagonal >elements. > >I tried setting diag(M) = NA and M = na.omit(M). > >But this omits all the rows. I only want to omit that diagonal elements >only >but consider the whole row. > >diag(M) = 0 seems like a good option but this will affect my result. > >How to proceed with this. How to just ignore some specific values. what >if i >want to consider only the upper / lower triangular matrix > >Asha > > >http://adfarm.mediaplex.com/ad/ck/4686-26272-10936-31?ck=RegSell Start >your >business. > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! >http://www.R-project.org/posting-guide.htmlhttp://ads.mediaturf.net/event.ng/Type=click&FlightID=17307&AdID=44925&T argetID=9763&Targets=9763&Values=414,868,1093,2385&Redirect=http:%2F%2Fw ww.icicibanknripromotions.com%2Fm2i_feb%2Fnri_M2I_feb.jsp%3Fadid%3D44925 %26siteid%3D1093%26flightid%3D17307 Get a FREE 30 minute India Calling Card. ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html