Re: [R] While loop history

2013-04-08 Thread C W
an using them. > > Bill Dunlap > Spotfire, TIBCO Software > wdunlap tibco.com > > > > -----Original Message- > > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > On Behalf > > Of C W > > Sent: Sunday, April 07, 2013 3:11 PM >

Re: [R] While loop history

2013-04-08 Thread MacQueen, Don
There are a number of different ways to do this, so it would have been helpful if you had set the context with a stripped down example. That said, here are some pointers: > x1 <- NULL > x1 <- c(x1,3) > x1 [1] 3 > x1 <- c(x1,4) > x1 [1] 3 4 So you see that you can add elements to the end of a vect

Re: [R] While loop history

2013-04-07 Thread William Dunlap
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf > Of C W > Sent: Sunday, April 07, 2013 3:11 PM > To: John Kane > Cc: r-help@r-project.org; Baylee Smith > Subject: Re: [R] While loop history > > May I say also ask one thing?

Re: [R] While loop history

2013-04-07 Thread Jeff Newmiller
Vectors. Data frames are lists of vectors. Create longer vectors and perform computations vector-wise on all simulation data sets at once. Depending on the type of simulation, matrices and linear algebra may help as well. ---

Re: [R] While loop history

2013-04-07 Thread C W
May I say also ask one thing? @OP: sorry to use your post. What would you use instead of loops? I am aware of the apply() functions, but they are wrapper function of for loops, so they are slower. At one point, I was told to go back to C for faster implementation, but I like R much more. In th

Re: [R] While loop history

2013-04-07 Thread John Kane
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example Loops are seldom a good solution in R so some more information and data would be useful At the simplist, for your specific question I think you could set up two vectors (e.g. v1 <- rep(NA, 10 ) and just w

Re: [R] While loop working with TRUE/FALSE?

2012-02-02 Thread Petr PIKAL
Hi > > Thanks to Berend and the others, > > I've found a solution which works fine for my problem. > > I have not only 2 vectors, but also 4. > Question is, if q1 and q2 is equal to w1 and w2. > The computational time is very short, also for large data. > > q1 <- c(9,5,1,5) > q2 <- c(9,2,1,5)

Re: [R] While loop working with TRUE/FALSE?

2012-02-02 Thread David Winsemius
On Feb 2, 2012, at 6:55 AM, Chris82 wrote: Thanks to Berend and the others, I've found a solution which works fine for my problem. I have not only 2 vectors, but also 4. Question is, if q1 and q2 is equal to w1 and w2. The computational time is very short, also for large data. q1 <- c(9,5,1,

Re: [R] While loop working with TRUE/FALSE?

2012-02-02 Thread Patrizio Frederic
Hey Chris, I would take advantage from the apply function: apply(cbind(q1,q2),1,function(x)any((x[1]==w1)&(x[2]==w2))) Regards PF On Thu, Feb 2, 2012 at 12:55 PM, Chris82 wrote: > Thanks to Berend and the others, > > I've found a solution which works fine for my problem. > > I have not only 2

Re: [R] While loop working with TRUE/FALSE?

2012-02-02 Thread Chris82
Thanks to Berend and the others, I've found a solution which works fine for my problem. I have not only 2 vectors, but also 4. Question is, if q1 and q2 is equal to w1 and w2. The computational time is very short, also for large data. q1 <- c(9,5,1,5) q2 <- c(9,2,1,5) w1 <- c(9,4,4,4,5) w1 <- c

Re: [R] While loop working with TRUE/FALSE?

2012-02-01 Thread Berend Hasselman
On 01-02-2012, at 17:32, Chris82 wrote: > Thanks to both. > > This is just a simple example. In real I have two vectors with different > lengths. > The code consists of two for loops for r and z. The main problem is the > computational time, so I try to stop the loop if w is TRUE for the first

Re: [R] While loop working with TRUE/FALSE?

2012-02-01 Thread Feng Li
I guess you want something like w=F z <- c(0,1,2,3,4,5,6,7,8,9) r <- 7 while(w == F) { for ( i in 1:10 ){ w <- r == z[i] print(w) } } But this loop will run forever. The condition for "while" is checked when i jumps from 10 to 1. At that momen

Re: [R] While loop working with TRUE/FALSE?

2012-02-01 Thread Jeff Newmiller
No. The while loop is only tested after the for loop has completed. Use debug to understand this if it doesn't make sense to you. --- Jeff NewmillerThe . . Go Live... DCN:Basi

Re: [R] While loop working with TRUE/FALSE?

2012-02-01 Thread Chris82
Thanks to both. This is just a simple example. In real I have two vectors with different lengths. The code consists of two for loops for r and z. The main problem is the computational time, so I try to stop the loop if w is TRUE for the first time. First I tried to use the command "stop" in comb

Re: [R] While loop working with TRUE/FALSE?

2012-02-01 Thread Berend Hasselman
On 01-02-2012, at 16:55, Chris82 wrote: > Hi R users, > > is there any possibilty that a while loop is working like that: > > z <- c(0,1,2,3,4,5,6,7,8,9) > r <- 7 > > while(w == T) { >for ( i in 1:10 ){ >w <- r == z[i] >print(w) >} > } > >

Re: [R] While loop working with TRUE/FALSE?

2012-02-01 Thread Milan Bouchet-Valat
Le mercredi 01 février 2012 à 07:55 -0800, Chris82 a écrit : > Hi R users, > > is there any possibilty that a while loop is working like that: > > z <- c(0,1,2,3,4,5,6,7,8,9) > r <- 7 > >while(w == T) { > for ( i in 1:10 ){ > w <- r == z[i] > print(w)

Re: [R] While loop working with TRUE/FALSE?

2012-02-01 Thread R. Michael Weylandt
You are combining too many loop constructs: perhaps you just want to use for and break. Of course, in your case it's much faster to write which(r == z) or which.min(r == z) Michael On Wed, Feb 1, 2012 at 10:55 AM, Chris82 wrote: > Hi R users, > > is there any possibilty that a while loop is wor

Re: [R] while loop until end of file

2010-08-29 Thread Joshua Wiley
Hi Marcel, Not quite sure what you want the while loop for. Does this do what you want? mydat <- read.table(textConnection(" Pair group param1 1 D 10 1 D 10 1 R 10 1 D 10 2 D 10 2

Re: [R] while loop until end of file

2010-08-29 Thread Bill.Venables
Eh? ## First calculate the means: mns <- with(alldata, tapply(param1, list(Pair, group), mean)) ## now put the results into a data frame res <- data.frame(mns, dif = mns[, "D"] - mns[, "R"]) ## Then write it out if that's your thing. -Original Message- From: r-help-boun...@r-projec

Re: [R] While loop set up

2008-11-18 Thread bartjoosen
Hello Rodrigo, You're almost there: you should make the variable distance before the while loop, and this should be higher than 14 to go inside the while loop: selectmarkers<- function(n=10){ tapply(mm$marker, mm$chr, function(m){ distances <- 15 while (max(distances) > 14) {

Re: [R] While loop

2008-07-11 Thread Henrique Dallazuanna
If I understand correctly, you can try: m <- matrix(sample(0:5, 24, rep = TRUE), nc = 3) # A list with the index lapply(apply(m == 0, 2, which), head, 1) # A vector unlist(lapply(apply(m == 0, 2, which), head, 1)) On Fri, Jul 11, 2008 at 2:06 PM, Rheannon <[EMAIL PROTECTED]> wrote: > > Hello,

Re: [R] while loop syntax help

2008-03-03 Thread Heikki Kaskelma
zack holden: > I need to sort through a vector (x) and identify the point at which 2 > successive values become smaller than the previous value. x <- c(5,5,7,6,5,4,3) a=c(diff(x, 1) < 0, FALSE) & c(diff(x, 2) < 0, FALSE, FALSE) a # FALSE FALSE TRUE TRUE TRUE FALSE FALSE which(a) # 3 4 5

Re: [R] while loop syntax help

2008-02-29 Thread jim holtman
Does this give the answer that you want? > x <- c(5,5,7,6,5,4,3) > result <- NULL > for (i in 1:(length(x) - 2)){ + if ((x[i + 1] < x[i]) && (x[i + 2] < x[i])) result <- c(result, i) + } > result [1] 3 4 5 > On 2/29/08, zack holden <[EMAIL PROTECTED]> wrote: > > Dear list, > I'm trying to w