Comments (11)
@hadley's suggestion/question:
x <- c("a b c")
stri_sub(x, c(1, 3), c(1, 3)) <- c("A", "B")
x
# [1] "A b c" "a B c"
Is there an easy way to get "A B c" ?
from stringi.
vectorize_all
arg to stri_sub???
from stringi.
@markdanese's example:
# toy data and split matrix
x <- c("abcdefgh", "ijklmnop")
split <- matrix(1:8, ncol = 2, byrow = TRUE)
stri_sub(x, split)
gives:
[1] "ab" "kl" "ef" "op"
but I was hoping for this:
[[1]]
[1] "ab" "cd" "ef" "gh"
[[2]]
[1] "ij" "kl" "mn" "op"
or even better, this:
[,1] [,2] [,3] [,4]
[1,] "ab" "cd" "ef" "gh"
[2,] "ij" "kl" "mn" "op"
The last piece is accomplished by do.call(rbind, lapply(x, stri_sub, split))
but I was hoping it might be faster if it were all done in c++.
from stringi.
Note: we should be able to imitate a call to stri_replace(...)
with stri_subXXX(stri_locate(...)) <- ...
and a call to stri_extract(...)
with stri_sub(stri_locate(...))
from stringi.
Also, stri_paste
accepting lists could be handy, see #175
from stringi.
library(stringi)
x <- "abcdefgh"
str_sub(x, c(1, 3), c(1, 3)) <- c("X", "Y")
x
#> [1] "Xbcdefgh" "abYdefgh"
Ideally it would return "XbYdefgh"
from stringi.
Ooops, I guess I keep forgetting about this issue!
from stringi.
It's been quite some time since the last comment. Is there a work around for this that people have come up with?
from stringi.
Finally I've had time for this. DONE.
Example 1:
> stri_sub_replace_all("a b c", c(1, 3, 5), c(1, 3, 5), value=c("A", "B", "C"))
[1] "A B C"
Example 2:
> x <- c("12 3456 789", "abc", "", NA, "667")
> stri_sub_all(x, stri_locate_all_regex(x, "[0-9]+", omit_no_match=TRUE)) <- "***"
> print(x)
[1] "*** *** ***" "abc" "" NA "***"
Example 3 (@markdanese):
> x <- c("abcdefgh", "ijklmnop")
> split <- matrix(1:8, ncol = 2, byrow = TRUE)
> split
[,1] [,2]
[1,] 1 2
[2,] 3 4
[3,] 5 6
[4,] 7 8
> stri_sub_all(x, split)
[[1]]
[1] "ab" "cd" "ef" "gh"
[[2]]
[1] "ij" "kl" "mn" "op"
> stri_list2matrix(stri_sub_all(x, split), byrow=TRUE)
[,1] [,2] [,3] [,4]
[1,] "ab" "cd" "ef" "gh"
[2,] "ij" "kl" "mn" "op"
from stringi.
Nice work - thanks!
from stringi.
thanks! looking forward to testing it out
from stringi.
Related Issues (20)
- The tip information when install the stringi: stringi cannot be built with these settings in place. HOT 2
- Unable to build stringi: βisNullβ was not declared in this scope HOT 6
- neither conda R version nor base R installed stringi successfully HOT 9
- Unable to install stringi HOT 1
- DOI not found: https://dx.doi.org/10.18637/jss.v103.i02 HOT 2
- Timout downloading ICU at stringi installation HOT 12
- unable to install stringi via http_proxy HOT 7
- libicui18n.so.71: cannot open shared object file HOT 2
- stri_detect_regex gives non-intuitive error (U_ILLEGAL_ARGUMENT_ERROR) with strings longer than 858993457 characters HOT 1
- `stri_(any|all)_(regex|fixed)` HOT 1
- stri_split_boundaries() returns slightly different tokens when the ICU rules are supplied HOT 3
- [Feature] Convert String to Code Points HOT 2
- [Feature] Extract Non-ASCII Characters HOT 3
- Unable to install stringi in R 4.3 HOT 10
- install issue, no internet HOT 2
- Behavior of `stri_sub()` when `from = 0` HOT 2
- Cannot install stringi on linux (CENTOS 7) machine HOT 1
- installation of package 'stringi' had non-zero exit status HOT 2
- Fails to build with clang on Windows HOT 2
- Calling stringi C functions without Rcpp HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stringi.