I have a function h(n)
that returns values for each integer 1 =< n =< k.
How can I construct a list of the form (h(1), h(2), h(3), ...)
where k is large so doing this manually will take some time.
Without your function, I don't know for sure, but lapply(1:k, h)
should take every value between 1 and k and send it to your function and return them in a list.
> h <- function(n) return(1:n)
> lapply(1:5, h)
[[1]]
[1] 1
[[2]]
[1] 1 2
[[3]]
[1] 1 2 3
[[4]]
[1] 1 2 3 4
[[5]]
[1] 1 2 3 4 5
P.S. This isn't homework is it?
h
we can help you to take advantage of that, such that typingh(1:10)
will returnc(h(1), h(2), ..., h(10))
- mathematical.coffee 2012-04-04 23:40