Re: [R] Insert value in a Vector Alternately
How about this: dat-c(0.00377467,0.00377467,0.00377467,0.00380083,0.00380083,0.00380083,0.00380959, + 0.00380959,0.00380959,0.00380083,0.00380083,0.00380083) dat[seq(1, by=3, to=length(dat))] - 0 dat [1] 0. 0.00377467 0.00377467 0. 0.00380083 0.00380083 0. 0.00380959 0.00380959 0. 0.00380083 [12] 0.00380083 On Thu, Feb 19, 2009 at 1:47 AM, Gundala Viswanath gunda...@gmail.com wrote: Hi, I have a vector that look like this: dat V1 V2 V3 V4 V5 V6 0.00377467 0.00377467 0.00377467 0.00380083 0.00380083 0.00380083 V7 V8 V9V10V11V12 0.00380959 0.00380959 0.00380959 0.00380083 0.00380083 0.00380083 what I want to do is to insert 0 (zero) for every 3 position yielding: V1 V2 V3V4 V5V6 V7 V8 0 0.00377467 0.00377467 0.00377467 0 0.00380083 0.00380083 0.00380083 V9 V10 V11V12 V13V14 V15 V16 0 0.00380959 0.00380959 0.00380959 0 .00380083 0.00380083 0.00380083 Is there a quick way to do it in R? - Gundala Viswanath Jakarta - Indonesia __ 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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.
Re: [R] Insert value in a Vector Alternately
Perhaps you can try this, d - c(0.00377467, 0.00377467, 0.00377467, 0.00380083, 0.00380083, 0.00380083, 0.00380959, 0.00380959, 0.00380959, 0.00380083, 0.00380083, 0.00380083) c( t( cbind(matrix(d, ncol=3, byrow=T), 0))) I don't know how to avoid the transpose operation that might slow things down in large cases. Hope this helps, baptiste On 19 Feb 2009, at 12:47, jim holtman wrote: How about this: dat- c (0.00377467,0.00377467,0.00377467,0.00380083,0.00380083,0.00380083,0.00380959 , + 0.00380959,0.00380959,0.00380083,0.00380083,0.00380083) dat[seq(1, by=3, to=length(dat))] - 0 dat [1] 0. 0.00377467 0.00377467 0. 0.00380083 0.00380083 0. 0.00380959 0.00380959 0. 0.00380083 [12] 0.00380083 On Thu, Feb 19, 2009 at 1:47 AM, Gundala Viswanath gunda...@gmail.com wrote: Hi, I have a vector that look like this: dat V1 V2 V3 V4 V5 V6 0.00377467 0.00377467 0.00377467 0.00380083 0.00380083 0.00380083 V7 V8 V9V10V11V12 0.00380959 0.00380959 0.00380959 0.00380083 0.00380083 0.00380083 what I want to do is to insert 0 (zero) for every 3 position yielding: V1 V2 V3V4 V5V6 V7 V8 0 0.00377467 0.00377467 0.00377467 0 0.00380083 0.00380083 0.00380083 V9 V10 V11V12 V13V14 V15 V16 0 0.00380959 0.00380959 0.00380959 0 .00380083 0.00380083 0.00380083 Is there a quick way to do it in R? - Gundala Viswanath Jakarta - Indonesia __ 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ 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.
Re: [R] Insert value in a Vector Alternately
to avoid the transposition you can use rbind(matrix(d, nrow=3), 0) baptiste auguie schrieb: Perhaps you can try this, d - c(0.00377467, 0.00377467, 0.00377467, 0.00380083, 0.00380083, 0.00380083, 0.00380959, 0.00380959, 0.00380959, 0.00380083, 0.00380083, 0.00380083) c( t( cbind(matrix(d, ncol=3, byrow=T), 0))) I don't know how to avoid the transpose operation that might slow things down in large cases. Hope this helps, baptiste On 19 Feb 2009, at 12:47, jim holtman wrote: How about this: dat-c(0.00377467,0.00377467,0.00377467,0.00380083,0.00380083,0.00380083,0.00380959, + 0.00380959,0.00380959,0.00380083,0.00380083,0.00380083) dat[seq(1, by=3, to=length(dat))] - 0 dat [1] 0. 0.00377467 0.00377467 0. 0.00380083 0.00380083 0. 0.00380959 0.00380959 0. 0.00380083 [12] 0.00380083 On Thu, Feb 19, 2009 at 1:47 AM, Gundala Viswanath gunda...@gmail.com wrote: Hi, I have a vector that look like this: dat V1 V2 V3 V4 V5 V6 0.00377467 0.00377467 0.00377467 0.00380083 0.00380083 0.00380083 V7 V8 V9V10V11V12 0.00380959 0.00380959 0.00380959 0.00380083 0.00380083 0.00380083 what I want to do is to insert 0 (zero) for every 3 position yielding: V1 V2 V3V4 V5V6 V7 V8 0 0.00377467 0.00377467 0.00377467 0 0.00380083 0.00380083 0.00380083 V9 V10 V11V12 V13V14 V15 V16 0 0.00380959 0.00380959 0.00380959 0 .00380083 0.00380083 0.00380083 Is there a quick way to do it in R? - Gundala Viswanath Jakarta - Indonesia __ 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ 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. -- Eik Vettorazzi Institut für Medizinische Biometrie und Epidemiologie Universitätsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/42803-8243 F ++49/40/42803-7790 __ 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.
Re: [R] Insert value in a Vector Alternately
2009/2/19 baptiste auguie ba...@exeter.ac.uk Perhaps you can try this, d - c(0.00377467, 0.00377467, 0.00377467, 0.00380083, 0.00380083, 0.00380083, 0.00380959, 0.00380959, 0.00380959, 0.00380083, 0.00380083, 0.00380083) c( t( cbind(matrix(d, ncol=3, byrow=T), 0))) I don't know how to avoid the transpose operation that might slow things down in large cases Like that ? c(rbind(matrix(dat, nrow = 3), 0)) david Hope this helps, baptiste On 19 Feb 2009, at 12:47, jim holtman wrote: How about this: dat-c(0.00377467,0.00377467,0.00377467,0.00380083,0.00380083,0.00380083,0.00380959, + 0.00380959,0.00380959,0.00380083,0.00380083,0.00380083) dat[seq(1, by=3, to=length(dat))] - 0 dat [1] 0. 0.00377467 0.00377467 0. 0.00380083 0.00380083 0. 0.00380959 0.00380959 0. 0.00380083 [12] 0.00380083 On Thu, Feb 19, 2009 at 1:47 AM, Gundala Viswanath gunda...@gmail.com wrote: Hi, I have a vector that look like this: dat V1 V2 V3 V4 V5 V6 0.00377467 0.00377467 0.00377467 0.00380083 0.00380083 0.00380083 V7 V8 V9V10V11V12 0.00380959 0.00380959 0.00380959 0.00380083 0.00380083 0.00380083 what I want to do is to insert 0 (zero) for every 3 position yielding: V1 V2 V3V4 V5V6 V7 V8 0 0.00377467 0.00377467 0.00377467 0 0.00380083 0.00380083 0.00380083 V9 V10 V11V12 V13V14 V15 V16 0 0.00380959 0.00380959 0.00380959 0 .00380083 0.00380083 0.00380083 Is there a quick way to do it in R? - Gundala Viswanath Jakarta - Indonesia __ 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ 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. [[alternative HTML version deleted]] __ 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.
Re: [R] Insert value in a Vector Alternately
actually c(rbind(0,matrix(d, nrow=3))) which has the bonus of giving the desired result ;) baptiste auguie schrieb: Perhaps you can try this, d - c(0.00377467, 0.00377467, 0.00377467, 0.00380083, 0.00380083, 0.00380083, 0.00380959, 0.00380959, 0.00380959, 0.00380083, 0.00380083, 0.00380083) c( t( cbind(matrix(d, ncol=3, byrow=T), 0))) I don't know how to avoid the transpose operation that might slow things down in large cases. Hope this helps, baptiste On 19 Feb 2009, at 12:47, jim holtman wrote: How about this: dat-c(0.00377467,0.00377467,0.00377467,0.00380083,0.00380083,0.00380083,0.00380959, + 0.00380959,0.00380959,0.00380083,0.00380083,0.00380083) dat[seq(1, by=3, to=length(dat))] - 0 dat [1] 0. 0.00377467 0.00377467 0. 0.00380083 0.00380083 0. 0.00380959 0.00380959 0. 0.00380083 [12] 0.00380083 On Thu, Feb 19, 2009 at 1:47 AM, Gundala Viswanath gunda...@gmail.com wrote: Hi, I have a vector that look like this: dat V1 V2 V3 V4 V5 V6 0.00377467 0.00377467 0.00377467 0.00380083 0.00380083 0.00380083 V7 V8 V9V10V11V12 0.00380959 0.00380959 0.00380959 0.00380083 0.00380083 0.00380083 what I want to do is to insert 0 (zero) for every 3 position yielding: V1 V2 V3V4 V5V6 V7 V8 0 0.00377467 0.00377467 0.00377467 0 0.00380083 0.00380083 0.00380083 V9 V10 V11V12 V13V14 V15 V16 0 0.00380959 0.00380959 0.00380959 0 .00380083 0.00380083 0.00380083 Is there a quick way to do it in R? - Gundala Viswanath Jakarta - Indonesia __ 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ 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. -- Eik Vettorazzi Institut für Medizinische Biometrie und Epidemiologie Universitätsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/42803-8243 F ++49/40/42803-7790 __ 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.
Re: [R] Insert value in a Vector Alternately
thanks all for the correction, funny how it's often the complicated solution that comes to mind first. baptiste On 19 Feb 2009, at 13:41, Eik Vettorazzi wrote: actually c(rbind(0,matrix(d, nrow=3))) which has the bonus of giving the desired result ;) baptiste auguie schrieb: Perhaps you can try this, d - c(0.00377467, 0.00377467, 0.00377467, 0.00380083, 0.00380083, 0.00380083, 0.00380959, 0.00380959, 0.00380959, 0.00380083, 0.00380083, 0.00380083) c( t( cbind(matrix(d, ncol=3, byrow=T), 0))) I don't know how to avoid the transpose operation that might slow things down in large cases. Hope this helps, baptiste On 19 Feb 2009, at 12:47, jim holtman wrote: How about this: dat- c (0.00377467,0.00377467,0.00377467,0.00380083,0.00380083,0.00380083,0.00380959 , + 0.00380959,0.00380959,0.00380083,0.00380083,0.00380083) dat[seq(1, by=3, to=length(dat))] - 0 dat [1] 0. 0.00377467 0.00377467 0. 0.00380083 0.00380083 0. 0.00380959 0.00380959 0. 0.00380083 [12] 0.00380083 On Thu, Feb 19, 2009 at 1:47 AM, Gundala Viswanath gunda...@gmail.com wrote: Hi, I have a vector that look like this: dat V1 V2 V3 V4 V5 V6 0.00377467 0.00377467 0.00377467 0.00380083 0.00380083 0.00380083 V7 V8 V9V10V11V12 0.00380959 0.00380959 0.00380959 0.00380083 0.00380083 0.00380083 what I want to do is to insert 0 (zero) for every 3 position yielding: V1 V2 V3V4 V5V6 V7 V8 0 0.00377467 0.00377467 0.00377467 0 0.00380083 0.00380083 0.00380083 V9 V10 V11V12 V13V14 V15 V16 0 0.00380959 0.00380959 0.00380959 0 .00380083 0.00380083 0.00380083 Is there a quick way to do it in R? - Gundala Viswanath Jakarta - Indonesia __ 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ 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. -- Eik Vettorazzi Institut für Medizinische Biometrie und Epidemiologie Universitätsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/42803-8243 F ++49/40/42803-7790 _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ 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.
Re: [R] Insert value in a Vector Alternately
- Original Message - From: baptiste auguie ba...@exeter.ac.uk To: Gundala Viswanath gunda...@gmail.com Cc: r-h...@stat.math.ethz.ch R-help r-h...@stat.math.ethz.ch Sent: Thursday, February 19, 2009 7:12:23 AM GMT -06:00 US/Canada Central Subject: Re: [R] Insert value in a Vector Alternately Perhaps you can try this, d - c(0.00377467, 0.00377467, 0.00377467, 0.00380083, 0.00380083, 0.00380083, 0.00380959, 0.00380959, 0.00380959, 0.00380083, 0.00380083, 0.00380083) c( t( cbind(matrix(d, ncol=3, byrow=T), 0))) I don't know how to avoid the transpose operation that might slow things down in large cases. --- This seems to work: c(0,c(rbind(matrix(d,nrow=3),0))) -- David Winsemius --- Hope this helps, baptiste On 19 Feb 2009, at 12:47, jim holtman wrote: How about this: dat- c (0.00377467,0.00377467,0.00377467,0.00380083,0.00380083,0.00380083,0.00380959 , + 0.00380959,0.00380959,0.00380083,0.00380083,0.00380083) dat[seq(1, by=3, to=length(dat))] - 0 dat [1] 0. 0.00377467 0.00377467 0. 0.00380083 0.00380083 0. 0.00380959 0.00380959 0. 0.00380083 [12] 0.00380083 On Thu, Feb 19, 2009 at 1:47 AM, Gundala Viswanath gunda...@gmail.com wrote: Hi, I have a vector that look like this: dat V1 V2 V3 V4 V5 V6 0.00377467 0.00377467 0.00377467 0.00380083 0.00380083 0.00380083 V7 V8 V9 V10 V11 V12 0.00380959 0.00380959 0.00380959 0.00380083 0.00380083 0.00380083 what I want to do is to insert 0 (zero) for every 3 position yielding: V1 V2 V3 V4 V5 V6 V7 V8 0 0.00377467 0.00377467 0.00377467 0 0.00380083 0.00380083 0.00380083 V9 V10 V11 V12 V13 V14 V15 V16 0 0.00380959 0.00380959 0.00380959 0 .00380083 0.00380083 0.00380083 Is there a quick way to do it in R? - Gundala Viswanath Jakarta - Indonesia __ 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ 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. [[alternative HTML version deleted]] __ 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.
[R] Insert value in a Vector Alternately
Hi, I have a vector that look like this: dat V1 V2 V3 V4 V5 V6 0.00377467 0.00377467 0.00377467 0.00380083 0.00380083 0.00380083 V7 V8 V9V10V11V12 0.00380959 0.00380959 0.00380959 0.00380083 0.00380083 0.00380083 what I want to do is to insert 0 (zero) for every 3 position yielding: V1 V2 V3V4 V5V6 V7 V8 0 0.00377467 0.00377467 0.00377467 0 0.00380083 0.00380083 0.00380083 V9 V10 V11V12 V13V14 V15 V16 0 0.00380959 0.00380959 0.00380959 0 .00380083 0.00380083 0.00380083 Is there a quick way to do it in R? - Gundala Viswanath Jakarta - Indonesia __ 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.
Re: [R] Insert value in a Vector Alternately
Hi Gundala: Below works but I was trying to figure out a way to not have to add the last line and I gave up. dat-c(0.00377467,0.00377467,0.00377467,0.00380083,0.00380083,0.00380083,0.00380959, 0.00380959,0.00380959,0.00380083,0.00380083,0.00380083) # MAKE A TEMPORARY MATRIX temp - matrix(dat,nrow=3) # RBIND THE ZEROS AND MAKE IT A VECTOR withzeros - as.vector(rbind(temp,0)) # TAKE THE LAST ONE OFF withzeros-head(withzeros,-1) On Thu, Feb 19, 2009 at 1:47 AM, Gundala Viswanath wrote: Hi, I have a vector that look like this: dat V1 V2 V3 V4 V5 V6 0.00377467 0.00377467 0.00377467 0.00380083 0.00380083 0.00380083 V7 V8 V9V10V11V12 0.00380959 0.00380959 0.00380959 0.00380083 0.00380083 0.00380083 what I want to do is to insert 0 (zero) for every 3 position yielding: V1 V2 V3V4 V5V6 V7 V8 0 0.00377467 0.00377467 0.00377467 0 0.00380083 0.00380083 0.00380083 V9 V10 V11V12 V13V14 V15 V16 0 0.00380959 0.00380959 0.00380959 0 .00380083 0.00380083 0.00380083 Is there a quick way to do it in R? - Gundala Viswanath Jakarta - Indonesia __ 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. __ 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.