Dear R gurus..
I had tried out some suggestions sent to me privately..and unfortunately,
they did not work..

To use a condiition in a subset, the associated dataframe needs to be
attached and detached, which I found cumbersome to use if using more than 1
dataframe (with different dimensions) with same condition. I would highly
appreciate your suggestions to overcome this problem.. Please see my example
of usage I am trying to implement. Please note that the "cond' takes in the
character instead of logical values...

cond1 <- 'group==1&sales>200'
cond2 <- 'group==2&sales>200'
cond3 <- 'group==3&sales>200'

d1 <- subset(dat,subset=cond1)
plot(y~x,data=dat,subset=cond1,type='b')
lines(y~x,data=dat,subset=cond2)
points(y~x,data=dat,subset=paste(cond1,cond2,sep='&'),col='blue')
points(y~x,data=d1,subset=cond3,col='red')

If I try the above, I get the following error message:
*Error in subset.data.frame(dat, cond) : 'subset' must evaluate to logical*

If you could also suggest references implementing similar code, I would
highly appreciate it.
Thanks so much,

Santosh

On Mon, Nov 23, 2009 at 6:38 PM, Santosh <santosh2...@gmail.com> wrote:

> Thanks... I would try it out..
>  -santosh
>
>
> On Sat, Nov 21, 2009 at 12:04 AM, Bernardo Rangel Tura <
> t...@centroin.com.br> wrote:
>
>> 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!
>>
>>
>>
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to