want the piece of the matrix I wanted
1
0
Entering edit mode
yueli7 ▴ 20
@yueli7-8401
Last seen 3.5 years ago
China

Hello,

 

I only want a piece of the matrix, not the whole.

 

I only want the fifth column to the end and the first row to the fourth.

 

That means I only want

 

P

V1 V2 V3

V1 0.3506 0.2943 0.6931

V2 0.7733 0.0383 0.8874

V3 0.4476 0.2438 0.0652

V4 0.1597 0.6114 0.6958

 

 

Thanks in advance for great help!

 

> library("Hmisc")

Loading required package: lattice

Loading required package: survival

Loading required package: Formula

Loading required package: ggplot2

 

Attaching package: ‘Hmisc’

 

The following objects are masked from ‘package:base’:

 

format.pval, units

 

> x<-as.matrix(read.table("tmp01"))

> x

V1 V2 V3 V4

[1,] 1 2 5 4

[2,] 4 4 7 5

[3,] 3 3 2 5

[4,] 3 5 5 3

[5,] 2 4 4 1

> y<-as.matrix(read.table("tmp02"))

> y

V1 V2 V3

[1,] 7 8 1

[2,] 10 1 2

[3,] 7 8 11

[4,] 10 1 3

[5,] 1 3 4

> P<-matrix(0,ncol(x),ncol(y))

> P

[,1] [,2] [,3]

[1,] 0 0 0

[2,] 0 0 0

[3,] 0 0 0

[4,] 0 0 0

> P<-rcorr(x,y)

> P

V1 V2 V3 V4 V1 V2 V3

V1 1.00 0.62 0.27 0.42 0.54 -0.59 0.24

V2 0.62 1.00 0.27 -0.37 0.18 -0.90 -0.09

V3 0.27 0.27 1.00 0.10 0.45 -0.64 -0.85

V4 0.42 -0.37 0.10 1.00 0.73 0.31 0.24

V1 0.54 0.18 0.45 0.73 1.00 -0.23 -0.15

V2 -0.59 -0.90 -0.64 0.31 -0.23 1.00 0.44

V3 0.24 -0.09 -0.85 0.24 -0.15 0.44 1.00

 

n= 5

 

 

P

V1 V2 V3 V4 V1 V2 V3

V1 0.2692 0.6659 0.4822 0.3506 0.2943 0.6931

V2 0.2692 0.6659 0.5436 0.7733 0.0383 0.8874

V3 0.6659 0.6659 0.8745 0.4476 0.2438 0.0652

V4 0.4822 0.5436 0.8745 0.1597 0.6114 0.6958

V1 0.3506 0.7733 0.4476 0.1597 0.7109 0.8040

V2 0.2943 0.0383 0.2438 0.6114 0.7109 0.4595

V3 0.6931 0.8874 0.0652 0.6958 0.8040 0.4595

matrix • 1.1k views
ADD COMMENT
1
Entering edit mode
Axel Klenk ★ 1.0k
@axel-klenk-3224
Last seen 10 hours ago
UPF, Barcelona, Spain

Dear yueli7,

try

P[1:4, 5:7]

or

P[1:4, 5:ncol(P)]

is that what you want? If yes, it is very basic R subsetting and not related to Bioconductor.

It should be asked on StackOverflow or r-help and you may benefit from reading some introduction to R.

Hope this helps.

ADD COMMENT
0
Entering edit mode

Avel Klenk,

 

Thank you so much for your great help!

 

 

 

> library("Hmisc")
Loading required package: lattice
Loading required package: survival
Loading required package: Formula
Loading required package: ggplot2

Attaching package: ‘Hmisc’

The following objects are masked from ‘package:base’:

    format.pval, units

> x <- as.matrix(read.table("tmp01"))
> x
     V1 V2 V3 V4
[1,]  1  2  5  4
[2,]  4  4  7  5
[3,]  3  3  2  5
[4,]  3  5  5  3
[5,]  2  4  4  1
> y <- as.matrix(read.table("tmp02"))
> y
     V1 V2 V3
[1,]  7  8  1
[2,] 10  1  2
[3,]  7  8 11
[4,] 10  1  3
[5,]  1  3  4
> P <- matrix(0, ncol(x), ncol(y))
> P
     [,1] [,2] [,3]
[1,]    0    0    0
[2,]    0    0    0
[3,]    0    0    0
[4,]    0    0    0
> for (i in 1:ncol(x)) {
+  for(j in 1:ncol(y)) {
+ P[i,j] <- rcorr(x[,i],y[,j])$P[1,2]}
+ }
> P
          [,1]       [,2]       [,3]
[1,] 0.3506314 0.29431174 0.69307702
[2,] 0.7732771 0.03833574 0.88741510
[3,] 0.4476207 0.24378172 0.06520707
[4,] 0.1597474 0.61142749 0.69575215
 

 

ADD REPLY

Login before adding your answer.

Traffic: 552 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6