[R] sas to r

Adaikalavan Ramasamy ramasamy at cancer.org.uk
Sat Jul 17 16:59:06 CEST 2004


I am must be a bigger/slower fool to have fallen for April fools trick
in the mid of July !

Sorry Greg for misleading you.


On Sat, 2004-07-17 at 11:43, Uwe Ligges wrote:
> Adaikalavan Ramasamy wrote:
> 
> > On Fri, 2004-07-16 at 23:18, Greg Adkison wrote:
> > 
> >>I would be incredibly grateful to anyone who'll help me translate some 
> >>SAS code into R code.
> > 
> > 
> > Searching for "SAS code OR script OR translate" on
> > http://maths.newcastle.edu.au/~rking/R/ gives a few results, one of
> > which looks promising is
> 
> 
> > http://tolstoy.newcastle.edu.au/R/help/04/04/0009.html and
> 
> I anticipated the above citation from 01 Apr 2004 (hint: 01 April !!!!!)
> when I looked at the thread and realized URLs were cited ...
> 
> Uwe
> 
> 
> > http://tolstoy.newcastle.edu.au/R/help/04/02/0660.html
> > 
> > 
> >>Say for example that I have a dataset named "dat1" that includes five 
> >>variables:  wshed, site, species, bda, and sla.  I can calculate with the 
> >>following SAS code the mean, CV, se, and number of observations of 
> >>"bda" and "sla" for each combination of "wshed," "species," and "site," 
> >>restricting the species considered to only three of several species in 
> >>dat1 (b, c, and p).  Moreover, I can output these calculations and 
> >>grouping variables to a dataset named "dat2" that will reside in RAM 
> >>and include the variables  wshed, site, species, mBdA, msla, cBda, 
> >>sBdA, ssla, nBda, and nsla.
> > 
> > 
> > data(iris)
> > attach(iris)
> > iris[c(1,2,51,52,101,102), ]
> >     Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
> > 1            5.1         3.5          1.4         0.2     setosa
> > 2            4.9         3.0          1.4         0.2     setosa
> > ...
> > 51           7.0         3.2          4.7         1.4 versicolor
> > 52           6.4         3.2          4.5         1.5 versicolor
> > ...
> > 101          6.3         3.3          6.0         2.5  virginica
> > 102          5.8         2.7          5.1         1.9  virginica
> > 
> > 
> >>tapply(Sepal.Length, Species, function(x) c( mean(x), sd(x)/mean(x),
> > 
> > length(x) ))
> > $setosa
> > [1]  5.00600000  0.07041344 50.00000000
> > 
> > $versicolor
> > [1]  5.93600000  0.08695606 50.00000000
> > 
> > $virginica
> > [1]  6.58800000  0.09652089 50.00000000
> > 
> > 
> > 
> >>proc sort data=dat1;
> >>  by wshed site species;
> >>proc means data=dat1 noprint mean cv stderr n;
> >>  by wshed site species;
> >>  where species in ('b', 'c', 'p');
> >>  var BdA sla;
> >>  output out=dat2
> >>    mean=mBdA msla
> >>    cv=cBdA csla
> >>    stderr=sBdA ssla
> >>    n=nBdA nsla;
> >>
> >>Thanks,
> >>Greg
> >>
> >>______________________________________________
> >>R-help at stat.math.ethz.ch mailing list
> >>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> >>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> >>
> > 
> > 
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> 
>




More information about the R-help mailing list