Re: [R] Using a loop to define new variables

2010-05-28 Thread Gabor Grothendieck
Although you asked for a loop this may be clearer if you just have to do it once and only have 10 x and 10 y columns. Here we use the built in anscombe data frame which has columns x1, x2, x3, x4, y1, y2, y3, y4: transform(anscombe, r1 = y1 / x1, r2 = y2 / x2, r3 = y3 / x3, r4 = y4 / x4) In th

Re: [R] Using a loop to define new variables

2010-05-28 Thread Barry Rowlingson
On Fri, May 28, 2010 at 12:52 PM, Andre Easom wrote: > Hi, > > I'm a novice R user, much more used to SAS.  My problem is pretty simple - > basically, in a data frame, I have variables named > x1,,x10 and y1,...,y10; and I would like to create r1 = x1 / y1 etc > > Apologies if this is way too

Re: [R] Using a loop to define new variables

2010-05-28 Thread Ivan Calandra
Sorry, I should have written it an other way: test$z <- test[[2]]/test[[3]] Which is then really easy to fit into a for loop Ivan Le 5/28/2010 14:05, Ivan Calandra a écrit : Hi, Would this do: test <- data.frame(a=LETTERS[1:10], x=1:10, y=seq(0.1,1,0.1)) #create some data.frame test$z <- te

Re: [R] Using a loop to define new variables

2010-05-28 Thread Ivan Calandra
Hi, Would this do: test <- data.frame(a=LETTERS[1:10], x=1:10, y=seq(0.1,1,0.1)) #create some data.frame test$z <- test$x/test$y #add a column ? HTH, Ivan Le 5/28/2010 13:52, Andre Easom a écrit : Hi, I'm a novice R user, much more used to SAS. My problem is pretty simple - basically, in

[R] Using a loop to define new variables

2010-05-28 Thread Andre Easom
Hi, I'm a novice R user, much more used to SAS. My problem is pretty simple - basically, in a data frame, I have variables named x1,,x10 and y1,...,y10; and I would like to create r1 = x1 / y1 etc Apologies if this is way too rudimentary - but I couldn't find any posts online which solve t