Re: [R] Need some help in R : value more than equals to a row.

2009-06-07 Thread Gabor Grothendieck
Try this:

t(apply(m, 1, function(x) colMeans(outer(x, x, ">="


On Sun, Jun 7, 2009 at 10:09 AM, suparna
mitra wrote:
> Hallo,
>  I was trying some code, but couldn't make one step of the code properly.
> Can anybody  please  help me?
>
> I have one matrix like this
>> values
>          [,1]       [,2]       [,3]      [,4]      [,5]
> [1,] 0.778 0.3611 0. 0.139 0.000
> [2,] 1.000 0. 0.53846154 0.000 0.5384615
> [3,] 0.520 0.4800 0.6400 0.000 0.880
> [4,] 0.8928571 1. 0. 0.8928571 0.1071429
>
>
> And I want to get some matrix like:
>> values.new
>      [,1]  [,2]  [,3]  [,4]  [,5]
> [1,] 0.2  0.4  0.6  0.8  1.0
> [2,] 0.2  1.0  0.6  1.0  0.6
> [3,] 0.6  0.8  0.4  1.0  0.2
> [4,] 0.6  0.2  1.0  0.6  0.8
>
>
> This table should be computed by taking proportion of values in the row that
> are larger or equals to the value being considered with the total no of
> objects in the row.
>
> for example
>> values[1,2]
> [1] 0.361
> and
>> values[1,]
> [1] 0.778 0.361 0.222 0.139 0.000 0.861
> So there are two numbers more than equals to values[1,2]
> So
>> values.new[1,2]= 2/length(values[1,])
>
>
>
> With best regard,
> Suparna
> 
> Ms Suparna Mitra
> Eberhard-Karls-Universität Tübingen
> Wilhelm-Schickard-Institut
> Algorithmen der Bioinformatik
> Sand 14, 72076 Tuebingen
> Germany
> Tel. ++49-7071-29 70453 (0)
> Fax ++49-7071-29 5148 (0)
> Phone: ++49-176-20361469 (M)
>            ++49-7071-1477169 (R)
> Alternative e-mail: mi...@informatik.uni-tuebingen.de
>
>        [[alternative HTML version deleted]]
>
>
> __
> R-help@r-project.org 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.
>
>

__
R-help@r-project.org 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.


Re: [R] Need some help in R : value more than equals to a row.

2009-06-07 Thread Jakson Alves de Aquino
suparna mitra wrote:
> Hallo,
>  I was trying some code, but couldn't make one step of the code properly.
> Can anybody  please  help me?
> 
> I have one matrix like this
>> values
>   [,1]   [,2]   [,3]  [,4]  [,5]
> [1,] 0.778 0.3611 0. 0.139 0.000
> [2,] 1.000 0. 0.53846154 0.000 0.5384615
> [3,] 0.520 0.4800 0.6400 0.000 0.880
> [4,] 0.8928571 1. 0. 0.8928571 0.1071429
> 
> 
> And I want to get some matrix like:
>> values.new
>   [,1]  [,2]  [,3]  [,4]  [,5]
> [1,] 0.2  0.4  0.6  0.8  1.0
> [2,] 0.2  1.0  0.6  1.0  0.6
> [3,] 0.6  0.8  0.4  1.0  0.2
> [4,] 0.6  0.2  1.0  0.6  0.8
> 
> 
> This table should be computed by taking proportion of values in the row that
> are larger or equals to the value being considered with the total no of
> objects in the row.

I think the code below do what you want, but I would like to know how to
do it with one of the *apply functions:

m <- read.table(stdin(), header=F)
0.778 0.3611 0. 0.139 0.000
1.000 0. 0.53846154 0.000 0.5384615
0.520 0.4800 0.6400 0.000 0.880
0.8928571 1. 0. 0.8928571 0.1071429

m <- as.matrix(m)
bdim <- dim(m)
m2 <- m
for(i in 1:bdim[1])
  for(j in 1:bdim[2])
m2[i,j] <- sum(m[i,j] <= m[i,]) / bdim[2]
m2

__
R-help@r-project.org 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.