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

2018-04-30 Thread Bert Gunter
; Don MacQueen >> >> Lawrence Livermore National Laboratory >> >> 7000 East Ave., L-627 >> >> Livermore, CA 94550 >> >> 925-423-1062 >> >> Lab cell 925-724-7509 >> >> >> >> >> >> *From: *Luca Meyer >&

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

2018-04-30 Thread Luca Meyer
Ave., L-627 > > Livermore, CA 94550 > > 925-423-1062 > > Lab cell 925-724-7509 > > > > > > *From: *Luca Meyer > *Date: *Monday, April 30, 2018 at 8:08 AM > *To: *Rui Barradas > *Cc: *"MacQueen, Don" , array R-help < > r-help@r-project.or

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

2018-04-30 Thread Rui Barradas
: *Monday, April 30, 2018 at 8:08 AM *To: *Rui Barradas *Cc: *"MacQueen, Don" , array R-help *Subject: *Re: [R] How to visualise what code is processed within a for loop Hi Rui Thank you for your suggestion, I have tested the code suggested by you against that supplied by Don in terms

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

2018-04-30 Thread MacQueen, Don
94550 925-423-1062 Lab cell 925-724-7509 From: Luca Meyer Date: Monday, April 30, 2018 at 8:08 AM To: Rui Barradas Cc: "MacQueen, Don" , array R-help Subject: Re: [R] How to visualise what code is processed within a for loop Hi Rui Thank you for your suggestion, I have tested the code

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

2018-04-30 Thread Luca Meyer
Hi Rui Thank you for your suggestion, I have tested the code suggested by you against that supplied by Don in terms of timing and results are very much aligned: to populate a 5954x899 0/1 matrix on my machine your procedure took 79 secs, while the one with ifelse employed 80 secs, hence unfortuna

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

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

2018-04-25 Thread MacQueen, Don
Your code doesn't make sense to me in a couple of ways. Inside the loop, the first line assigns a value to an object named "t". Then, the second line does the same thing, assigns a value to an object named "t". The value of the object named "t" after the second line will be the output of the if

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

2018-04-24 Thread Luca Meyer
Hi Bob, Thank you for your suggestion. Actually d0 is a dataframe, does that change something in the code you propose? Kind regards, Luca 2018-04-24 10:19 GMT+02:00 Bob O'Hara : > The loop never assigns anything to d0, only t. The first line makes t > a character string "d0$V1" (or "d0$V2" etc

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

2018-04-24 Thread Bob O'Hara
The loop never assigns anything to d0, only t. The first line makes t a character string "d0$V1" (or "d0$V2" etc.). The second line assigns either 0 or 1 to t. Looking at this, I don't think you've got into the R psychology (bad news if you want to use R, good news in many other ways). I assume d0