similar to: regex help: splitting strings with no separator

Displaying 20 results from an estimated 3000 matches similar to: "regex help: splitting strings with no separator"

2008 Nov 02
5
R newbie: how to replace string/regular expression
Hello; I am a R newbie and would like to know correct and efficient method for doing string replacement. I have a large data set, where I want to replace character "M", "b", and "K" (currency in Million, Billion and K) to millions. That is 209.7B with (209.7 * 10e6) and 100.00K with (100.00 *1/100) and etc.. d <- c("120.0M", "11.01m",
2009 Jul 07
3
Numbering sequences of non-NAs in a vector
Greetings, I have a vector of the form: [10,8,1,3,0,8,NA,NA,NA,NA,2,1,6,NA,NA,NA,0,5,1,9...] That is, a combination of sequences of non-missing values and missing values, with each sequence possibly of a different length. I'd like to create another vector which will help me pick out the sequences of non-missing values. For the example above, this would be:
2010 Jan 06
1
Write a blank line to CSV
Greetings and happy new year! I'm attempting to write a series of tables to a CSV file, and would like to insert a blank line after each table. To do this, I use: > write.csv(NULL,"tables.csv",append=T) which appears to work, except that this warning is thrown: > Warning message: > In write.table(NULL, "tables.csv", append = T, col.names = NA, : > appending
2010 Aug 06
2
stats::reshape question
Hello, A quick question for my edification. When I run the following (R 2.8.1 on Microsoft Windows): > d = data.frame(x1=c(1,2),x2=c(3,4),y1=c(5,6),y2=c(7,8)) > reshape(d,varying=c("y1","x1","y2","x2"),v.names=c("y","x"),dir="long") I found myself surprised by the results--the column labeled "y" is actually
2011 Oct 24
2
splitting a string into words preserving blanks (using regex)
I would like to split a string into words at its blanks but also to preserve all blanks. Example: c(" some words to split ") should become c(" ", "some", " ", " words", " ", "to" , " ", "split", " ") I was not able to achieve this via strsplit() . But I am not familiar with regular
2010 Dec 02
2
Hmisc label function applied to data frame
Hello, I'm attempting to create a data frame with correlations between every pair of variables in a data frame, so that I can then sort by the value of the correlation coefficient and see which pairs of variables are most strongly correlated. The sm2vec function in the corpcor library works very nicely as shown here: library(Hmisc) library(corpcor) # Create example data x1 = runif(50) x2 =
2008 Jan 18
1
Regex magic anyone?
Hi again, how to elegantly split s <- "ABCDEFGT(P)HIJK" into "A" "B" "C" "D" "E" "F" "G" "T(P)" "H" "I" "J" "K" (independently of which letters 'T' or 'P' actually represent ...). Please jumstart my regexing, Joh
2023 Apr 12
1
Split String in regex while Keeping Delimiter
On Wed, 12 Apr 2023 08:29:50 +0000 Emily Bakker <emilybakker at outlook.com> wrote: > Some example data: > ?leucocyten + gramnegatieve staven +++ grampositieve staven ++? > ?leucocyten ? grampositieve coccen +? > ? > I want to split the strings such that I get the following result: > c(?leucocyten +?, ??gramnegatieve staven +++?, > ??grampositieve staven ++?) >
2008 Nov 11
2
strsplit (regex)
#how do I break these up into first two letters (RM), number, and then the last part #is there an easily accessible regex tutorial on the internet? v = (structure(1:122, .Label = c("RM215Temp", "RM215SpCond", "RM215DO.Conc", "RM215Depth", "RM215pH", "RM215ORP", "RM215Turbidity.", "RM215Battery", "RM215DO.",
2008 Oct 28
1
gsubfn, strapply, REGEX Problem
Hi all, I swear this used to work: library(gsubfn) strapply("S(AC,P)TVDK(8)EELVQK(8), ".[(].{1,2}[)]|.")[[1]] But somewhere along the update path it stopped ... now giving me this Error in base::gsub(pattern, rs, x, ...) : invalid backreference 2 in regular expression Can't figure it out. What am I doing wrong? Thanks for any hints, Joh
2009 Aug 04
4
regex question
Hi, I am getting stuck over an apparently simple problem in the use of regular expressions : To collect together the first letters of the words from the Perl motto, ?There is more than one way to do it? in the following form ? TIMTOWTDI. I tried the following code : ? ##### A regex problem with the Perl motto astr<-"There is more than one way to do it" b1<-grep("\\<",
2010 Sep 16
2
glm: formula vs character
Hello, This is a question motivated by curiosity, not a pressing problem. Any responses are much appreciated! In the following code, function reg1 calls glm with a formula object while reg2 uses a string. In both cases, glm works; however, in the second case, the add1 function fails with the following message: "Error in eval(predvars, data, env) : invalid 'envir' argument."
2010 Feb 18
3
parsing strings between [ ] in columns
Dear all, I have a data.frame with a column like the x shown below myDF<-data.frame(cbind(x=c("[[1, 0, 0], [0, 1]]", "[[1, 1, 0], [0, 1]]","[[1, 0, 0], [1, 1]]", "[[0, 0, 1], [0, 1]]"))) > myDF x 1 [[1, 0, 0], [0, 1]] 2 [[1, 1, 0], [0, 1]] 3 [[1, 0, 0], [1, 1]] 4 [[0, 0, 1], [0, 1]] As you can see my x column is composed of
2010 Mar 15
2
tcltk and R
I have had some comments on sqldf regarding its dependence on tcltk such as the second last sentence on this blog post: http://translate.google.com/translate?hl=en&sl=zh-CN&u=http://www.wentrue.net/blog/%3Fp%3D453&prev=http://blogsearch.google.com/blogsearch%3Fhl%3Den%26ie%3DUTF-8%26q%3Dsqldf%26lr%3D%26sa%3DN%26start%3D10 sqldf does not directly use tcltk but it does use strapply in
2007 Aug 23
2
Splitting strings
I'm having a Thursday morning mental block, any suggestions on the following would be most appreciated... I have (as an example) surgery = c("d48", "d67", "dnc37", "a75", "d10", "a78", "d31", "d55", "d1") before each number part the possibilities are c("a", "d",
2010 Jul 02
3
Good Package(s) for String and URL processing?
Are there packages that allow improved String and URL processing? E.g. extract parts of a URLs such as sub-domains, top-level domain, protocols (e.g. https, http, ftp), file type based on endings, check if a URL is valid or not, etc... I am currently only using split and paste. Are there better and more efficient ways to handle strings e.g. finding sub-strings or to do pattern matching? What
2010 Aug 26
5
Quick GREP challenge
> grep("f[0-9]+=", "f1=5,f22=3,", value = T) [1] "f1=5,f22=3," How do I make the line output c("f1", "f22") instead? (Actually, c(1,22) would be even better). Thank you. -- View this message in context: http://r.789695.n4.nabble.com/Quick-GREP-challenge-tp2339486p2339486.html Sent from the R help mailing list archive at Nabble.com.
2006 Sep 25
2
Splitting a character variable into a numeric one and a character one?
Hi All, I have a data with a variable like this: Column 1 "123abc" "12cd34" "1e23" ... Now I want to do an operation that can split it into two variables: Column 1 Column 2 Column 3 "123abc" 123 "abc" "12cd34" 12 "cd34" "1e23" 1
2008 Aug 01
2
Extract Element of String with R's Regex
Hi, I have this string, in which I want to extract some of it's element: > x <- "Best-K Gene 11340 211952_at RANBP5 Noc= 3 - 2 LL= -963.669 -965.35" yielding this array [1] "211952_at" "RANBP5" "2" In Perl we would do it this way: __BEGIN__ my @needed =(); my $str = "Best-K Gene 11340 211952_at RANBP5 Noc= 3 - 2 LL= -963.669
2008 Jan 23
1
Package Building and Name Space
Hello, I just don't get this and would appreciate if someone could write a line or two: I'm trying to build this package and it stops installing after I add the following to the NAMESPACES file: >importFrom(gsubfn,strapply) The error during the package test is: Error in MyPackage::MyFunction : package 'MyPackage' has no name space and is not on the search path Calls: