Re: [R] vector manipulations -- differences

2015-09-22 Thread Frank Schwidom
And if we want to use the approach of William Dunlap for sequence.optimization , then we can write: rev( xr[ seq_len(sum(vec)) - rep.int(cumsum(c(0L, vec[-length(vec)])), vec)] - rep.int( xr[ -1], vec)) Regards. On 2015-09-22 23:43:10, Frank Schwidom wrote: > Hi, > > xr <- rev( x) > vec <- 1:

Re: [R] vector manipulations -- differences

2015-09-22 Thread Frank Schwidom
Hi, xr <- rev( x) vec <- 1:(length( x) - 1) rev( xr[ sequence( vec)] - rep.int( xr[ -1], vec)) On 2015-09-21 14:17:40, Dan D wrote: > I need an efficient way to build a new n x (n-1)/2 vector from an n-vector x > as: > > c(x[-1]-x[1], x[-(1:2)]-x[2], ... , x[-(1:(n-1)] - x[n-1]) > > x is incre

Re: [R] vector manipulations -- differences

2015-09-21 Thread Bert Gunter
Use ?mappy and ?rep.int > x[unlist(mapply(":",2:4,4))] - x[rep.int(1:3,3:1)] [1] 3 7 20 4 17 13 Cheers, Bert Bert Gunter "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." -- Clifford Stoll On Mon, Sep 21, 2015 at 2:17 PM, Dan D wrote: > I

[R] vector manipulations -- differences

2015-09-21 Thread Dan D
I need an efficient way to build a new n x (n-1)/2 vector from an n-vector x as: c(x[-1]-x[1], x[-(1:2)]-x[2], ... , x[-(1:(n-1)] - x[n-1]) x is increasing with x[1] = 0. The following works but is not the greatest: junk<-outer(x, x, '-') junk[junk>0] e.g., given x<-c(0, 3, 7, 20) junk<-outer

Re: [R] Vector manipulations

2011-03-02 Thread Benjamin Hartley
he room still a room when its empty? Does the room, > the thing itself have purpose? Or do we, what's the word... imbue it." > - Jubal Early, Firefly > > r-help-boun...@r-project.org wrote on 03/02/2011 10:42:12 AM: > > > [image removed] > > > > [

Re: [R] Vector manipulations

2011-03-02 Thread Jonathan P Daily
/02/2011 10:42:12 AM: > [image removed] > > [R] Vector manipulations > > Benjamin Hartley > > to: > > r-help > > 03/02/2011 11:08 AM > > Sent by: > > r-help-boun...@r-project.org > > I have a question regarding the most efficient way to

Re: [R] Vector manipulations

2011-03-02 Thread Ista Zahn
Hi Benjamin, There may be faster ways, but v <- 1:100 x <- 10 n <- which(cumsum(v) == x) w <- v[1:n] seems pretty straightforward. Best, Ista On Wed, Mar 2, 2011 at 10:42 AM, Benjamin Hartley wrote: > I have a question regarding the most efficient way to select a substring of > a vector: > > I

[R] Vector manipulations

2011-03-02 Thread Benjamin Hartley
I have a question regarding the most efficient way to select a substring of a vector: I have a vector of value v, and I want to select a subspace of this vector called w such that: w=v[1:n] where sum(w) = x I am interested in what you thing would be the most efficient way to do this - I would

Re: [R] vector manipulations

2008-03-05 Thread Pete Dorothy
ro.au/bill.venables/ > > -Original Message- > > From: Duncan Murdoch [mailto:[EMAIL PROTECTED] > Sent: Wednesday, 5 March 2008 9:36 AM > To: Venables, Bill (CMIS, Cleveland) > Cc: r-help@r-project.org > Subject: Re: [R] vector manipulations > > On 3/4/2008 5:41 PM,

Re: [R] vector manipulations

2008-03-04 Thread Bill.Venables
://www.cmis.csiro.au/bill.venables/ -Original Message- From: Duncan Murdoch [mailto:[EMAIL PROTECTED] Sent: Wednesday, 5 March 2008 9:36 AM To: Venables, Bill (CMIS, Cleveland) Cc: r-help@r-project.org Subject: Re: [R] vector manipulations On 3/4/2008 5:41 PM, [EMAIL PROTECTED] wrote: > Your problem

Re: [R] vector manipulations

2008-03-04 Thread Duncan Murdoch
On 3/4/2008 5:41 PM, [EMAIL PROTECTED] wrote: > Your problem is that your function log1( , ) is not vectorized with > respect to its arguments. For a function to work in outer(...) it must > accept vectors for its first two arguments and it must produce a > parallel vector of responses. > > To

Re: [R] vector manipulations

2008-03-04 Thread Bill.Venables
700 mailto:[EMAIL PROTECTED] http://www.cmis.csiro.au/bill.venables/ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Pete Dorothy Sent: Wednesday, 5 March 2008 3:38 AM To: r-help@r-project.org Subject: [R] vector manipulations Hello, I have simulated a set of

Re: [R] vector manipulations

2008-03-04 Thread Pete Dorothy
Thank you very much to both of you, and especially you Phil. I will tell you if it works. 2008/3/4, Phil Spector <[EMAIL PROTECTED]>: > > Pete - > As others have told you, outer only works with vectorized > functions. An alternative is to use expand.grid to find all > the combinations of bet

Re: [R] vector manipulations

2008-03-04 Thread Erik Iverson
Did you read the help page for 'outer'? ?outer It says 'FUN' is called with these two extended vectors as arguments. Therefore, it must be a vectorized function (or the name of one), expecting at least two arguments. I don't think your logl function is vectorized according to

[R] vector manipulations

2008-03-04 Thread Pete Dorothy
Hello, I have simulated a set of data which i called "nir" (a vector). I have created a function "logl" which calculates the log-likelihood. logl is a function of 2 real parameters : "beta" and "zeta" (of length 1). This function works perfectly well when I try for example "logl(0.1,0.2)" Now