View source: R/left_and_right.R
left | R Documentation |
left
takes a string and a character as arguments, then returns the
characters to the left. right
takes a string and a character as
arguments, then returns the characters to the right.
Wrappers around some regular expressions. Left
and right
operate
similar to combining left()
/right()
and search()
in excel. So maybe
there's a bit of nostalgia for me in using these functions. But I also
think that the naming makes it clearer what is going on.
left(string, char)
right(string, char)
string |
The string |
char |
A character used to delimit the string |
A string
https://stackoverflow.com/questions/45070117/r-check-if-special-character-in-string
https://stackoverflow.com/questions/36928870/r-check-if-string-contains-special-characters
a <- c("left.right","left.right","left.right")
left(a, ".")
right(a, ".")
library(dplyr)
library(tibble)
test_df <- tibble::tibble(
label = c("resection_margin=Mohs, > 1 cm",
"resection_margin=Mohs, > 1 cm",
"resection_margin=Mohs, <= 1 cm",
" resection_margin=Mohs, > 1 cm"))
test_df %>%
mutate(left = left(label, "="),
right = right(label, "="))
right(test_df$label, "=")
left(test_df$label, "=")
stringr::str_trim(left(test_df$label, "="), side = "both")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.