s-news
[Top] [All Lists]

FW: [S] Question on data manipulation

To: "'s-news@wubios.wustl.edu'" <s-news@wubios.wustl.edu>
Subject: FW: [S] Question on data manipulation
From: Abd Rahman Kassim <rahmank@frim.gov.my>
Date: Wed, 31 May 2000 17:27:34 +0800
Sender: owner-s-news@wubios.wustl.edu
Dear S-Plus user,

Sorry for posting this question, I've found the answer after several more trial 
using the following command;

tapply(species,family,function(x) length(unique(x)))

Abd Rahman

-----Original Message-----
From:   Abd Rahman Kassim [SMTP:rahmank@frim.gov.my]
Sent:   Wednesday, May 31, 2000 4:42 PM
To:     s-news@wubios.wustl.edu
Subject:        [S] Question on data manipulation


Dear S-Plus user,

I have a data set with 7000 records containing the following variables; 
size, species name, and  family name of trees in the forest. Most family 
has more than one species. I am trying to calculate the number of 
individual and number of species in each, but only succeed for the first 
calculation (i.e. number of trees by family using the tapply command).

for example;

attach(file.dat)
tapply( size,family,length)

For the second calculation, I would like to find the number of unique 
species present in each family.
The command tapply(species,family,length) showed the total number of 
species which include repeated species name.  I've browsed  unique command 
in help page, with the thought that by creating another file containing 
unique species along with other variables, i.e. family and size. Then use 
tapply to create the required data output.But the unique command only apply 
to a vector instead of a data frame.  Is this correct? How can I subset a 
data frame which will produce the unique species and related family 
variable?

I've also tried using the following command but the results is not what I 
expected.

tapply(unique(spp),family[unique(spp)] ,length)

Any assistance would be appreciated. Thanks.

Abd Rahman Kassim
Hill Forest Silviculture
Forest Research Institute Malaysia (FRIM)
Kepong 52109
Kuala Lumpur

-----------------------------------------------------------------------
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

-----------------------------------------------------------------------
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

<Prev in Thread] Current Thread [Next in Thread>