Re: [R] Subtracting elements of a vector from each other stepwise

2013-09-13 Thread Michael Budnick
, September 10, 2013 5:39 PM Subject: Re: [R] Subtracting elements of a vector from each other stepwise arun smartpink111 at yahoo.com writes: Hi, Not sure this is what you wanted: sapply(seq_along(x), function(i) {x1- x[i]; x2- x[-i]; x3-x2[which.min(abs(x1-x2))];c(x1,x3

Re: [R] Subtracting elements of a vector from each other stepwise

2013-09-12 Thread Ben Bolker
On 13-09-11 07:06 PM, Ben Harrison wrote: If I were Michael (OP) right now, I think my head would be spinning. As a newbie myself, I know how hard it is to read R code for the first time, so could it also be part of the newsgroup etiquette to at least partially explain provided code to

Re: [R] Subtracting elements of a vector from each other stepwise

2013-09-11 Thread Ben Harrison
of a vector from each other stepwise arun smartpink111 at yahoo.com writes: Hi, Not sure this is what you wanted: sapply(seq_along(x), function(i) {x1- x[i]; x2- x[-i]; x3-x2[which.min(abs(x1-x2))];c(x1,x3)}) # [,1] [,2] [,3] [,4] #[1,] 17 19 23 29 #[2,] 19 17 19 23 A.K

Re: [R] Subtracting elements of a vector from each other stepwise

2013-09-11 Thread Jeff Newmiller
elements of a vector from each other stepwise arun smartpink111 at yahoo.com writes: Hi, Not sure this is what you wanted: sapply(seq_along(x), function(i) {x1- x[i]; x2- x[-i]; x3-x2[which.min(abs(x1-x2))];c(x1,x3)}) # [,1] [,2] [,3] [,4] #[1,] 17 19 23 29 #[2,] 19 17

Re: [R] Subtracting elements of a vector from each other stepwise

2013-09-10 Thread arun
...@stat.math.ethz.ch Cc: Sent: Tuesday, September 10, 2013 5:39 PM Subject: Re: [R] Subtracting elements of a vector from each other stepwise arun smartpink111 at yahoo.com writes: Hi, Not sure this is what you wanted:  sapply(seq_along(x), function(i) {x1- x[i]; x2- x[-i]; x3-x2[which.min(abs

Re: [R] Subtracting elements of a vector from each other stepwise

2013-09-10 Thread Ben Bolker
...@stat.math.ethz.ch Cc: Sent: Tuesday, September 10, 2013 5:39 PM Subject: Re: [R] Subtracting elements of a vector from each other stepwise arun smartpink111 at yahoo.com writes: Hi, Not sure this is what you wanted: sapply(seq_along(x), function(i) {x1- x[i]; x2- x[-i]; x3-x2[which.min

Re: [R] Subtracting elements of a vector from each other stepwise

2013-09-10 Thread Ben Bolker
arun smartpink111 at yahoo.com writes: Hi, Not sure this is what you wanted:  sapply(seq_along(x), function(i) {x1- x[i]; x2- x[-i]; x3-x2[which.min(abs(x1-x2))];c(x1,x3)}) # [,1] [,2] [,3] [,4] #[1,]   17   19   23   29 #[2,]   19   17   19   23 A.K. It's a little inefficient

Re: [R] Subtracting elements of a vector from each other stepwise

2013-09-10 Thread arun
Hi, Not sure this is what you wanted:  sapply(seq_along(x), function(i) {x1- x[i]; x2- x[-i]; x3-x2[which.min(abs(x1-x2))];c(x1,x3)}) # [,1] [,2] [,3] [,4] #[1,]   17   19   23   29 #[2,]   19   17   19   23 A.K. - Original Message - From: Michael Budnick mbudnic...@snet.net To: