[R] SAS-like method of recoding variables?
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Tue Jun 23 09:15:06 CEST 2009
Dieter Menne wrote:
>
>
> P.Dalgaard wrote:
>>
>>> IF TYPE='TRUCK' and count=12 THEN VEHICLES=TRUCK+((CAR+BIKE)/2.2);
>> vehicles <- ifelse(TYPE=='TRUCK' & count=12, TRUCK+((CAR+BIKE)/2.2), NA)
>>
>>
>
> Read both versions to an audience, and you will have to admit that this is
> one of the cases where SAS is superior.
>
> Dieter
>
>
That's not entirely clear. For instance, SAS is not being clear about
what happens when the condition is FALSE.
SAS is also not distinguishing comparison and assignment, but then again
you don't accidentally do count=12 when you mean count==12....
As a generic matter, SAS (the DATA step) is generally good at things
that are done by sequential sweeps through a data file. The shortcomings
come in when you do things that can't be done sequentially, or require
substantial rearranging of data first. x - ave(x,g,median) is an example
which IIRC requires
proc sort
proc means by group (saving medians to data set)
data step (merge and subtract)
On the third (!) hand, some other things require rethinking in R that
are easily expressed in a sequential setting. "Last observation carried
forward" comes to mind (notwithstanding theoretical issues of that
procedure).
--
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list