[R] Vector from Matrix
David Winsemius
dwinsemius at comcast.net
Fri Jan 29 21:43:38 CET 2010
On Jan 29, 2010, at 11:25 AM, Thiem Alrik wrote:
> Dear Mailing List Members,
>
> the problem I've been grappling with für quite some time now is the
> following:
>
> I have a 100 rows x 200 columns matrix.
>
> data.set <- matrix(rnorm(20000, 100, 200))
I am guessing that you wanted to type:
data.set <- matrix(rnorm(20000), 100, 200)
>
> Now I would like to get a vector of length 100 which collects the
> values from the following procedure:
>
> Take the sum of the minima of the two values from each row of
> columns 1 and 101, and divide it by the sum of column 101.
If so, then this should be step 1:
sum( pmin(data.set[,1], data.set[,101]))/sum(data.set[,101])
> Do the same for column 2 and 102, 3 and 103 and so on.
Perhaps (runs without error but unverified):
sapply(1:100, function(x) sum(pmin(data.set[,x], data.set[,100+x]))/
sum(data.set[,100+x]))
> Thanks a lot for your help.
>
> Alrik
>
> *******************************************
> Alrik Thiem
> Research Assistant
>
> WEC E17
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
More information about the R-help
mailing list