Re: [R] re stricting points in a data frame

From: Petr PIKAL <petr.pikal_at_precheza.cz>
Date: Thu, 31 Jan 2008 09:10:47 +0100


Maybe what is seeked is rather

between <- function (x,y) x>=range(y)[1] & x<=range(y)[2] A[between(A[,1], x1)& between(A[,2], x2),]

Regards

Petr
petr.pikal_at_precheza.cz

r-help-bounces_at_r-project.org napsal dne 30.01.2008 18:14:55:

> Let's A = expand.grid(xk1=xk1,xk2=xk2)
>
> B = A[A[,1] %in% x1 & A[,2] %in% x2, ]
>
> Should in principle produce the desired result.
>
> Mama
>
>
> -----
> Mama Attiglah, PhD
> Advanced Research Center
> Quantitative Research Analyst
> State Street Bank
> +44(0)20 7698 6290 (Direct Line)
> +44 (0)207 004 2968 (Direct Fax)
> Please visit our Web site at
> www.ssga.com
>
> -----Original Message-----
> From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org]
> On Behalf Of dxc13
> Sent: 30 January 2008 16:20
> To: r-help_at_r-project.org
> Subject: [R] re stricting points in a data frame
>
>
> useR's,
>
> Consider some variables and a data frame of points:
> x1 <- c(1,2,3)
> x2 <- c(3,4,5)
> xk1 <- seq(min(x1)-.5, max(x1)+.5,.5)
> xk2 <- seq(min(x2)-.5, max(x2)+.5,.5)
> expand.grid(xk1=xk1,xk2=xk2)
>
> xk1 xk2
> 1 0.5 2.5
> 2 1.0 2.5
> 3 1.5 2.5
> 4 2.0 2.5
> 5 2.5 2.5
> 6 3.0 2.5
> 7 3.5 2.5
> ...
> 46 2.0 5.5
> 47 2.5 5.5
> 48 3.0 5.5
> 49 3.5 5.5
>
> I want to restrict the data frame to only contain points that are within
> the
> x1 and x2 range. So for this example, only points between 1 and 3
> should be
> kept for x1 and values between 3 and 5 should be kept for x2. This
> condition needs to be satisfied for both points, not just one of them;
> i.e.,
> if an x1 point satisfies this, but its corresponding x2 point does not,
> then
> this point should be removed.
> Does anyone know a way to do this, in general, for any data frame?
> Hope this is not confusing.
> Thanks in advance
> dxc13
> --
> View this message in context:
> http://www.nabble.com/restricting-points-in-a-data-frame-tp15184381p1518
> 4381.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help_at_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.
>
> ______________________________________________
> R-help_at_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.



R-help_at_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. Received on Thu 31 Jan 2008 - 08:15:40 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 31 Jan 2008 - 08:30:09 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive