Displaying 20 results from an estimated 10000 matches similar to: "extending strsplit(): supply pattern to keep, not to split by"
2008 Jun 14
2
strsplit, keeping delimiters
Hi all,
Does anyone have a version of strsplit that keeps the string that is
split by. e.g. from
x <- "A: 123 B: 456 C: 678"
I'd like to get
c("A:", "123 ", "B: ", "456 ", "C: ", 678)
but
strsplit(x, "[A-Z]+:")
gives me
c("", " 123 ", " 456 ", " 678")
Any ideas?
Thanks,
2010 Jul 08
2
strsplit("dia ma", "\\b") splits characterwise
\b is word boundary.
But, unexpectedly, strsplit("dia ma", "\\b") splits character by character.
> strsplit("dia ma", "\\b")
[[1]]
[1] "d" "i" "a" " " "m" "a"
> strsplit("dia ma", "\\b", perl=TRUE)
[[1]]
[1] "d" "i" "a" " "
2009 Jun 11
2
need help with strsplit function
Hi, if I have this string: "a.b.c.d" and I use this function:
unlist(strsplit("a.b.c.d", "\\.")), I get this as my output: "a", "b", "c",
and "d". Is there a way to just split on the first period so I obtain only
two pieces like: "a" and "b.c.d"? Anyways, thanks in advance!
--
View this message in context:
2011 Feb 04
3
lapply, strsplit, and list elements
Hi there,
I have a problem about lapply, strsplit, and accessing list elements,
which I don't understand or cannot solve:
I have e.g. a character vector with three elements:
x = c("349/077,349/074,349/100,349/117",
"340/384.2,340/513,367/139,455/128,D13/168",
"600/437,128/903,128/904")
The task I want to perform, is to generate a list,
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 Aug 30
1
strsplit and regexp
Dear list,
I am trying to split a string using regexp:
x <- "2 Value 34 a-c 45 t"
strsplit(x, "[0-9]")
[[1]]
[1] "" " Value " "" " a-c " "" " t"
But I don't want to lose the digits (pattern), the result
should be:
[[1]]
[1] "2" " Value " "34" " a-c "
2008 Oct 15
4
strsplit and regex
Hi All,
Is there a means to extract the "10" from "23:10:34" in one pass using
strsplit (or something else)?
tst <- "23:10:34"
For example my attempt
strsplit(as.character(tst),"^[0-9]*:")
gives
[[1]]
[1] "" "" "34"
Obviously it is matching the first two instances of [0-9]. Note that
there may be only one digit
2011 Oct 12
5
strsplit question
Dear R People:
I have the following set of data
> Block[1:5]
[1] "5600-5699" "6100-6199" "9700-9799" "9400-9499" "8300-8399"
and I want to split at the -
> strsplit(Block[1:5],"-")
[[1]]
[1] "5600" "5699"
[[2]]
[1] "6100" "6199"
[[3]]
[1] "9700" "9799"
[[4]]
[1]
2009 May 07
1
extending strsplit to handle missing text that doesn't have the target on which to split
I am sure there is an obvious answer to this that I'm missing but I
can't find it. I'm parsing headers of Emails and most have a date like
this:
"Wed, 16 Nov 2005 05:28:00 -0800"
and I can parse that using:
tmp.dat.data <- matrix(unlist(strsplit(headers$Date.line,",")),
ncol = 2, byrow = TRUE)
before going on to look at the day and date/time data.
2009 Nov 18
2
parsing numeric values
Dear list,
I'm seeking advice to extract some numeric values from a log file
created by an external program. Consider the following example,
input <-
readLines(textConnection(
"some text
<ax> = 1.3770E-03 <bx> = 3.4644E-07
<ay> = 1.9412E-04 <by> = 4.8840E-08
other text
<aax> = 1.3770E-03 <bbx> = 3.4644E-07
2008 Oct 29
6
substring/strsplit question
Dear R People:
Here is a toy example:
> x <- c("2E","5W","12H")
> substr(x,2,2)
[1] "E" "W" "2"
>
Sometimes x has 3 elements, sometimes 2. I want to extract the last
element, and then extract the other 1 or 2 elements.
How can I do this, please?
TIA,
Sincerely,
Erin
--
Erin Hodgess
Associate Professor
Department of
2010 May 20
3
regex help: splitting strings with no separator
Greetings,
I have a vector of values that are a word followed by a number, e.g., x =
c("Apple12","HP42","Dell91"). The goal is to split this vector into two
vectors such that the first vector contains just the words and the second
contains just the numbers. I cannot use strsplit (or at least I do not know
how) as there is no obvious separator.
I can use sub to
2013 Sep 18
2
strsplit with a vector split argument
Hi,
I find this behavior unexpected:
--8<---------------cut here---------------start------------->8---
> strsplit(c("a,b;c","d;e,f"),c(",",";"))
[[1]]
[1] "a" "b;c"
[[2]]
[1] "d" "e,f"
--8<---------------cut here---------------end--------------->8---
I thought that it should be identical to this:
2012 Jan 12
3
strsplit() does not split on "."?
Any ideas what is wrong?
> strsplit("a.b", ".") # generates empty strings with split="."
[[1]]
[1] "" "" ""
> strsplit("a b", " ") # seems to work fine with split=" ", and other
characters...
[[1]]
[1] "a" "b"
>
> R.Version()
$platform
[1]
2009 Sep 07
2
using an array of strings with strsplit, issue when including a space in split criteria
Dear all,
I'm having a problem understanding why a split does not occur with in
the 2nd use of the function strsplit below:
# text strings
> txt <- c("sales to 23 August 2008 published 29 August",
+ "sales to 6 September 2008 published?11 September")
# first use
> strsplit(txt, 'published', fixed=TRUE)
[[1]]
[1] "sales to 23 August 2008 "
2008 Dec 09
4
extract the digits of a number
Hello,
Anyone knows how can I do this in a cleaner way?
mynumber = 1001
as.numeric(unlist(strsplit(as.character(mynumber),"")))
[1] 1 0 0 1
Thanks in advance,
Gustavo
2010 Apr 23
2
Problem with parsing a dataset - help earnestly sought
Dear fellow R-help members,
I hope to seek your advice on how to parse/manage a dataset with hundreds of
columns. Two examples of these columns, 'cancer.problems', and
'neuro.problems' are depicted below. Essentially, I need to parse this into
a useful dataset, and unfortunately, I am not familiar with perl or any such
language.
data <- data.frame(id=c(1:10))
2012 May 30
1
gsub/strsplit with multiple patterns/splits
Hi,
I have a vector like this:
DF <- c("Aetna, Inc.", "Alexander's Inc.", "Allegheny Energy, Inc")
For each element in the vector I would like to remove the "incorporated"
info, so that my vector looks like this:
DF <- c("Aetna", "Alexander's", "Allegheny Energy")
That means that I have to strip:
strip <-
2011 May 26
4
Applying "toupper" to only portions of text strings
Colleagues
Assume that I have a vector containing some text strings, some of which contain a particular character. I could like to apply "toupper" to the text before the character. For example (in this case, "|" is the particular character):
ORIGINAL:
TEXT <- c("aaaa", "bbb|cc", "|ddd")
AFTER APPLICATION OF toupper:
TEXT <-
2012 Apr 11
1
strsplit help
Dear all,
I want to use string split to parse column names, however, I am having
some errors that I don't understand.
I see a problem when I try to rbind the output from strsplit.
please let me know if I'm missing something obvious,
thanks,
alison
here are my commands:
>strsplit<-strsplit(as.character(Rumino_Reps_agreeWalign$geneid),"\\.")
>