Bill Dunlap sent me a couple of more compact versions and perhaps forgot the hit "reply all":

 Data[ Data[,1]^2 + Data[,2]^2 >= 49, , drop=FALSE]

And a second one that handles higher dimensions than 2, still with and L2 metric:

 Data[ rowSums(Data^2)>49, , drop=FALSE]

--
David Winsemius

On Nov 23, 2009, at 6:13 PM, David Winsemius wrote:


On Nov 23, 2009, at 2:57 PM, sandsky wrote:


Hello,

Considering 5 points in X-Y plain. Data is a 5*2 matrix (5 rows for samples
& 2 columns for X and Y)
With a distance from the origin, if a distance < 7, remove the row from the
Data.

After calculating the distance for each point, I can't forward because of
this "Removing" problem.

Anyone can help me?


Data=matrix(1:10,5,2)

> Data[apply(Data, 1, function(x) sqrt(x[1]^2+x[2]^2)>=7), ]
    [,1] [,2]
[1,]    2    7
[2,]    3    8
[3,]    4    9
[4,]    5   10


a=rep(0,5);
b=rep(0,5);

for (i in 1:5))
{
   for (k in 1:2)
   {    
      a[i,k]=a[i,k]+(Data[i,k])^2
   }
   b[i,j]=(a[i,j])^0.5   # distance from the origin
}       


Thank you,

Jin
        


--
View this message in context: 
http://old.nabble.com/Removing-rows-which-do-not-satisfy-a-condition-tp26484778p26484778.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

______________________________________________
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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

______________________________________________
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