recycle | R Documentation |
A convenience function to recycle R objects to either a common or specified size.
recycle(..., length = NULL, .args = NULL)
... |
Objects to recycle. |
length |
Optional length to recycle objects to. |
.args |
An alternative to |
Data frames are recycled by recycling their rows.
recycle()
is optimised to only recycle objects that need recycling.
NULL
objects are ignored and not recycled or returned.
A list of recycled R objects.
library(cheapr)
# Recycles both to size 10
recycle(Sys.Date(), 1:10)
# Any vectors of zero-length are all recycled to zero-length
recycle(integer(), 1:10)
# Unless length is supplied
recycle(integer(), 1:10, length = 10)
# Data frame rows are recycled
recycle(sset(iris, 1:3), length = 9)
# To recycle objects in a list, use `.args`
my_list <- list(from = 1L, to = 10L, by = seq(0.1, 1, 0.1))
recycle(.args = my_list)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.