On 2011-02-07 00:18, Joel wrote:

Hi

Im confused by one thing, and if someone can explain it I would be a happy

rev(strsplit("hej",NULL))
[[1]]
[1] "h" "e" "j"

lapply(strsplit("hej",NULL),rev)
[[1]]
[1] "j" "e" "h"

Why dossent the first one work? What is it in R that "fails" so to say that
you need to use lapply for it to get the correct output.

See if this helps to see what's happening in the first case:

 L <- list(fruit=c("apple", "orange"))
 L
 rev(L)

 L <- list(fruit=c("apple", "orange"), nuts=c("pecan", "almond"))
 L
 rev(L)

 lapply(L, rev)

For your second case, lapply() applies FUN to the pieces
of the list.

Peter Ehlers

______________________________________________
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.

Reply via email to