Re moving rows which do not satisfy a condition
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 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.
David Winsemius, MD Heritage Laboratories West Hartford, CT