s-news
[Top] [All Lists]

YADMQ - Yet Another Data Manipulation Question

To: "s-news" <s-news@lists.biostat.wustl.edu>
Subject: YADMQ - Yet Another Data Manipulation Question
From: "Thompson, David (MNR)" <David.John.Thompson@ontario.ca>
Date: Thu, 28 Jun 2007 14:01:49 -0400
Thread-index: Ace5rmWiLqNDjSEQTDC3tP3zZsMvYw==
Thread-topic: YADMQ - Yet Another Data Manipulation Question
Hello,

I have 54 plots (oplt) each containing 10 sub-plots (rplt) within which
stem counts were made for each species found in five height classes. The
data are organized (and I use the term very loosely ;-}) with a species
column (sp1-sp5) for each of the five height class columns (hc1-hc5). I
would like to pool the species codes into a single column (spp) with the
associated stem counts remaining in the hc1-hc5 columns but aligned in
the proper rows. This will expand the existing number of rows. Also,
there is ABSOLUTELY NO form of order in how each element was entered.
And there are many blank cells as only species found in each height
class at each location were recorded.

A sample of the two data arrangements are included below. Suggestions?
Also, would it be possible to generate a solution that would work in
both S and R?

Many thanks in advance, DaveT.

olddat <- data.frame(
rbind( c(1, 1, 'Or', 2, 'Iw', 4, 'Iw', 2, 'Iw', 2, 'He', 2, NA),
        c(1, 1, 'Iw', 2, 'Be', 2, NA, NA, NA, NA, 'Mh', 2, NA),
        c(1, 1, 'Mh', 3, NA, NA, NA, NA, NA, NA, NA, NA, NA),
        c(1, 2, 'Be', 2, 'Iw', 4, 'Iw', 4, 'Iw', 1, 'He', 2, NA),
        c(1, 2, 'Mh', 3, 'Mh', 2, NA, NA, NA, NA, 'Mh', 1, NA),
        c(1, 2, 'Iw', 4, NA, NA, NA, NA, NA, NA, NA, NA, NA),
        c(1, 2, 'Or', 1, NA, NA, NA, NA, NA, NA, NA, NA, NA)))
names(olddat) <- c('oplt', 'rplt', 'sp1', 'hc1', 'sp2', 'hc2', 'sp3',
'hc3', 'sp4', 'hc4', 'sp5', 'hc5', 'com')

newdat <- data.frame(rbind( c(1, 1, 'Or', 2, NA, NA, NA, NA, NA),
        c(1, 1, 'Iw', 2, 4, 2, 2, NA, NA),
        c(1, 1, 'Mh', 3, NA, NA, NA, 2, NA),
        c(1, 1, 'Be', NA, 2, NA, NA, NA, NA),
        c(1, 1, 'He', NA, NA, NA, NA, 2, NA),
        c(1, 2, 'Be', 2, NA, NA, NA, NA, NA),
        c(1, 2, 'Mh', 3, 2, NA, NA, 1, NA),
        c(1, 2, 'Iw', 4, 4, 4, 1, NA, NA),
        c(1, 2, 'Or', 1, NA, NA, NA, NA, NA),
        c(1, 2, 'He', NA, NA, NA, NA, 2, NA)))
names(newdat) <- c('oplt', 'rplt', 'spp', 'hc1', 'hc2', 'hc3', 'hc4',
'hc5', 'com')

> olddat
  oplt rplt sp1 hc1  sp2  hc2  sp3  hc3  sp4  hc4  sp5  hc5  com
1    1    1  Or   2   Iw    4   Iw    2   Iw    2   He    2 <NA>
2    1    1  Iw   2   Be    2 <NA> <NA> <NA> <NA>   Mh    2 <NA>
3    1    1  Mh   3 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
4    1    2  Be   2   Iw    4   Iw    4   Iw    1   He    2 <NA>
5    1    2  Mh   3   Mh    2 <NA> <NA> <NA> <NA>   Mh    1 <NA>
6    1    2  Iw   4 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
7    1    2  Or   1 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
> newdat
   oplt rplt spp  hc1  hc2  hc3  hc4  hc5  com
1     1    1  Or    2 <NA> <NA> <NA> <NA> <NA>
2     1    1  Iw    2    4    2    2 <NA> <NA>
3     1    1  Mh    3 <NA> <NA> <NA>    2 <NA>
4     1    1  Be <NA>    2 <NA> <NA> <NA> <NA>
5     1    1  He <NA> <NA> <NA> <NA>    2 <NA>
6     1    2  Be    2 <NA> <NA> <NA> <NA> <NA>
7     1    2  Mh    3    2 <NA> <NA>    1 <NA>
8     1    2  Iw    4    4    4    1 <NA> <NA>
9     1    2  Or    1 <NA> <NA> <NA> <NA> <NA>
10    1    2  He <NA> <NA> <NA> <NA>    2 <NA>

*************************************
Silviculture Data Analyst
Ontario Forest Research Institute
Ontario Ministry of Natural Resources
david.john.thompson@ontario.ca
http://ofri.mnr.gov.on.ca
*************************************

<Prev in Thread] Current Thread [Next in Thread>
  • YADMQ - Yet Another Data Manipulation Question, Thompson, David (MNR) <=