On 06/15/2012 08:13 AM, Peter Houk wrote:
Greetings -

I have a question regarding a relatively simple data transformation, and
wondering if it can be automated in R (or any other platform).  For large
input datasets with numeric density and size, is there a function that can
reformat the data into a single vector for statistical analyses?

For instance, for the two column dataset:

   numeric density size  5 5  4 8  3 9  4 10

How could the following output vector be automated:


  size  5  5  5  5  5  8  8  8  8  9  9  9  10  10  10  10

mat=matrix(c(5,5,4,8,3,9,4,10), ncol=2, byrow=T)

rep(mat[,2], mat[,1])

Last, what if there was a third column for 'location', and the desired
output would be a single vector for each location?

mat2=matrix(c(5,5,1, 4,8,1, 3,9,2, 4,103, ), ncol=3, byrow=T)

by(mat2, list(factor(mat2[,3])), function(A) rep(A[,2], A[,1]) )

And use str() to check the by() object and extract what you want.

Bob

--
Bob O'Hara

Biodiversity and Climate Research Centre
Senckenberganlage 25
D-60325 Frankfurt am Main,
Germany

Tel: +49 69 798 40226
Mobile: +49 1515 888 5440
WWW:   http://www.bik-f.de/root/index.php?page_id=219
Blog: http://blogs.nature.com/boboh
Journal of Negative Results - EEB: www.jnr-eeb.org

Reply via email to