[R] Plotting a simple subset

Peter Wolf s-plus at wiwi.uni-bielefeld.de
Fri Jul 8 18:24:41 CEST 2005


Michael Hopkins wrote:

>Hi all
>
>Just converting from Stata to R and struggling a little to come to terms
>with the new philosophy/command line.
>
>E.g. I want to plot x against y if x < 5
>
>In Stata: graph x y, if( x < 5 )
>
>How do I do this in R?  Have tried most of the obvious options without
>success.
>
>Can I have multiple subsets? I.e. In Stata: if( x < 5 && y > 3 )
>

Try:

x<-rnorm(20,0,5)
y<-2*x+rnorm(20)
# plot without condition
plot(x,y)
# some conditions on x and y
index<- x<5 & y>3
plot(x[index],y[index])

Peter Wolf

>
>TIA 
>
>Michael
>
>
>_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
>
>        _/    _/   _/_/_/             Hopkins Research Ltd
>       _/    _/   _/    _/
>      _/_/_/_/   _/_/_/          http://www.hopkins-research.com/
>     _/    _/   _/   _/
>    _/    _/   _/     _/               'touch the future'
>                   
>_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://stat.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