Re: [R] How to visualise what code is processed within a for loop

2018-04-28 Thread Rui Barradas
I forgot to explain why my suggestion. The logical condition returns FALSE/TRUE that in R are coded as 0/1. So all you have to do is coerce to integer. This works because the ifelse will return a 1 or a 0 depending on the condition. Meaning exactly the same values. And is more efficient since

Re: [R] How to visualise what code is processed within a for loop

2018-04-28 Thread Rui Barradas
Hello, instead of ifelse, the following is exactly the same and much more efficient. d0[[nm]] <- as.integer(regexpr(d1[i,1], d0$X0) > 0) Hope this helps, Rui Barradas On 4/28/2018 8:45 PM, Luca Meyer wrote: Thanks Don, for (i in 1:10){ nm <- paste0("V", i) d0[[nm]] <-

Re: [R] How to visualise what code is processed within a for loop

2018-04-28 Thread Luca Meyer
Thanks Don, for (i in 1:10){ nm <- paste0("V", i) d0[[nm]] <- ifelse( regexpr(d1[i,1], d0$X0) > 0, 1, 0) } is exaclty what I needed. Best regards, Luca 2018-04-25 23:03 GMT+02:00 MacQueen, Don : > Your code doesn't make sense to me in a couple of ways. > > Inside the loop