[R] Conditional plot length in R

David Winsemius dwinsemius at comcast.net
Fri May 6 20:34:56 CEST 2011


On May 6, 2011, at 2:28 PM, Pavan G wrote:

> Hello All,
> Let's say I have data spanning all quadrants of x-y plane. If I plot  
> data
> with a certain x and y range using xlim and ylim or by using  
> plot.formula as
> described in this link:
> http://www.mathkb.com/Uwe/Forum.aspx/statistics/5684/plotting-in-R
>
> *DF <- data.frame(x = rnorm(1000), y = rnorm(1000))
>
> *
> *> str(DF)*
> *'data.frame':   1000 obs. of  2 variables:
> $ x: num  -0.0265  0.1554 -0.1050 -0.9697 -0.3430 ...
> $ y: num   1.386 -1.356 -1.170  0.426  0.204 ...
>
> Now, let's plot the data meeting the criteria you indicated above:
>
> plot(y ~ x, data = DF, subset = (x > 0) & (y > 0))*
>
> How then can I get the length of that data? If have 1000 data points  
> and 200
> lie in x,y>0, how do I find that the length is 200?

with(DF, sum((x > 0) & (y > 0), na.rm=TRUE) )  # since it is 1 for  
TRUE and 0 for false after coercion.

-- 
David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list