Title: | Pythonic Zip() for R |
---|---|
Description: | Implements Python-style zip for R. Is a more flexible version of cbind. |
Authors: | Leslie Huang [aut, cre] |
Maintainer: | Leslie Huang <[email protected]> |
License: | GPL-3 |
Version: | 0.1.1 |
Built: | 2024-11-19 05:11:28 UTC |
Source: | https://github.com/leslie-huang/zipr |
broadcasts a shorter vector-like object into a vector of equal length as a longer vector-like object
broadcast(longer, shorter)
broadcast(longer, shorter)
longer |
longer vector-like object |
shorter |
shorter vector-like object |
This function checks that the vector-like objects x, y are of equal length.
check_length(x, y)
check_length(x, y)
x |
vector-like object |
y |
vector-like object |
Use a given fillvalue to fill in a shorter sequence and returns a sequence of equal length to the longer sequence. Takes a subset of the fill sequence if fill sequence is longer than the difference between the longer and shorter sequences
fill(longer, shorter, fillvalue)
fill(longer, shorter, fillvalue)
longer |
longer vector-like object |
shorter |
shorter vector-like object |
fillvalue |
sequence of value(s) to fill in shorter vector. If fillvalue is longer than the difference between 'shorter' and 'longer', values from fillvalue will be taken only until 'shorter' is the same length as 'longer' |
zip two vector-like objects into a dataframe
zipr(x = x, y = x, broadcast = FALSE, fill = FALSE, fillvalue = c(NA))
zipr(x = x, y = x, broadcast = FALSE, fill = FALSE, fillvalue = c(NA))
x |
vector-like object |
y |
vector-like object |
broadcast |
defaults to FALSE; if TRUE, shorter sequence is repeated until its length is equal to that of the longer sequence |
fill |
defaults to FALSE; bool for whether fillvalue should be implemented |
fillvalue |
value or sequence of value(s) to fill in shorter sequence until it is the same length as the longer sequence. Defaults to NA |
A dataframe
a <- c(1,2,3) b <- c(4,5,6) c <- c(1,2,3,4,5,6) d <- c(7,8) z <- c(9) filler <- c(NA) # zip two vectors of the same length zipr(a,b) # zip two vectors of different lengths, repeating the shorter vector zipr(a, z, broadcast = TRUE) # zip two vectors of different lengths, using the default fill value zipr(z, a, fill = TRUE) # zip two vectors of different lengths, using a custom fill value zipr(c,a, fill = TRUE, fillvalue = z)
a <- c(1,2,3) b <- c(4,5,6) c <- c(1,2,3,4,5,6) d <- c(7,8) z <- c(9) filler <- c(NA) # zip two vectors of the same length zipr(a,b) # zip two vectors of different lengths, repeating the shorter vector zipr(a, z, broadcast = TRUE) # zip two vectors of different lengths, using the default fill value zipr(z, a, fill = TRUE) # zip two vectors of different lengths, using a custom fill value zipr(c,a, fill = TRUE, fillvalue = z)