Re: [R] make apply() return a list

2004-11-02 Thread Arne Henningsen
Hi, thank you very much Sundar, Patrick, Tony, Mahub and Gabor for your helpful answers! All your examples work great. They are all more straightforeward than my example and much faster than the for-loop. These are the average elapsed times (in seconds) returned by system.time()[3] (applied

Re: [R] make apply() return a list

2004-11-02 Thread Gabor Grothendieck
Arne Henningsen ahenningsen at email.uni-kiel.de writes: : : Hi, : : thank you very much Sundar, Patrick, Tony, Mahub and Gabor for your helpful : answers! All your examples work great. They are all more straightforeward : than my example and much faster than the for-loop. : These are the

Re: [R] make apply() return a list

2004-11-02 Thread Arne Henningsen
On Tuesday 02 November 2004 15:29, Gabor Grothendieck wrote: Arne Henningsen ahenningsen at email.uni-kiel.de writes: : Hi, : : thank you very much Sundar, Patrick, Tony, Mahub and Gabor for your : helpful answers! All your examples work great. They are all more : straightforeward than my

Re: [R] make apply() return a list

2004-11-02 Thread Gabor Grothendieck
Arne Henningsen ahenningsen at email.uni-kiel.de writes: : : On Tuesday 02 November 2004 15:29, Gabor Grothendieck wrote: : Arne Henningsen ahenningsen at email.uni-kiel.de writes: : : Hi, : : : : thank you very much Sundar, Patrick, Tony, Mahub and Gabor for your : : helpful answers! All

[R] make apply() return a list

2004-11-01 Thread Arne Henningsen
Hi, I have a dataframe (say myData) and want to get a list (say myList) that contains a matrix for each row of the dataframe myData. These matrices are calculated based on the corresponding row of myData. Using a for()-loop to do this is very slow. Thus, I tried to use apply(). However, afaik

Re: [R] make apply() return a list

2004-11-01 Thread Tony Plate
for()-loops aren't so bad. Look inside the code of apply() and see what it uses! The important thing is that you use vectorized functions to manipulate vectors. It's often fine to use for-loops to manipulate the rows or columns of a matrix, but once you've extracted a row or a column, then

Re: [R] make apply() return a list

2004-11-01 Thread Mahbub Latif
How about this... x = matrix(1:27, ncol=9, byrow=T) nr= nrow(x) lapply(1:nr, function(i) matrix(x[i,], nrow=3, byrow=T)) Mahbub. On Mon, 1 Nov 2004 19:37:08 +0100, Arne Henningsen [EMAIL PROTECTED] wrote: Hi, I have a dataframe (say myData) and want to get a list (say myList) that

Re: [R] make apply() return a list

2004-11-01 Thread Gabor Grothendieck
Arne Henningsen ahenningsen at email.uni-kiel.de writes: : : Hi, : : I have a dataframe (say myData) and want to get a list (say myList) that : contains a matrix for each row of the dataframe myData. These matrices are : calculated based on the corresponding row of myData. Using a for()-loop