[19123] in s-news-athena

home help back first fref pref prev next nref lref last post

Re: [S] Question on data manipulation

daemon@ATHENA.MIT.EDU (Prof Brian D Ripley)
Tue Sep 7 02:41:25 1999

Date: Tue, 7 Sep 1999 07:33:49 +0100 (BST)
From: Prof Brian D Ripley <ripley@stats.ox.ac.uk>
To: Scott Saleska <srs@io.harvard.edu>
Cc: Abd Rahman Kassim <rahmank@frim.gov.my>,
        "s-news@wubios.wustl.edu" <s-news@wubios.wustl.edu>
In-Reply-To: <3.0.3.32.19990906222442.009748e0@pop.fas.harvard.edu>
Message-Id: <Pine.GSO.4.05.9909070719001.18557-100000@auk.stats>
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII


On Mon, 6 Sep 1999, Scott Saleska wrote:

> 
> 
> Try this:  
> 
> tapply( tree.dat$DBH, tree.dat$Plot, function(x) { 
> 		y <- rep(0, length(x))
> 		for( i in 1:length(x) ) y[i] <- sum( x[x>x[i]] )
> 		y } 
> 	)
> 
> There is probably also a more elegant way without a loop.

I am not sure what exactly is required: in the example the answers
differ for the two trees of size 10. So I presume the answer is required 
by plot. What would be the answer if there were ties in the tree sizes
in a plot?

Here's a small function to go from DBH to DBHL

lg <- function(x)
{
  ind <- rev(order(x))
  y <- cumsum(x[ind])
  y <- c(0, y[-length(y)])
  x[ind] <- y
  x
}
> lg(c(10, 15, 13, 12))
[1] 40  0 15 28

This does not handle ties, but is faster for large groups.

> 
> At 09:28 AM 9/7/99 +0800, Abd Rahman Kassim wrote:
> >
> >Dear S-plus user,
> >
> >Sorry, I have to send another similar question because I have'nt received 
> >any response yet. I guess my earlier question is not clear and confusing.
> >
> >My question is on how to write S-plus code to calculate the value of 
> > "relative position"  for a particular subject of that variable. For 
> >example,
> >
> >Data file: tree.dat
> >Variables : Plot : Size of the plot
> >                 DBH : Diameter of the subject tree
> >                 DBHL: Total diameter of trees for trees larger than the 
> >subject tree
> >
> >Plot      DBH        DBHL
> >------    ------------    ---------
> >a            10           30   <- 40?
> >a            15            0
> >a            13           15
> >a            12           28
> >b             5            30
> >b            10           13
> >b             7            23
> >b             13           0
> >

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

home help back first fref pref prev next nref lref last post