We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sep
str_dup
I was going through this SO question, and thought that it might be useful to add an optional sep argument to str_dup.
For instance, in the case of the SO question the OP wants to repeat a string and add ; between every repeated value.
;
n = 3 input = c(67L, 24L, 72L, 3L) expected_output = c("67;67;67", "24;24;24", "72;72;72", "3;3;3")
So far, what one can do is:
library(stringr) library(purrr) map_chr(input, ~ str_flatten(rep(.x, each = n), ";")) #[1] "67;67;67" "24;24;24" "72;72;72" "3;3;3"
Or in base R:
sapply(input, \(x) paste(rep(x, n), collapse=";"))
But what about a simple str_dup call?
str_dup(input, n, sep = ";")
The text was updated successfully, but these errors were encountered:
No branches or pull requests
I was going through this SO question, and thought that it might be useful to add an optional
sep
argument tostr_dup
.For instance, in the case of the SO question the OP wants to repeat a string and add
;
between every repeated value.So far, what one can do is:
Or in base R:
But what about a simple
str_dup
call?The text was updated successfully, but these errors were encountered: