[R] outputting functions in lapply

Rune Schjellerup Philosof rphilosof at health.sdu.dk
Mon Dec 7 14:53:53 CET 2009


How come the k is 3 in all of this output?
I expected it to be equal to r.

> tmp3 <- lapply(1:3, function(k) function(r) print(paste(r, "<- r | k
->", k)))
> for (i in 1:3) { tmp3[[i]](i) }
[1] "1 <- r | k -> 3"
[1] "2 <- r | k -> 3"
[1] "3 <- r | k -> 3"

-- 
Med venlig hilsen

Rune Schjellerup Philosof
Ph.d-stipendiat, Forskningsenheden for Biostatistik

Telefon: 6550 3607
E-mail:	 rphilosof at health.sdu.dk
Adresse: J.B. Winsløwsvej 9, 5000 Odense C

SYDDANSK UNIVERSITET
_______________________________________________________________
* Campusvej 55 * 5230 * Odense M * 6550 1000 * www.sdu.dk




More information about the R-help mailing list