Message-ID: <1258790673.12056.15.camel@R3-thux>
Date: 2009-11-21T08:04:33Z
From: Bernardo Rangel Tura
Subject: "subset" or "condition" as argument to a function
In-Reply-To: <816b5ce40911201740w29d4b86bi452e0087e57a6dd5@mail.gmail.com>
On Fri, 2009-11-20 at 17:40 -0800, Santosh wrote:
> Dear Rxperts!
>
> I was wondering if it is possible to write a function which can take in
> argument of a subset or condition.. Of course, I am aware of the alternate
> methods like coplot, par.plot, xyplot etc... I am specifically interested in
> using conditions/subsets with "plot"..
>
> A simple fragmented example is shown here..
>
> pltit <- function(y,x,dat,dat1,dat2,sbst) {
> plot(y~x, data=dat, subset=sbst)
> lines(y~x,data=dat1, subset=subst)
> points(y~x,data=dat2,subset=subst)
> }
>
> pltit(profit,weeks,dat=zone1, sbst='group==1&sales>200')
>
> Could you also suggest pointers/references/examples on efficient ways to
> plot simulated data overlaid with observed data?
>
> Have a good weekend!
Hi Santosh,
IMHO your script is
pltit <- function(y,x,dat,dat1,dat2,sbst) {
subs <- subset(dat,sbst)
with(subs,plot(y~x))
subs1 <- subset(dat1,sbst)
with(subs1,lines(y~x))
subs2 <- subset(dat2,sbst)
with(subs2,points(y~x))
}
--
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil