[R] Search values and create a new matrix

David Winsemius dwinsemius at comcast.net
Wed Nov 4 23:23:54 CET 2009


On Nov 4, 2009, at 4:45 PM, Jose Narillos de Santos wrote:

> Hi
>
> You wrotte me in R help and I´m very gratefull.
> I couldn´t reply because an illness.
>
> I writte this to see if you can help to solve. I´m a begginer (I´m  
> 20 years
> old ) but I´m trying to learn more about this program also I´m  
> learning
> Octave.
>
> I need to create a matrix in R whose values depends on the values of  
> other
> matrix. You see:
>
> I have a first "R" matrix whose first row and first colum are a "key/ 
> title"
> in my case numbers. Imagine R has a size N,M
>
> The second matrix  "Z" has an N-1,2  size. In this new matrix the  
> second
> column on Z is equal to the first column on R. The first column has  
> numbers
> "desordered" but that  will appear on the first row on R.
>
>
> Each pair on Z (in example row 2 and colum 2) is a point in R.
>
> I want to create a code that searches the values on each row and  
> colum on Z
> and create a new matrix "F"  whose size is (N-1,1) and whose values  
> are each
> cross value on R.
>
>
> In example:
>
> R=
> 0 12 14 16
> 1  2     3   6
> 2   5     5    2
> 3  6     5   2
>
> Z=
>
> 1  14
> 2   12
> 3   16

 > apply(Z, 1, function(x) R[x[1]+1, which(R[1, ]==x[2]) ] )
[1] 3 5 2

>
> The result should be:
>
> F=
>
> 3
> 5 (point for example is the second row first colum on R)
> 2
>
> You can guide me?
>
> Sorry for all and many thans I´m getting crazy...
>
> In excel there is a function Search H or Search V similar but only on
> dimension not both dimmensions...
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list