stringi

Extract last word in a string after comma if there are multiple words else the first word

狂风中的少年 提交于 2019-12-07 02:27:02
问题 I have data where the words as follows location<- c("xyz, sss, New Zealand", "USA", "Pris,France") id<- c(1,2,3) df<-data.frame(location,id) I would like to extract the country name from the data. The tricky part is if i extract just the last word then I will have only one record (France). library(stringr) df$country<- word(df$location,-1) Any ideas on how to extract country data from this data? id location country 1 xyz, sss, New Zealand New Zealand 2 USA USA 3 Pris,France France 回答1: You

Extract last word in a string after comma if there are multiple words else the first word

老子叫甜甜 提交于 2019-12-05 08:20:32
I have data where the words as follows location<- c("xyz, sss, New Zealand", "USA", "Pris,France") id<- c(1,2,3) df<-data.frame(location,id) I would like to extract the country name from the data. The tricky part is if i extract just the last word then I will have only one record (France). library(stringr) df$country<- word(df$location,-1) Any ideas on how to extract country data from this data? id location country 1 xyz, sss, New Zealand New Zealand 2 USA USA 3 Pris,France France You can try sub df$country <- sub('.*,\\s*', '', df$location) df$country #[1] "New Zealand" "USA" "France" Or

Installation of packages ‘stringr’ and ‘stringi’ had non-zero exit status

感情迁移 提交于 2019-12-04 02:07:27
Please help me to install stringr and stringi packages in R. The result is: install.packages("stringi") Installing package into ‘C:/Users/kozlovpy/Documents/R/win-library/3.2’ (as ‘lib’ is unspecified) пробую URL 'https://mran.revolutionanalytics.com/snapshot/2015-08-27/bin/windows/contrib/3.2/stringi_0.5-5.zip' Error in download.file(url, destfile, method, mode = "wb", ...) : не могу открыть URL 'https://mran.revolutionanalytics.com/snapshot/2015-08-27/bin/windows/contrib/3.2/stringi_0.5-5.zip' Вдобавок: Предупреждение: В download.file(url, destfile, method, mode = "wb", ...) :

How to install stringi library from archive and install the local icu52l.zip

耗尽温柔 提交于 2019-12-04 00:10:41
问题 We're bumbling through making some R code work in a production environment and as part of that we're installing some R packages as follows: # Default directories and mirrors WORKING_DIR <- "/srv/foo/bar/baz" LIB_DIR <- paste( WORKING_DIR, "libs", sep="/" ) setwd(WORKING_DIR) stringi.loc <- paste( WORKING_DIR, "stringi_0.4-1.tar.gz", sep="/" ) This might not be the most elegant way of installing R packages but it seems to work okay for us (any other tips on R package management would be

Extract character before and after “/”

你。 提交于 2019-12-02 23:34:56
问题 I'm trying to extract character before and after "/" with no success. Sentences are: XXXX YYY ZZZ - AV HAHEHRS, 3061 - SDDW ASDA DDSF - SAO JOSE DOS CAMPOS / SP - CEP: 00000-000 Output should be SAO JOSE DOS CAMPOS / SP I'm trying str_extract(str, "- [a-zA-Z]{1,} / [a-zA-Z]{1,}") but it's just bringing me CAMPOS / SP 回答1: In your regex there is the space missing. Try: str_extract(str, "- [a-zA-Z ]+ / [a-zA-Z ]+") Note the space in the character class. Also, {1,} is the long form of + . The

stringr function to concatenate vector of words separated by comma with “and” before last word

橙三吉。 提交于 2019-12-02 05:46:39
问题 I know I can easily write one, but does anyone know if stringr (or stringi) already has a function that concatenates a vector of one or more words separated by commas, but with an "and" before the last word? 回答1: You can use the knitr::combine_words function knitr::combine_words(letters[1:2]) # [1] "a and b" knitr::combine_words(letters[1:3]) # [1] "a, b, and c" knitr::combine_words(letters[1:4]) # [1] "a, b, c, and d" 回答2: Here's another solution : enum <- function(x) paste(c(head(x,-2),

Convert HTML Entity to proper character R

拈花ヽ惹草 提交于 2019-12-02 03:06:28
Does anyone know of a generic function in r that can convert ä to its unicode character â ? I have seen some functions that take in â , and convert it to a normal character. Any help would be appreciated. Thanks. Edit: Below is a record of data, which I probably have over 1 million records. Is there an easier solution other than reading the data into a massive vector, and for each element, changing the records? wine/name: 1999 Domaine Robert Chevillon Nuits St. Georges 1er Cru Les Vaucrains wine/wineId: 43163 wine/variant: Pinot Noir wine/year: 1999 review/points: N/A review/time: 1337385600

How to use back reference with stringi package?

妖精的绣舞 提交于 2019-12-01 18:36:31
问题 In R I can use \\1 to reference to a capturing group. However, when using the stringi package, this doesn't work as expected. library(stringi) fileName <- "hello-you.lst" (fileName <- stri_replace_first_regex(fileName, "(.*)\\.lst$", "\\1")) [1] "1" Expected output: hello-you . In the documentation I couldn't find anything concerning this problem. 回答1: You need to use $1 instead of \\1 in the replacement string: library(stringi) fileName <- "hello-you.lst" fileName <- stri_replace_first_regex

How to use back reference with stringi package?

不打扰是莪最后的温柔 提交于 2019-12-01 18:01:44
In R I can use \\1 to reference to a capturing group. However, when using the stringi package, this doesn't work as expected. library(stringi) fileName <- "hello-you.lst" (fileName <- stri_replace_first_regex(fileName, "(.*)\\.lst$", "\\1")) [1] "1" Expected output: hello-you . In the documentation I couldn't find anything concerning this problem. You need to use $1 instead of \\1 in the replacement string: library(stringi) fileName <- "hello-you.lst" fileName <- stri_replace_first_regex(fileName, "(.*)\\.lst$", "$1") [1] "hello-you" From the doc , stri_*_regex uses ICU's regular expressions

Difference between `paste`, `str_c`, `str_join`, `stri_join`, `stri_c`, `stri_paste`?

北城余情 提交于 2019-12-01 11:23:00
What are the differences between all of these functions that seem very similar ? stri_join , stri_c , and stri_paste come from package stringi and are pure aliases str_c comes from stringr and is just stringi::stri_join with a parameter ignore_null hardcoded to TRUE while stringi::stri_join has it set to FALSE by default. stringr::str_join is a deprecated alias for str_c see: library(stringi) identical(stri_join, stri_c) # [1] TRUE identical(stri_join, stri_paste) # [1] TRUE library(stringr) str_c # function (..., sep = "", collapse = NULL) # { # stri_c(..., sep = sep, collapse = collapse,