[R] re stricting points in a data frame

Attiglah, Mama Mama_Attiglah at ssga.com
Wed Jan 30 18:14:55 CET 2008


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.



More information about the R-help mailing list