search for: str_split

Displaying 20 results from an estimated 24 matches for "str_split".

2013 Sep 27
2
Locating inefficient code
.... That is all. Can this code improved ? data <- read.table("D:\\Log Analysis\\26-9-2013\\concurrentusage-node1",sep="",header=T,stringsAsFactors=FALSE, fill=TRUE) var <- c("Foreign.Address") data[,var] <- sapply(data[,var],function(x) ifelse(length(unlist(str_split(x,":")))==5,unlist(str_split(x,":"))[4],unlist(str_split(x,":"))[1])) var <- c("Local.Address") data[,var] <- sapply(data[,var],function(x) ifelse(length(unlist(str_split(x,":")))==5,paste(unlist(str_split(x,":"))[4],":",u...
2019 Sep 23
5
Consulta
...#39;C:/Users/bdominguez/Documents/H0711/Bond/1909/'? archivos<-list.files(path=ruta,pattern = '*.pdf')? ? ? imagen <- image_read_pdf(path=paste(ruta,"/",nombre,".pdf",sep=""))? prueba <-image_ocr(imagen, language = 'eng')? lineas<-unlist(str_split(prueba,pattern = "\n"))? lineasp<-unlist(str_split(prueba[2],pattern = "\r\n"))? ? newnom <- NULL? renglones <- NULL? for (nombre in archivos){? subgrupo <- str_extract(str_extract(nombre,pattern = subgrupo_rg),pattern = "[0-9]{1,3}")? imagen <- imag...
2019 Sep 24
2
Consulta
...rg> Asunto: Re: [R-es] Consulta Hola, Estos mensajes de error no son por el paquete pdftools. Las funciones image_read_pdf e image_ocr son del paquete magick. ¿Lo tienes instalado? ¿Lo tienes cargado? Según el script sí, pero asegúrate de que library(magick) no da ningún error. La otra función ?str_split? es del paquete stringr, pasa lo mismo: tiene que estar cargado para poder utilizar sus funciones. Saludos, Emilio El 24 sept 2019, a las 16:20, BERENICE DOMINGUEZ SANCHEZ <ds_bere en hotmail.com<mailto:ds_bere en hotmail.com>> escribió: Emilio Buen día, si me manda un error muy esp...
2023 Dec 18
3
Function with large nested list
...ual information in algorithm ##### CULTURES ##### for (i in names(AB_list)) { ab_data <- dataset_ab[dataset_ab$middel == i,] #get info for this AB from dataset_ab # Extract and split the diagnoses, dosering, and duur info for the current antibiotic ab_diagnoses <- str_split(ab_data$diagnoses, pattern = " \\| ")[[1]] ab_diagnose_dosering <- str_split(ab_data$`diagnose dosering`, pattern = " \\| ")[[1]] ab_diagnose_duur <- str_split(ab_data$`diagnose duur`, pattern = " \\| ")[[1]] # Find the index of the current diagn...
2013 Apr 16
3
Splitting the Elements of character vector
Dear R forum I have a data.frame df = data.frame(currency_type = c("EURO_o_n", "EURO_o_n", "EURO_1w", "EURO_1w", "USD_o_n", "USD_o_n", "USD_1w", "USD_1w"), rates = c(0.47, 0.475, 0.461, 0.464, 1.21, 1.19, 1.41, 1.43))   currency_type     rates 1      EURO_o_n   0.470 2      EURO_o_n   0.475 3       EURO_1w   0.461
2012 Jun 27
2
A solution for question about formatting Dates
...Here is a solution to the dates without leading zeros: pou1 <- function(x) { #Note: x is a data frame #Assume that Column 1 has the date #Column 2 has station #Column 3 has min #Column 4 has max library(stringr) w <- character(length=nrow(x)) z <- str_split(x[,1],"/") for(i in 1:nrow(x)) { u <- str_pad(z[[i]][1:3],width=2,pad="0") w[i] <- paste(u,sep="",collapse="/") } a <- as.Date(w,"%m/%d/%Y") This is not particularly elegant, but it does the trick. Thanks, E...
2013 Jun 08
1
splitting a string column into multiple columns faster
Hello! I have a column in my data frame that I have to split: I have to distill the numbers from the text. Below is my example and my solution. x<-data.frame(x=c("aaa1_bbb1_ccc3","aaa2_bbb3_ccc2","aaa3_bbb2_ccc1")) x library(stringr) out<-as.data.frame(str_split_fixed(x$x,"aaa",2)) out2<-as.data.frame(str_split_fixed(out$V2,"_bbb",2)) out3<-as.data.frame(str_split_fixed(out2$V2,"_ccc",2)) result<-cbind(x,out2[1],out3) result My problem is: str_split.fixed is relatively slow. In my real data frame I have over 80,000 ro...
2023 Jun 29
0
Processing a hierarchical string name
...ace": > > bg3_race_sum$label |> > (\(.) sub('^ !!', '', .))() |> > (\(.) gsub('[^!]*!!', ' ', .))() > > But that solution could have been impossible if the task was slightly > different. > >> I can split the label using str_split(label, pattern = "!!") to get a >> vector of strings, but don't know how to work on the last string and >> all the rest of the strings separately. > > str_split() would have given you a list of character vectors. You can > use lapply to evaluate a function on eac...
2013 Apr 16
1
converting blank cells to NAs
You can use na.strings="" in read.table() or read.csv() library(stringr) vec1<-unlist(str_split(readLines(textConnection("3,7,11,,12,14,15,,17,18,19")),",")) ?vec1[vec1==""]<- NA ?vec1 # [1] "3"? "7"? "11" NA?? "12" "14" "15" NA?? "17" "18" "19" #or scan(text="3,7,1...
2013 Apr 22
1
Print occurrence / positions of words
Hi, May be this helps: vec<- "this is a nice text with nice characters" library(stringr) ?vec2<-unlist(str_match_all(vec,"\\w+")) #or # vec2<-str_split(vec," ")[[1]] res<-unique(lapply(vec2,function(x) which(!is.na(match(vec2,x))))) ?names(res)<- unique(vec2) res #$this #[1] 1 # #$is #[1] 2 # #$a #[1] 3 # #$nice #[1] 4 7 # #$text #[1] 5 # #$with #[1] 6 # #$characters #[1] 8 A.K. >Hi, >I have tried some different packages i...
2012 Jun 05
1
Trouble with Functions
...os.words, neg.words) { # clean up sentences with R?s regex-driven global substitute, gsub(): sentence = gsub(?[[:punct:]]?, ?, sentence) sentence = gsub(?[[:cntrl:]]?, ?, sentence) sentence = gsub(?\\d+?, ?, sentence) # and convert to lower case: sentence = tolower(sentence) # split into words. str_split is in the stringr package word.list = str_split(sentence, ?\\s+?) # sometimes a list() is one level of hierarchy too much words = unlist(word.list) # compare our words to the dictionaries of positive & negative terms pos.matches = match(words, pos.words) neg.matches = match(words, neg.words)...
2015 Jan 14
3
Abreviado de especies
Hola, Vaya desastre al mandar la cabecera de la base de datos. Al enviarlo, se veía bien, pero está visto que por el camino la cosa se torció. Siguiendo el consejo de Javier, he subido un pequeño fragmento al DropBox. He quitado algunas especies para no hacerlo muy largo. Espero que ésta vez no haya problemas. https://www.dropbox.com/s/q7zla50oq7owg8k/CPUE.csv?dl=0 Un saludo y gracias Juan
2015 Jan 14
3
Abreviar nombres ciéntificos
...iones, es la stringr si tienes los datos más o menos adecuadamente dispuestos. > Puede que en tu caso funciones como la de str_extract(string, pattern) sea interesante para localizar exactamente el sitio donde está el espacio en blanco o para extraer en 2 componentes los 2 elementos puede usarse str_split(string, pattern, n = Inf) > Espero haber ayudado > Un saludo, Francisco > > Date: Mon, 12 Jan 2015 20:09:06 -0300 > > From: javier.ruben.marcuzzi en gmail.com > > To: r-help-es en r-project.org > > Subject: Re: [R-es] Abreviar nombres ciéntificos > > > >...
2018 May 25
1
options other than regex
Numbers -- thanks. Another clever trick. On 5/25/2018 11:54 AM, Greg Minshall wrote: > Evan, > > are you really looking at numbers, or just at character strings (that, > in your case, happen to be numbers)? if just characters, this rather > odd combination of strsplit() and Reduce() might do the trick: > ---- >> x <- '10110111' >> print(x) > [1]
2013 Apr 10
3
Stringr Package
Hi Group, I have a question on Stringr package I have a table like this X Y ab su - di ac pi - tu ad tu - tu I want output like this X Y ab su ab di ac pi ac tu ad tu ad tu I am wondering if this operation can be done using stringr package (only) ? [[alternative HTML version deleted]]
2012 Mar 07
3
GPS handling libraries or (String manipulation)
Dear all, I would like to ask you if R has a library that can work with different GPS formats For example  I have a string of this format N50° 47.513 E006° 03.985 and I would like to convert to GPS decimal format. that means for example converting the part N50° 47.513 to 50 + 47/60 + 513/3600. Is it possible to do that with R? What is the name of such a library? I would like to thank you in
2017 Sep 04
1
Dataframe Manipulation
...tidyr) > > data_help <- read_csv("data_help.csv") > cat_help <- read_csv("cat_help.csv") > > # Helper function to split the Items and create a data_frame > split_items <- function(items){ > x <- items$Items_purchased_on_Receipts %>% > str_split(pattern = ",") %>% > unlist(use.names = FALSE) > > data_frame(Item = x, Purchase_ID = items$Purchase_ID) > } > > data_help <- > data_help %>% > mutate(Purchase_ID = 1:n()) %>% > group_by(Purchase_ID) %>% > do(split_items(.)) &gt...
2017 Aug 31
0
Dataframe Manipulation
...brary(dplyr) library(stringr) library(tidyr) data_help <- read_csv("data_help.csv") cat_help <- read_csv("cat_help.csv") # Helper function to split the Items and create a data_frame split_items <- function(items){ x <- items$Items_purchased_on_Receipts %>% str_split(pattern = ",") %>% unlist(use.names = FALSE) data_frame(Item = x, Purchase_ID = items$Purchase_ID) } data_help <- data_help %>% mutate(Purchase_ID = 1:n()) %>% group_by(Purchase_ID) %>% do(split_items(.)) cat_help %>% gather("Foo", "Item...
2013 Apr 27
11
Help
Hello, I have a question and need your help urgently. I am new to R but want to learn it. I have several files in a folder which I have imported to R using : temp = list.files(pattern="*.txt") >myfiles = lapply(temp, read.delim) The resulting files are on the workspace stored as List[110]. So they are 110 files in the list. Each file has several different columns and rows. My
2015 Jan 12
3
Abreviar nombres ciéntificos
Hola a tod en s, Estoy tratando de abreviar nombres ciéntificos pero no me gusta cómo queda usando make.cepnames de la librería vegan. Me gustaría poderlos abreviar así, Hymenocephalus italicus --> H.italicus Merluccius merluccius --> M.merluccius He probado con varias opciones y no consigo dar con ello. Estoy casi seguro de que es algo relativamente sencillo, pero no doy con ello.