[R] If...while...or what else??

2009-01-13 Thread Niccolò Bassani
Dear R users,I come to you with a quite silly question I think, but I hope you can answer me... That is, I've got some problems in using the if and while conditions in a loop. Substantially, I want to select rows in a dataset depending on an index variable (suppose it ranges from 1 to 5), so to

Re: [R] If...while...or what else??

2009-01-13 Thread jim holtman
Shouldn't your loop be: for (i in 1:4){ for (j in (i+1):5{ ... } } On Tue, Jan 13, 2009 at 8:20 AM, Niccolò Bassani biostatist...@gmail.com wrote: Dear R users,I come to you with a quite silly question I think, but I hope you can answer me... That is, I've got some problems in using

Re: [R] If...while...or what else??

2009-01-13 Thread Duncan Murdoch
On 1/13/2009 8:20 AM, Niccolò Bassani wrote: Dear R users,I come to you with a quite silly question I think, but I hope you can answer me... That is, I've got some problems in using the if and while conditions in a loop. Substantially, I want to select rows in a dataset depending on an index

Re: [R] If...while...or what else??

2009-01-13 Thread David Winsemius
Generally extraction of subsets is better done by subset(). myDat - subset(dataset, subset= (variable==i) | (variable==j) ) #, or myDat - dataset[which( (dataset$variable==i) | (dataset $variable==j) ), ] #note the need to add the name of the dataframe in the second version. Both of these

Re: [R] If...while...or what else??

2009-01-13 Thread Ted Harding
On 13-Jan-09 13:20:54, Niccolò Bassani wrote: Dear R users,I come to you with a quite silly question I think, but I hope you can answer me... That is, I've got some problems in using the if and while conditions in a loop. Substantially, I want to select rows in a dataset depending on an

Re: [R] If...while...or what else??

2009-01-13 Thread Gabor Grothendieck
If efficiency is not of concern then this is easy to understand: for(i in 1:5) for(j in 1:5) if (i j) { ... } On Tue, Jan 13, 2009 at 8:20 AM, Niccolò Bassani biostatist...@gmail.com wrote: Dear R users,I come to you with a quite silly question I think, but I hope you can answer me... That

Re: [R] If...while...or what else??

2009-01-13 Thread David Winsemius
On Jan 13, 2009, at 10:28 AM, Gabor Grothendieck wrote: If efficiency is not of concern then this is easy to understand: for(i in 1:5) for(j in 1:5) if (i j) { ... } or?: xx - expand.grid(i=1:5, j=1:5) subset(xx, i j) i j 6 1 2 11 1 3 12 2 3 16 1 4 17 2 4 18 3 4 21 1 5 22 2 5 23 3