Re: [R] how to get rid of 2 for-loops and optimize runtime

2009-10-20 Thread Ian Willems
Hi Joris, The amount of a month ago is normally one value from another row. But I used 'sum-sum + dataset[i,22]' because I would like to reuse the code also for other tables. In some tables it is possible that the value of last month is the sum of values from different rows. Thank u for your

Re: [R] how to get rid of 2 for-loops and optimize runtime

2009-10-20 Thread Ian Willems
Hi William, Your programs works perfect and very fast for the table I'm using right now (only one match per row) If I want to reuse this code other tables, it can match with more than one row. Is it possible to adapt your code easily, if I have to sum the values of last month from different

Re: [R] how to get rid of 2 for-loops and optimize runtime

2009-10-20 Thread William Dunlap
-Original Message- From: Ian Willems [mailto:ian.will...@uz.kuleuven.ac.be] Sent: Tuesday, October 20, 2009 6:46 AM To: William Dunlap; r-help@r-project.org Subject: RE: [R] how to get rid of 2 for-loops and optimize runtime Hi William, Your programs works perfect and very fast

[R] how to get rid of 2 for-loops and optimize runtime

2009-10-19 Thread Ian Willems
Short: get rid of the loops I use and optimize runtime Dear all, I want to calculate for each row the amount of the month ago. I use a matrix with 2100 rows and 22 colums (which is still a very small matrix. nrows of other matrixes can easily be more then 10) Table before Year month

Re: [R] how to get rid of 2 for-loops and optimize runtime

2009-10-19 Thread joris meys
Hi Ian, first of all, take a look at the functions sapply, mapply, lapply, tapply, ... : they are the more efficient way of implementing loops. Second, could you elaborate a bit further on the data set : the amount of the month ago, is that one value from another row, or the sum of all values in

Re: [R] how to get rid of 2 for-loops and optimize runtime

2009-10-19 Thread William Dunlap
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ian Willems Sent: Monday, October 19, 2009 6:50 AM To: 'r-help@r-project.org' Subject: [R] how to get rid of 2 for-loops and optimize runtime Short: get rid of the loops I