Re: [R] help with creating new variables using a loop

2013-02-09 Thread Uwe Ligges
On 07.02.2013 17:16, christel lacaze wrote: Hi there, I've got a set of 10 numeric variables called Mood1 to Mood10 in a dataset called mood. I'm trying to create a set of 10 new variables called m1 to m10 so that m1=Mood1*1, m2=Mood2*2, etc to m10=Mood10*10 Trawling through the

Re: [R] help with creating new variables using a loop

2013-02-09 Thread arun
Hi,  mood- data.frame(Mood1=1:5,Mood2=6:10,Mood3=11:15) lapply(seq_along(mood),function(i) i*mood[i]) A.K. - Original Message - From: christel lacaze christellac...@hotmail.co.uk To: r-help@r-project.org Cc: Sent: Thursday, February 7, 2013 11:16 AM Subject: [R] help with creating new

Re: [R] help with creating new variables using a loop

2013-02-09 Thread arun
   14     2    120    51 #3    16     3    130    54 #4    18     4    140    57 #5    20     5    150    60 A.K. - Original Message - From: christel lacaze christellac...@hotmail.co.uk To: r-help@r-project.org Cc: Sent: Thursday, February 7, 2013 11:16 AM Subject: [R] help with creating new

[R] help with creating new variables using a loop

2013-02-07 Thread christel lacaze
Hi there, I've got a set of 10 numeric variables called Mood1 to Mood10 in a dataset called mood. I'm trying to create a set of 10 new variables called m1 to m10 so that m1=Mood1*1, m2=Mood2*2, etc to m10=Mood10*10 Trawling through the internet, I eventually tried the following code: for (i

Re: [R] help with creating new variables using a loop

2013-02-07 Thread Barry Rowlingson
On Thu, Feb 7, 2013 at 4:16 PM, christel lacaze christellac...@hotmail.co.uk wrote: Hi there, I've got a set of 10 numeric variables called Mood1 to Mood10 in a dataset called mood. That's where you went wrong in the first place. Don't use variable names for indexing purposes. You should