Hello All,
As I mentioned before, I am new to R and I am trying to mimic the tasks that I can easily be done in SAS with R.
Here is another example:
In SAS I wrote these lines:
data viscdaib_;
merge viscdaib(where=(paramcd="T_CDAI") rename=(aval=cdaib) keep= usubjid paramcd aval trtn)
viscdaib(where=(paramcd="I_NLVSS") rename=(aval=sfb) keep= usubjid paramcd aval trtn)
viscdaib(where=(paramcd="I_APSS") rename=(aval=apb) keep= usubjid paramcd aval trtn);
by usubjid;
sfb=round(sfb/7,.1);
apb=round(apb/7,.1);
run;
Here I am creating 'a' dataset viscdaib_ from viscdaib by merging three datasets where the paramcd are distinct, renaming the aval variable into relevant variable names, keeping only the needed variables and calculating sfb and apb - A simple task accomplished in one data step.
With R, what I can do using filter(), rename() and select() functions:
Rename and calculate sfb and apb
cdaib <- visdatab |> filter(paramcd=="T_CDAI") |> rename(cdaib=aval) |> select(usubjid, paramcd, trtn, cdaib)
sfb <- visdatab |> filter(paramcd=="I_NLVSS") |> rename(sfb=aval/7) |> select(usubjid, paramcd, trtn, sfb)
apb <- visdatab |> filter(paramcd=="I_APSS") |> rename(apb=aval/7) |> select(usubjid, paramcd, trtn, apb)
These created three additional data and I did piping to go from one dataset to another.
Questions to the Gurus:
-
Is there any simpler way to accomplish this by combining all these functions and not creating three different dataset?
-
If not, I also need to merge these three data together by usubjid. That will create another dataset and I do not yet know how to merge three datasets.
I can always write my own functions but asking the if there is a simpler way to do that with already built functions.
Thanks in advanced.
Sharif