Displaying 20 results from an estimated 10000 matches similar to: "strsplit and regexp"
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,
2008 Nov 28
3
regexp help needed
Hello,
I have a vector of dates and I would like to grep the year component
from this vector (= all digits
after the last punctuation character)
dates <- c("28.7.08","28.7.2008","28/7/08", "28/7/2008", "28/07/2008",
"28-07-2008", "28-07-08")
the resulting vector should look like
"08" "2008"
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:
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 Feb 25
3
regexp capturing group in R
Hello,
Newbie question: how do you capture groups in a regexp in R?
Let's say I have txt="blah blah start=20080101 end=20090224".
I'd like to get the two dates start and end.
In Perl, one would say:
my ($start,$end) = ($txt =~ /start=(\d{8}).*end=(\d{8})/);
I've tried:
txt <- "blah blah start=20080101 end=20090224"
m <-
2010 Nov 17
2
Regexp question
I have a vector like this:
a <- c("thisIsName", "thisIsAlsoName", "andThisName")
How to break this into pieces and produce a vector with unique parts:
this
Is
Name
Also
and
This
-J
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
2008 Aug 12
2
perl expression question
I have a string such as
fileName<-"Agg.20.20.20-all-01".
All I want to do is pull the "20.20.20" and the "all" as strings.
Obviously, they aren't always those values.
The "20.20.20" can be "30.30.30" but it's always after the . which is
next to the second g in Agg and it's always the same length. The all
might not always be
2009 Mar 03
4
regular expression question
can someone show me how to use a regular expression to break the string
at the bottom up into its three components :
(-0.791,-0.263]
(-38,-1.24]
(0.96,2.43]
I tried to use strplit because of my regexpitis ( it's not curable. i've
been to many doctors all over NYC. they tell me there's no cure ) but
it doesn't work because there also dots inside the brackets. Thanks.
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]
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.
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,
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.",
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
2008 Apr 09
11
Number of words in a string
Hi R,
A quick question: How do we find the number of words in a string?
Example:
C="Have a nice day"
And the number of words should be 4. any built in function or?...
Thanks, Shubha
Shubha Karanth | Amba Research
Ph +91 80 3980 8031 | Mob +91 94 4886 4510
Bangalore * Colombo * London * New York * San José * Singapore * www.ambaresearch.com
This e-mail may contain
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
2006 Jul 23
3
RfW 2.3.1: regular expressions to detect pairs of identical word-final character sequences
Dear all
I use R for Windows 2.3.1 on a fully updated Windows XP Home SP2 machine and I have two related regular expression problems.
platform i386-pc-mingw32
arch i386
os mingw32
system i386, mingw32
status
major 2
minor
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 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
2009 Jul 08
5
R regular expression to extract words with the query string.
Hi,
Is there a way in R to get the string which matches the expression, where
the expression is a substring of the parent string.
Lets say, I have $i <- "transcript:ENST0000112334 pid:ENSP000012345"
What I need is the string "pid:ENSP000012345" from $i using the query
"ENSP".
Appreciate your comments.
Praveen Surendran
School of Medicine and