Re: [R] get index of current element in vector
Thanks all, that worked! Yes, it should be for (i in 1:length(a)) a[i]- scalar * a[i] * i And now is... a - a * scalar * seq_along(a) That is almost as cool as the PERL programming language :-) 2012/6/4 Rui Barradas ruipbarra...@sapo.pt Hello, Just learning the alphabet? If yes, there's a difference between 'v' and 'a'. Now more seriously. Your description and your loop don't do the same. Description: vm - scalar * v * seq_along(v) Loop: a - scalar * a Also, seq_along is the way to do it, it works even if length(a) == 0. Hope this helps, Rui Barradas Em 04-06-2012 21:25, Erdal Karaca escreveu: (Just learning R) I have this vector: v- c(1:10) Now, I want to multiply each element of that vector with a scalar value multiplied with its index: vm- v * scalar * indexOfCurrentElementOf_v Is that possible without using a loop? In a loop I would do this: for (i in 1:length(a)) a[i]- scalar * a[i] [[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. [[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] get index of current element in vector
On 05.06.2012 00:36, Erdal Karaca wrote: Thanks all, that worked! Yes, it should be for (i in 1:length(a)) a[i]- scalar * a[i] * i And now is... a- a * scalar * seq_along(a) That is almost as cool as the PERL programming language :-) Almost? Uwe Ligges 2012/6/4 Rui Barradasruipbarra...@sapo.pt Hello, Just learning the alphabet? If yes, there's a difference between 'v' and 'a'. Now more seriously. Your description and your loop don't do the same. Description: vm- scalar * v * seq_along(v) Loop: a- scalar * a Also, seq_along is the way to do it, it works even if length(a) == 0. Hope this helps, Rui Barradas Em 04-06-2012 21:25, Erdal Karaca escreveu: (Just learning R) I have this vector: v- c(1:10) Now, I want to multiply each element of that vector with a scalar value multiplied with its index: vm- v * scalar * indexOfCurrentElementOf_v Is that possible without using a loop? In a loop I would do this: for (i in 1:length(a)) a[i]- scalar * a[i] [[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. [[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-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] get index of current element in vector
Do we need an Obfuscated R contest? On Tue, Jun 5, 2012 at 8:17 AM, Uwe Ligges lig...@statistik.tu-dortmund.de wrote: On 05.06.2012 00:36, Erdal Karaca wrote: Thanks all, that worked! Yes, it should be for (i in 1:length(a)) a[i]- scalar * a[i] * i And now is... a- a * scalar * seq_along(a) That is almost as cool as the PERL programming language :-) Almost? Uwe Ligges 2012/6/4 Rui Barradasruipbarra...@sapo.pt Hello, Just learning the alphabet? If yes, there's a difference between 'v' and 'a'. Now more seriously. Your description and your loop don't do the same. Description: vm- scalar * v * seq_along(v) Loop: a- scalar * a Also, seq_along is the way to do it, it works even if length(a) == 0. Hope this helps, Rui Barradas Em 04-06-2012 21:25, Erdal Karaca escreveu: (Just learning R) I have this vector: v- c(1:10) Now, I want to multiply each element of that vector with a scalar value multiplied with its index: vm- v * scalar * indexOfCurrentElementOf_v Is that possible without using a loop? In a loop I would do this: for (i in 1:length(a)) a[i]- scalar * a[i] [[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. [[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-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 Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ 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] get index of current element in vector
On 05.06.2012 14:46, jim holtman wrote: Do we need an Obfuscated R contest? I already know potential winners Uwe On Tue, Jun 5, 2012 at 8:17 AM, Uwe Ligges lig...@statistik.tu-dortmund.de wrote: On 05.06.2012 00:36, Erdal Karaca wrote: Thanks all, that worked! Yes, it should be for (i in 1:length(a)) a[i]- scalar * a[i] * i And now is... a- a * scalar * seq_along(a) That is almost as cool as the PERL programming language :-) Almost? Uwe Ligges 2012/6/4 Rui Barradasruipbarra...@sapo.pt Hello, Just learning the alphabet? If yes, there's a difference between 'v' and 'a'. Now more seriously. Your description and your loop don't do the same. Description: vm- scalar * v * seq_along(v) Loop: a- scalar * a Also, seq_along is the way to do it, it works even if length(a) == 0. Hope this helps, Rui Barradas Em 04-06-2012 21:25, Erdal Karaca escreveu: (Just learning R) I have this vector: v- c(1:10) Now, I want to multiply each element of that vector with a scalar value multiplied with its index: vm- v * scalar * indexOfCurrentElementOf_v Is that possible without using a loop? In a loop I would do this: for (i in 1:length(a)) a[i]- scalar * a[i] [[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. [[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-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.
[R] get index of current element in vector
(Just learning R) I have this vector: v - c(1:10) Now, I want to multiply each element of that vector with a scalar value multiplied with its index: vm - v * scalar * indexOfCurrentElementOf_v Is that possible without using a loop? In a loop I would do this: for (i in 1:length(a)) a[i] - scalar * a[i] [[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] get index of current element in vector
On Jun 4, 2012, at 4:25 PM, Erdal Karaca wrote: (Just learning R) I have this vector: v - c(1:10) Now, I want to multiply each element of that vector with a scalar value multiplied with its index: vm - v * scalar * indexOfCurrentElementOf_v Almost: vm - v * scalar * seq(v) Is that possible without using a loop? -- David Winsemius, MD West Hartford, CT __ 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] get index of current element in vector
Hello, Just learning the alphabet? If yes, there's a difference between 'v' and 'a'. Now more seriously. Your description and your loop don't do the same. Description: vm - scalar * v * seq_along(v) Loop: a - scalar * a Also, seq_along is the way to do it, it works even if length(a) == 0. Hope this helps, Rui Barradas Em 04-06-2012 21:25, Erdal Karaca escreveu: (Just learning R) I have this vector: v- c(1:10) Now, I want to multiply each element of that vector with a scalar value multiplied with its index: vm- v * scalar * indexOfCurrentElementOf_v Is that possible without using a loop? In a loop I would do this: for (i in 1:length(a)) a[i]- scalar * a[i] [[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-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.