Re: [R] Combine by columns a vector with another vector that is constant across rows

2018-07-03 Thread Eric Berger
.davis.ca.us] > >Sent: Tuesday, 03 July, 2018 17:48 > >To: r-help@r-project.org; Viechtbauer, Wolfgang (SP); r-help@r- > >project.org > >Subject: Re: [R] Combine by columns a vector with another vector that is > >constant across rows > > > >Sorry trying ag

Re: [R] Combine by columns a vector with another vector that is constant across rows

2018-07-03 Thread Viechtbauer, Wolfgang (SP)
g >-Original Message- >From: Jeff Newmiller [mailto:jdnew...@dcn.davis.ca.us] >Sent: Tuesday, 03 July, 2018 17:48 >To: r-help@r-project.org; Viechtbauer, Wolfgang (SP); r-help@r- >project.org >Subject: Re: [R] Combine by columns a vector with another vector that is

Re: [R] Combine by columns a vector with another vector that is constant across rows

2018-07-03 Thread Jeff Newmiller
Sorry trying again... fastWolfgang <- function( v, vec ) { matrix( c( v, rep( vec, each = length( v ) ) ) , nrow = length( v ) ) } On July 3, 2018 8:21:47 AM PDT, Jeff Newmiller wrote: >Gabor's solution seems to optimize 'simpler'. > >More efficient is to learn that in R a vector is n

Re: [R] Combine by columns a vector with another vector that is constant across rows

2018-07-03 Thread Gabor Grothendieck
or this variation if you don't want the first column to be named init: Reduce(cbind2, vec, 1:5) On Tue, Jul 3, 2018 at 10:46 AM, Gabor Grothendieck wrote: > Try Reduce: > > Reduce(cbind, vec, 1:5) > > On Tue, Jul 3, 2018 at 9:28 AM, Viechtbauer, Wolfgang (SP) > wrote: >> Hi All, >> >> I have

Re: [R] Combine by columns a vector with another vector that is constant across rows

2018-07-03 Thread Jeff Newmiller
Gabor's solution seems to optimize 'simpler'. More efficient is to learn that in R a vector is not a matrix, but a matrix is just an ornamented vector. fastWolfgang <- function( v, vec ) { matrix( c( v, rep( vec, length( v ) ) ) , now = length( v ) ) } On July 3, 2018 6:28:45 AM PDT,

Re: [R] Combine by columns a vector with another vector that is constant across rows

2018-07-03 Thread Gabor Grothendieck
Try Reduce: Reduce(cbind, vec, 1:5) On Tue, Jul 3, 2018 at 9:28 AM, Viechtbauer, Wolfgang (SP) wrote: > Hi All, > > I have one vector that I want to combine with another vector and that other > vector should be the same for every row in the combined matrix. This > obviously does not work: >

Re: [R] Combine by columns a vector with another vector that is constant across rows

2018-07-03 Thread PIKAL Petr
Viechtbauer, > Wolfgang (SP) > Sent: Tuesday, July 3, 2018 3:29 PM > To: r-help@r-project.org > Subject: [R] Combine by columns a vector with another vector that is constant > across rows > > Hi All, > > I have one vector that I want to combine with another vector and

[R] Combine by columns a vector with another vector that is constant across rows

2018-07-03 Thread Viechtbauer, Wolfgang (SP)
Hi All, I have one vector that I want to combine with another vector and that other vector should be the same for every row in the combined matrix. This obviously does not work: vec <- c(2,4,3) cbind(1:5, vec) This does, but requires me to specify the correct value for 'n' in replicate(): cbi