Apply a callback to an array: Difference between revisions
Content added Content deleted
No edit summary |
m (→{{header|R}}) |
||
Line 1,203: | Line 1,203: | ||
cubes[i] <- cube(elements[i]) |
cubes[i] <- cube(elements[i]) |
||
}</lang> |
}</lang> |
||
Loop syntax can often simplified using the [http://stat.ethz.ch/R-manual/R-patched/library/base/html/apply.html * |
Loop syntax can often simplified using the [http://stat.ethz.ch/R-manual/R-patched/library/base/html/apply.html *apply] family of functions. |
||
<lang R>elements2 <- list(1,2,3,4,5) |
<lang R>elements2 <- list(1,2,3,4,5) |
||
cubes <- sapply(elements2, cube)</lang> |
cubes <- sapply(elements2, cube)</lang> |