Dear List,

Im new to R - making a transition from SAS. I have a space delimited file 
with the following structure. Each line in the datafile is identified by 
the first letter. 

A = Inventory (Inventory)
X = Stratum (Stratum_no Total Ye=year established)
P = Plot (Plot_no age slope= species)
T = Tree (tree_no frequency)
L = Leader (leader diameter height)
F = Feature (start_height finish_height feature)

On each of these lines there are some 'line specific' variables (in 
brackets). The data is hierarchical in nature - A feature belongs to a 
leader, a leader belongs to a tree, a tree belongs to a plot, a plot 
belongs to a stratum, a stratum belongs to inventory. There are many 
features in a tree. Many trees in a plot etc. 

In SAS I would read in the data in a procedural way using first. and last. 
variables to work out where inventories/stratums/plots/trees  finished and 
started so I could create summary statistics for each of them. For 
example, how many plots in a stratum? How many trees in a plot? An example 
of the sas code I would (not checked for errors!!!). If anybody could give 
me some idea on what the right approach in R would be for a similar 
analysis it would be greatly appreciated.

regards Andrew


Data datafile;
infile 'test.txt';
input @1 tag $1. @@;
retain inventory stratum plot tree leader;
if tag = 'A' then input @3 inventory $.;
if tag = 'X' then input @3 stratum_no $. total $. yearest $. ;
if tag = 'P' then input @3 plot_no $. age $. slope $. species $;
if tag = 'T' then input @3 tree_no $. frequency  ;
if tag = 'L' then input @3 leader_no $ diameter  height  ;
if tag = 'F' then input @3 start $ finish $ feature $;
if tag = 'F' then output;
run;
proc sort data = datafile;
by inventory stratum_no  plot_no  tree_no  leader_no;

* calculate mean dbh in each plot
data dbh
set datafile;
by inventory stratum_no  plot_no  tree_no leader_no
if first.leader_no then output;

proc summary data = diameter;
by inventory stratum plot tree;
var diameter;
output out = mean mean=;
run;

A BENALLA_1
X 1 10 YE=1985
P 1 20.25 slope=14 SPP:P.RAD
T 1 25
L 0 28.5 21.3528
F 0 21.3528 SFNSW_DIC:P
F 21.3528 100 SFNSW_DIC:P
T 2 25
L 0 32 23.1
F 0 6.5 SFNSW_DIC:A
F 6.5 23.1 SFNSW_DIC:C
F 23.1 100 SFNSW_DIC:C
T 3 25
L 0 39.5 22.2407
F 0 4.7 SFNSW_DIC:A
F 4.7 6.7 SFNSW_DIC:C
P 2 20.25 slope=13 SPP:P.RAD
T 1 25
L 0 38 22.1474
F 0 1 SFNSW_DIC:G
F 1 2.3 SFNSW_DIC:A
T 1001 25
L 0 38 22.1474
F 0 1 SFNSW_DIC:G
F 1 2.3 SFNSW_DIC:A
T 2 25
L 0 32.5 21.7386
F 0 2 SFNSW_DIC:A
F 2 3.3 SFNSW_DIC:G
F 3.3 10.4 SFNSW_DIC:C
X 2 10 YE=1985
P 1 20.25 slope=14 SPP:P.RAD
T 1 25
L 0 28.5 21.3528
F 0 21.3528 SFNSW_DIC:P
F 21.3528 100 SFNSW_DIC:P
T 2 25
L 0 32 23.1
F 0 6.5 SFNSW_DIC:A
F 6.5 23.1 SFNSW_DIC:C
F 23.1 100 SFNSW_DIC:C
T 3 25
L 0 39.5 22.2407
F 0 4.7 SFNSW_DIC:A
F 4.7 6.7 SFNSW_DIC:C
P 2 20.25 slope=13 SPP:P.RAD
T 1 25
L 0 38 22.1474
F 0 1 SFNSW_DIC:G
F 1 2.3 SFNSW_DIC:A
T 1001 25
L 0 38 22.1474
F 0 1 SFNSW_DIC:G
F 1 2.3 SFNSW_DIC:A
T 2 25
L 0 32.5 21.7386
F 0 2 SFNSW_DIC:A
F 2 3.3 SFNSW_DIC:G
F 3.3 10.4 SFNSW_DIC:C




        [[alternative HTML version deleted]]

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to