[R] Reading Matrices

jim holtman jholtman at gmail.com
Wed Aug 1 21:52:07 CEST 2007


If want you want to do is to delete the diagonal values in your
matrix, here is one way of doing it assuming that your matrix is 'x':

# ignore the diagonal value in each column
z <- lapply(1:ncol(x), function(a) x[-a, a])
# put back into a matrix
z <- do.call('cbind', z)



On 8/1/07, Urmi Trivedi <uhtrivedi208 at yahoo.co.in> wrote:
> Dear all,
>
> I have been successful so far in plotting matrices and getting the regression line. But, as the matrices contains values like 1 and 0 (diagonal line) which is actually not needed as they are for the same gene, is creating bias in my regression line. I wish to neglect that part of the matrix and read the rest and plot the matrices again.
>
> I am attaching two matrices here for your reference.
>
> Can anyone please help me regarding that.
>
> Thanks very much.
>
> Urmi
>
>
>
>
> ---------------------------------
>  Get the freedom to save as many mails as you wish. Click here to know how.
> 1       -0.012096       -0.100857       -0.069916       -0.097162       0.007382        0.49239 -0.083894       0.383229        0.122648        -0.133041       0.378121        -0.064975       0.475417        -0.156476       -0.080742
> -0.012096       1       -0.105556       0.113937        -0.092952       0.174718        0.08174 0.064185        -0.004801       0.118615        0.073362        0.025144        -0.051149       0.005549        0.144066        -0.045014
> -0.100857       -0.105556       1       0.048302        -0.065759       -0.021766       -0.089656       -0.026402       -0.187463       0.115297        -0.094202       -0.179138       -0.036165       -0.106557       -0.087692       0.675215
> -0.069916       0.113937        0.048302        1       0.025407        0.016662        0.009761        0.302218        -0.15783        0.004884        -0.0539 0.06716 0.078652        -0.047702       -0.000423       -0.037833
> -0.097162       -0.092952       -0.065759       0.025407        1       -0.018238       -0.087263       0.021593        -0.078723       -0.110616       0.127107        -0.02927        -0.094423       -0.048349       0.019307        -0.05013
> 0.007382        0.174718        -0.021766       0.016662        -0.018238       1       -0.01282        -0.015617       0.084991        -0.061002       -0.017901       -0.02836        -0.023457       0.002727        0.675366        -0.016839
> 0.49239 0.08174 -0.089656       0.009761        -0.087263       -0.01282        1       0.103351        0.545116        0.137995        -0.120075       0.335196        -0.036118       0.454495        -0.186613       -0.069724
> -0.083894       0.064185        -0.026402       0.302218        0.021593        -0.015617       0.103351        1       -0.082256       0.022675        0.029452        0.010494        -0.039677       -0.04907        -0.019435       -0.035206
> 0.383229        -0.004801       -0.187463       -0.15783        -0.078723       0.084991        0.545116        -0.082256       1       0.087963        0.212369        0.413117        -0.03035        0.576147        0.169672        -0.140684
> 0.122648        0.118615        0.115297        0.004884        -0.110616       -0.061002       0.137995        0.022675        0.087963        1       0.066721        0.100693        -0.105733       0.054071        -0.080891       -0.123128
> -0.133041       0.073362        -0.094202       -0.0539 0.127107        -0.017901       -0.120075       0.029452        0.212369        0.066721        1       0.19798 -0.097407       -0.115526       0.167922        -0.058937
> 0.378121        0.025144        -0.179138       0.06716 -0.02927        -0.02836        0.335196        0.010494        0.413117        0.100693        0.19798 1       -0.105542       0.224735        0.079891        -0.165202
> -0.064975       -0.051149       -0.036165       0.078652        -0.094423       -0.023457       -0.036118       -0.039677       -0.03035        -0.105733       -0.097407       -0.105542       1       -0.062121       -0.062172       -0.023992
> 0.475417        0.005549        -0.106557       -0.047702       -0.048349       0.002727        0.454495        -0.04907        0.576147        0.054071        -0.115526       0.224735        -0.062121       1       -0.025131       -0.086425
> -0.156476       0.144066        -0.087692       -0.000423       0.019307        0.675366        -0.186613       -0.019435       0.169672        -0.080891       0.167922        0.079891        -0.062172       -0.025131       1       -0.075676
> -0.080742       -0.045014       0.675215        -0.037833       -0.05013        -0.016839       -0.069724       -0.035206       -0.140684       -0.123128       -0.058937       -0.165202       -0.023992       -0.086425       -0.075676       1
>
> 0       1.701634        1.732966        1.638478        1.804548        1.679982        1.808682        1.907909        1.782082        1.820282        1.393257        1.568896        2.014273        1.40849 1.730805        1.645146
> 1.701634        0       1.166662        1.072174        1.238244        1.113678        1.58344 1.682667        1.55684 1.59504 1.423253        1.961898        2.407275        1.801492        2.123807        2.038148
> 1.732966        1.166662        0       0.548174        0.977588        0.853022        1.614772        1.713999        1.588172        1.626372        1.454585        1.99323 2.438607        1.832824        2.155139        2.06948
> 1.638478        1.072174        0.548174        0       0.8831  0.758534        1.520284        1.619511        1.493684        1.531884        1.360097        1.898742        2.344119        1.738336        2.060651        1.974992
> 1.804548        1.238244        0.977588        0.8831  0       0.728972        1.686354        1.785581        1.659754        1.697954        1.526167        2.064812        2.510189        1.904406        2.226721        2.141062
> 1.679982        1.113678        0.853022        0.758534        0.728972        0       1.561788        1.661015        1.535188        1.573388        1.401601        1.940246        2.385623        1.77984 2.102155        2.016496
> 1.808682        1.58344 1.614772        1.520284        1.686354        1.561788        0       0.477421        1.199876        1.238076        1.530301        2.068946        2.514323        1.90854 2.230855        2.145196
> 1.907909        1.682667        1.713999        1.619511        1.785581        1.661015        0.477421        0       1.299103        1.337303        1.629528        2.168173        2.61355 2.007767        2.330082        2.244423
> 1.782082        1.55684 1.588172        1.493684        1.659754        1.535188        1.199876        1.299103        0       0.823034        1.503701        2.042346        2.487723        1.88194 2.204255        2.118596
> 1.820282        1.59504 1.626372        1.531884        1.697954        1.573388        1.238076        1.337303        0.823034        0       1.541901        2.080546        2.525923        1.92014 2.242455        2.156796
> 1.393257        1.423253        1.454585        1.360097        1.526167        1.401601        1.530301        1.629528        1.503701        1.541901        0       1.653521        2.098898        1.493115        1.81543 1.729771
> 1.568896        1.961898        1.99323 1.898742        2.064812        1.940246        2.068946        2.168173        2.042346        2.080546        1.653521        0       0.988747        1.51847 1.840785        1.755126
> 2.014273        2.407275        2.438607        2.344119        2.510189        2.385623        2.514323        2.61355 2.487723        2.525923        2.098898        0.988747        0       1.963847        2.286162        2.200503
> 1.40849 1.801492        1.832824        1.738336        1.904406        1.77984 1.90854 2.007767        1.88194 1.92014 1.493115        1.51847 1.963847        0       1.054405        0.968746
> 1.730805        2.123807        2.155139        2.060651        2.226721        2.102155        2.230855        2.330082        2.204255        2.242455        1.81543 1.840785        2.286162        1.054405        0       0.722953
> 1.645146        2.038148        2.06948 1.974992        2.141062        2.016496        2.145196        2.244423        2.118596        2.156796        1.729771        1.755126        2.200503        0.968746        0.722953        0
>
> ______________________________________________
> 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
> and provide commented, minimal, self-contained, reproducible code.
>
>


-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list