[19122] in s-news-athena
Re: [S] Question on data manipulation
daemon@ATHENA.MIT.EDU (Scott Saleska)
Mon Sep 6 22:40:52 1999
Message-Id: <3.0.3.32.19990906222442.009748e0@pop.fas.harvard.edu>
Date: Mon, 06 Sep 1999 22:24:42 -0400
To: Abd Rahman Kassim <rahmank@frim.gov.my>,
"s-news@wubios.wustl.edu" <s-news@wubios.wustl.edu>
From: Scott Saleska <srs@io.harvard.edu>
In-Reply-To: <01BEF913.54643220.rahmank@frim.gov.my>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
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.
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
>a 15 0
>a 13 15
>a 12 28
>b 5 30
>b 10 13
>b 7 23
>b 13 0
>
>In this example, my question is how to write S-plus code, to calculate the
>value of DBHL.
>I am using S-plus for Windows Version 4.5 Rel. 2.
>
>The solution should be simple, I suppposed. But I don't have a clue. Any
>help would be much appreciated.
>
>
>Abd Rahman
>Hill Forest Silviculture
>FRIM
>
>
>
>-----------------------------------------------------------------------
>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
>
********
Scott R. Saleska, Ph.D.
Harvard University
Department of Earth and Planetary Sciences and
Division of Engineering and Applied Sciences
20 Oxford Street
Cambridge, MA 02138
617-495-9624 (voice)
617-495-2768 (fax)
-----------------------------------------------------------------------
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