Re: [R] row, col function but for a list (probably very easy question, cannot seem to find it though)

2012-03-27 Thread MBoersma
Thanks guys for all the replies.

It is an urban myth that using 'apply' functions will deliver better   
performance than 'for' loops. It may even worsen performance or create   
obstacles when it is improperly used with dataframes. Most of the   
benefits come from improving readability and maintainability.

This is what I had to learn the hard way: apply functions made it go
slower :) I do understand them much better now, also in the light of some of
these ways of using them.

In the end my program became much faster by making the data frames matrices,
and even more by finally seeing the light (courtesy of a colleague for
getting me to think in the right direction) and making much more of it into
a matrix operation. I'm very happy with the results :).

So consider me helped!

Regards,
Mark

--
View this message in context: 
http://r.789695.n4.nabble.com/row-col-function-but-for-a-list-probably-very-easy-question-cannot-seem-to-find-it-though-tp4504216p4508816.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] row, col function but for a list (probably very easy question, cannot seem to find it though)

2012-03-26 Thread MBoersma
Hi guys,

I'm quite new to R but quite enthousiastic. I'm trying to rewrite a bit of
code in order to make it faster, so instead of nesting for loops I'm trying
some apply functions. Since it's a combination of lists of matrices and
other matrices, I would like to use lapply() on the list and still be able
to use the list index to index in the matrices.

So, in code format-
x - list()
for (i in 1:10){
  x[[i]] - c(1:i)
}

lapply(x,length)

is there a possible way to say lapply(x, function(x) length(x)/index(x) )
and return 1's. I would be looking for the index. I know that row() and
col() work in the matrix case. I would find it interesting to use it with
arrays as well.

Many thanks in advance!

Regards,
Mark


--
View this message in context: 
http://r.789695.n4.nabble.com/row-col-function-but-for-a-list-probably-very-easy-question-cannot-seem-to-find-it-though-tp4504216p4504216.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.