[R] Help massaging big arrays

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Thu Aug 1 17:17:50 CEST 2002


Philip Rhoades <pri at chu.com.au> writes:

> Hi all,
> 
> I hope someone can give me some quick pointers - it would take me ages
> to work this out from scratch - I want to:
> 
> - From an array - 32 cols x 1000 rows of small floats
> 
> - Produce a second array from the first where the all numbers have an
> abs fn applied to them (to get rid of the neg numbers)
> 
> - Produce a third array from the second where all numbers less than
> 0.0005 are converted to 0.0005
> 
> - Produce a fourth array (5x1000) from the third where the first
> number in the row is the mean of the first two numbers of array #3,
> the second number is the mean of the first 4 numbers, 3rd mean of 8,
> 4th mean of 16, 5th mean of 32
> 
> - Produce a fifth (5x1000) array by dividing array #4 into another
> 5x1000 array
> 
> - Produce 5 means of the 5 columns of array #5


Except for item 4, these are trivial and quite fundamental. You'd be
better off looking into Ch.5 of  "An Introduction to R" than to have
people write down the solution for you.

Item 4 is a little tricky:

sapply(2^(1:5), function(i)apply(m[,1:i],1,mean))

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list