Re: [R] strsplit with a vector split argument

2013-09-18 Thread arun
Hi, You could try: strsplit(c("a,b;c","d;e,f"),",|;") #[[1]] #[1] "a" "b" "c" # #[[2]] #[1] "d" "e" "f" A.K. - Original Message - From: Sam Steingold To: r-help@r-project.org Cc: Sent: Wednes

Re: [R] strsplit with a vector split argument

2013-09-18 Thread Hervé Pagès
er a|b|c|d|e. It's also more compact and easier to read. H. #[[1]] #[1] "a" "b" "c" # #[[2]] #[1] "d" "e" "f" A.K. - Original Message - From: Sam Steingold To: r-help@r-project.org Cc: Sent: Wednesday, September 18, 2

Re: [R] strsplit with a vector split argument

2013-09-18 Thread Marc Schwartz
On Sep 18, 2013, at 10:42 AM, Sam Steingold wrote: > 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--

[R] strsplit with a vector split argument

2013-09-18 Thread Sam Steingold
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 th

Re: [R] strsplit with invalid regular expression

2012-11-08 Thread Jeff Newmiller
In R, the source code representation of a special character uses the \ as an escape character to begin a special character sequence. For example, "\n" is a single newline character. Because backslash has this special meaning, to represent a single backslash character one must escape it: "\\" lo

Re: [R] strsplit with invalid regular expression

2012-11-08 Thread arun
HI, cond<-"andsin(log_angle_1_4)"  diff_operator<-"sin\\("  strsplit(cond,diff_operator) #[[1]] #[1] "and"    "log_angle_1_4)" A.K. - Original Message - From: Bharat Warule To: r-help@r-project.org Cc: Sent: Thursday, Novem

Re: [R] strsplit with invalid regular expression

2012-11-08 Thread Ulrich Staudinger
> strsplit(")asdasdsin(abcd)", "sin\\(") [[1]] [1] ")asdasd" "abcd)" > On Thu, Nov 8, 2012 at 12:39 PM, Bharat Warule wrote: > Hi all, > > > diff_operator <- "\\(" > > strsplit(cond, diff_operator) > [[1]] > [1] "andsin" "log_angle_1_4)" > > > diff_operator <- "\\sin(" > > strsplit(co

[R] strsplit with invalid regular expression

2012-11-08 Thread Bharat Warule
Hi all, > diff_operator <- "\\(" > strsplit(cond, diff_operator) [[1]] [1] "andsin" "log_angle_1_4)" > diff_operator <- "\\sin(" > strsplit(cond, diff_operator) Error in strsplit(cond, diff_operator) : invalid regular expression '\sin(', reason 'Missing ')'' When I am going to split w

Re: [R] strsplit help

2012-04-12 Thread Jean V Adams
Alison, You've got two geneids with two periods (instead of just one period). gene.list <- strsplit(as.character(Rumino_Reps_agreeWalign$geneid),"\\.") Rumino_Reps_agreeWalign[sapply(gene.list, length)!=2, ] geneid count_Conser count_NonCons count_ConsSubst count_NCSubst 74

Re: [R] strsplit help

2012-04-12 Thread alison waller
Thanks - I checked through and it looks as if all of the geneids are formatted similarily so I don't know which one would be causing an error. Interestingly, your sapply method works on the same data. So I'm happy although still confused, because the strsplit method worked the other day with a

Re: [R] strsplit help

2012-04-11 Thread Jean V Adams
David, Right you are! Thanks for pointing that out. strsplit <- 1:10 strsplit("With spaces", NULL) strsplit Jean David Winsemius wrote on 04/11/2012 01:17:07 PM: > [image removed] > > Re: [R] strsplit help > > David Winsemius > > to: > > Jean

Re: [R] strsplit help

2012-04-11 Thread David Winsemius
On Apr 11, 2012, at 2:01 PM, Jean V Adams wrote: Alison, Your code works fine on the first six lines of the data that you provided. Rumino_Reps_agreeWalign <- data.frame( geneid = c("657313.locus_tag:RTO_08940", "457412.251848018", "657314.locus_tag:CK5

Re: [R] strsplit help

2012-04-11 Thread Jean V Adams
Alison, Your code works fine on the first six lines of the data that you provided. Rumino_Reps_agreeWalign <- data.frame( geneid = c("657313.locus_tag:RTO_08940", "457412.251848018", "657314.locus_tag:CK5_20630", "657323.locus_tag:CK1_330

[R] strsplit help

2012-04-11 Thread alison waller
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

Re: [R] Strsplit with a separator of ||

2012-03-22 Thread jing tang
Thanks! JIng -Original Message- From: Berend Hasselman [mailto:b...@xs4all.nl] Sent: 22. maaliskuuta 2012 9:33 To: Berend Hasselman Cc: jing tang; r-help@r-project.org Subject: Re: [R] Strsplit with a separator of || On 22-03-2012, at 08:28, Berend Hasselman wrote: > > On 22-0

Re: [R] Strsplit with a separator of ||

2012-03-22 Thread jim holtman
You need another \\ > strsplit("a||bc","\\|\\|") [[1]] [1] "a" "bc" > On Thu, Mar 22, 2012 at 3:23 AM, jing tang wrote: > Hi, > > I tried to use strsplit for separating a string with || like > strsplit(string,"\\||") but it returned each single character was separated. > > For example: > > s

Re: [R] Strsplit with a separator of ||

2012-03-22 Thread Berend Hasselman
On 22-03-2012, at 08:28, Berend Hasselman wrote: > > On 22-03-2012, at 08:23, jing tang wrote: > >> Hi, >> >> I tried to use strsplit for separating a string with || like >> strsplit(string,"\\||") but it returned each single character was separated. >> >> For example: >> >> strsplit("a||bc"

Re: [R] Strsplit with a separator of ||

2012-03-22 Thread Berend Hasselman
On 22-03-2012, at 08:23, jing tang wrote: > Hi, > > I tried to use strsplit for separating a string with || like > strsplit(string,"\\||") but it returned each single character was separated. > > For example: > > strsplit("a||bc","\\||") > > [[1]] > > [1] "a" "" "" "b" "c" > > where I wan

[R] Strsplit with a separator of ||

2012-03-22 Thread jing tang
Hi, I tried to use strsplit for separating a string with || like strsplit(string,"\\||") but it returned each single character was separated. For example: strsplit("a||bc","\\||") [[1]] [1] "a" "" "" "b" "c" where I want the result to be "a" and "bc". Any ideas? Thanks! Best

Re: [R] strsplit() does not split on "."?

2012-01-12 Thread Czerminski, Ryszard
al Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Czerminski, Ryszard Sent: Thursday, January 12, 2012 10:16 AM To: r-help Subject: [R] strsplit() does not split on "."? Any ideas what is wrong? > strsplit("a.b", ".&quo

Re: [R] strsplit() does not split on "."?

2012-01-12 Thread Jorge I Velez
Hi Ryszard, Try strsplit("a.b", "[.]")[[1]] and see "Extended Regular Expressions" in ?regexp. HTH, Jorge,- On Thu, Jan 12, 2012 at 10:15 AM, Czerminski, Ryszard <> wrote: > Any ideas what is wrong? > > > strsplit("a.b", ".") # generates empty strings with split="." > [[1]] > [1] "" "" "" >

Re: [R] strsplit() does not split on "."?

2012-01-12 Thread Sarah Goslee
Reread the help for strsplit: ## Note that 'split' is a regexp! ## If you really want to split on '.', use unlist(strsplit("a.b.c", "\\.")) ## [1] "a" "b" "c" ## or unlist(strsplit("a.b.c", ".", fixed = TRUE)) For your example: > strsplit("a.b", "\\.") [[1]] [1] "a"

[R] strsplit() does not split on "."?

2012-01-12 Thread Czerminski, Ryszard
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] "x86_64-unknown-linux-gnu" $arch [1] "x86_64" $os [1] "l

Re: [R] strsplit question

2011-10-12 Thread Gabor Grothendieck
On Wed, Oct 12, 2011 at 1:20 AM, Erin Hodgess wrote: > 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] "610

Re: [R] strsplit question

2011-10-11 Thread David Winsemius
On Oct 12, 2011, at 1:20 AM, Erin Hodgess wrote: 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] "9

Re: [R] strsplit question

2011-10-11 Thread Remko Duursma
Hi Erin, this is one way: Block <- c("5600-5699","6100-6199","9700-9799","9400-9499","8300-8399") splBlock <- strsplit(Block,"-") sapply(splBlock, "[", 1) greetings, Remko -- View this message in context: http://r.789695.n4.nabble.com/strsplit-question-tp3896847p3896850.html Sent from th

Re: [R] strsplit question

2011-10-11 Thread Jeff Newmiller
sapply(strsplit(Block[1:5],"-"), function (x) {x[1]}) comes to mind... --- Jeff Newmiller The . . Go Live... DCN: Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#.

Re: [R] strsplit question

2011-10-11 Thread Joshua Wiley
unlist(strsplit(Block[1:5], "-.+$")) if you are going to want the other pieces later, the most efficient way depends on the assumptions you can make about your data. If there are always two elements from the split: matrix(unlist(strsplit(Block[1:5], "-")), ncol = 2, byrow = TRUE) ## or do.call("

[R] strsplit question

2011-10-11 Thread Erin Hodgess
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] "9400" "9499" [[5]] [1] "8300

Re: [R] strsplit and forward slash '/'

2011-08-03 Thread Federico Calboli
On 3 Aug 2011, at 17:46, Sarah Goslee wrote: > Hi Federico, > > A forward slash isn't a special character: > >> strsplit("T/T", "/") > [[1]] > [1] "T" "T" > > so there's some other problem. > > Are you sure that your first column contains strings and not factors? > What does str(my.data) tell

Re: [R] strsplit and forward slash '/'

2011-08-03 Thread Federico Calboli
On 3 Aug 2011, at 17:41, Duncan Murdoch wrote: > > It looks as though your my.data[1,1] value is a factor, not a character value. > > strsplit(as.character(my.data[1,1]), "/") Thanks Duncan, this solved it. Best Federico > > would work, or you could avoid getting factors in the first plac

Re: [R] strsplit and forward slash '/'

2011-08-03 Thread Sarah Goslee
Hi Federico, A forward slash isn't a special character: > strsplit("T/T", "/") [[1]] [1] "T" "T" so there's some other problem. Are you sure that your first column contains strings and not factors? What does str(my.data) tell you? Does strsplit(as.character(my.data[1,1]), "/") work? If you us

Re: [R] strsplit and forward slash '/'

2011-08-03 Thread Duncan Murdoch
On 03/08/2011 12:37 PM, Federico Calboli wrote: Hi All, is there a way of using strsplit with a forward slash '/' as the splitting point? For data such as: 1 T/TC/C 16/33 2 T/TC/C 33/36 3 T/TC/C 16/34 4 T/TC/C 16/31 5 C/CC/C 28/29 6 T/T

[R] strsplit and forward slash '/'

2011-08-03 Thread Federico Calboli
Hi All, is there a way of using strsplit with a forward slash '/' as the splitting point? For data such as: 1 T/TC/C 16/33 2 T/TC/C 33/36 3 T/TC/C 16/34 4 T/TC/C 16/31 5 C/CC/C 28/29 6 T/TC/C 16/34 strsplit(my.data[1,1], "/") # and an

Re: [R] StrSplit

2010-10-09 Thread Santosh Srinivas
Thanks Jim. Exactly what I needed! -Original Message- From: jim holtman [mailto:jholt...@gmail.com] Sent: 09 October 2010 22:01 To: Santosh Srinivas Cc: r-help@r-project.org Subject: Re: [R] StrSplit Is this what you are after: > x <- c("Scheme Code;Scheme Name;Net

Re: [R] StrSplit

2010-10-09 Thread Jeffrey Spies
Obviously Jim's solution does work, and I did not intend to imply it didn't. In fact, his read.table solution would work both if the OP had a semi-colon delimited file to begin with (which I was trying to say was ideal from a workflow standpoint) or a vector of strings (for use when paired with te

Re: [R] StrSplit

2010-10-09 Thread David Winsemius
On Oct 9, 2010, at 12:46 PM, Jeffrey Spies wrote: Jim's solution is the ideal way to read in the data: using the sep=";" argument in read.table. However, if you do for some reason have a vector of strings like the following (maybe someone gives you an Rdata file instead of the raw data file):

Re: [R] StrSplit

2010-10-09 Thread Jeffrey Spies
Jim's solution is the ideal way to read in the data: using the sep=";" argument in read.table. However, if you do for some reason have a vector of strings like the following (maybe someone gives you an Rdata file instead of the raw data file): MF_Data <- c("106506;AIG India Liquid Fund-Institutio

Re: [R] StrSplit

2010-10-09 Thread jim holtman
Is this what you are after: > x <- c("Scheme Code;Scheme Name;Net Asset Value;Repurchase Price;Sale > Price;Date" + , "" + ,"Open Ended Schemes ( Liquid )" + , "" + , "" + , "AIG Global Investment Group Mutual Fund" + , "106506;AIG India Liquid Fund-Institutional Plan-Daily Dividend Option;1001.

[R] StrSplit

2010-10-09 Thread Santosh Srinivas
Newbie question ... I am looking something equivalent to read.delim but which accepts a text line as parameter instead of a file input. Below is my problem, I'm unable to get the exact output which is a simple data frame of the data where the delimiter exists ... coming quite close though I

Re: [R] strsplit("dia ma", "\\b") splits characterwise

2010-07-08 Thread Gabor Grothendieck
On Thu, Jul 8, 2010 at 4:15 AM, Suharto Anggono Suharto Anggono wrote: > \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] "

Re: [R] strsplit("dia ma", "\\b") splits characterwise

2010-07-08 Thread Joris Meys
l guess this is expected behaviour, although counterintuitive. \b represents an empty string indicating a word boundary, but is coerced to character and thus simply the empty string. This means the output you get is the same as > strsplit("dia ma", "",perl=T) [[1]] [1] "d" "i" "a" " " "m" "a" I'd

[R] strsplit("dia ma", "\\b") splits characterwise

2010-07-08 Thread Suharto Anggono Suharto Anggono
\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" " " "m" "a" How can that be? This is the output of 'gregexpr'. > gregexpr

Re: [R] strsplit

2010-06-01 Thread Ista Zahn
Another option is to use the colsplit() function (in the reshape package): testdata <- data.frame(sp = c("GenusA_SpeciesC_Tree", "GenusA_SpeciesF_Tree", "GenusB_SpeciesA_Shrub"), stringsAsFactors=FALSE) library(reshape) testdata <- cbind(testdata, colsplit(testdata$sp, split="_", names=c("Genus",

Re: [R] strsplit

2010-06-01 Thread Rafael Björk
This might not be the most elegant way of doing it, but it should probably work, given that data is always separated by a "_". string.1<-strsplit(c("GenusA_SpeciesC_Tree","GenusA_SpeciesF_Tree", "GenusB_SpeciesA_Shrub"),"_") matrix(unlist(string.1),ncol=3,byrow=TRUE) 2010/6/1 Joël Baumann > He

Re: [R] strsplit

2010-06-01 Thread Ivan Calandra
Hi, I don't know if it would help you since your goal is not really clear to me, but here are some thoughts: > x <- c("GenusA_SpeciesC_Tree", "GenusA_SpeciesF_Tree", "GenusB_SpeciesA_Shrub") > test <- strsplit(x, "_") > test [[1]] [1] "GenusA" "SpeciesC" "Tree" [[2]] [1] "GenusA" "Specie

Re: [R] strsplit

2010-06-01 Thread Sarah Goslee
How about this: testdata <- data.frame(sp = c("GenusA_SpeciesC_Tree", "GenusA_SpeciesF_Tree", "GenusB_SpeciesA_Shrub"), stringsAsFactors=FALSE) # for one unlist(strsplit(testdata[1,1], split="_")) # for all of them do.call(rbind, sapply(testdata[,1], strsplit, split="_")) Sarah On Tue, Jun 1,

[R] strsplit

2010-06-01 Thread Joël Baumann
Hello! I have the following problem: I have a file in R that has in the first row three informations in one row that I would like to in three different rows. The first row looks like this: GenusA_SpeciesC_Tree GenusA_SpeciesF_Tree GenusB_SpeciesA_Shrub ... I tried with strsplit and and subs

Re: [R] strsplit() and Windows file paths

2009-10-29 Thread Nordlund, Dan (DSHS/RDA)
> -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of Nordlund, Dan (DSHS/RDA) > Sent: Thursday, October 29, 2009 12:57 PM > To: r-help@r-project.org > Subject: Re: [R] strsplit() and Windows file paths > >

Re: [R] strsplit() and Windows file paths

2009-10-29 Thread Nordlund, Dan (DSHS/RDA)
> -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of Robert Baer > Sent: Thursday, October 29, 2009 12:40 PM > To: r-help@r-project.org > Subject: [R] strsplit() and Windows file paths > > There are two wa

[R] strsplit() and Windows file paths

2009-10-29 Thread Robert Baer
There are two ways to express file paths with the Windows environment: > a=file.choose() > a [1] "C:\\Documents and Settings\\rbaer\\Desktop\\_VNT_Test\\coordFocused 20k F5 0ng Ki8751 t20.txt" and >b= paste(getwd(),"/",dir()[1],sep="") >b [1] "C:/Documents and Settings/rbaer/Desktop/_VNT_Test/co

Re: [R] strsplit a matrix

2009-08-10 Thread Jun Shen
Henrique, This is a very nice approach. I wonder what if I have data like 2-172-45 and want to break it down into three parts 2, 172 and 45. How do we use your method to achieve it? Thanks. Jun On Mon, Aug 10, 2009 at 12:34 PM, Henrique Dallazuanna wrote: > Try this: > > #1 > gsub(".*-", "", zz

Re: [R] strsplit a matrix

2009-08-10 Thread Henrique Dallazuanna
Try this: #1 gsub(".*-", "", zzz) #2 gsub("-.*", "", zzz) #3) gsub(".*-(.*)-.*", "\\1", zzz) On Mon, Aug 10, 2009 at 4:20 PM, Jun Shen wrote: > Henrique, > > This is a very nice approach. I wonder what if I have data like 2-172-45 > and want to break it down into three parts 2, 172 and 45. Ho

Re: [R] strsplit a matrix

2009-08-10 Thread Henrique Dallazuanna
Try this: #1 gsub(".*-", "", zzz) #2 gsub("-.*", "", zzz) On Mon, Aug 10, 2009 at 1:56 PM, James Perkins wrote: > Dear all, > > I am trying to split a matrix into 2 as efficiently as possible. > > It is a character matrix: > > 1 2 3 1 "2-271" "2-367" "1-79" > 2 "2-282" "2-378"

Re: [R] strsplit a matrix

2009-08-10 Thread Dimitris Rizopoulos
one way us the following: mat <- rbind( c("2-271", "2-367", "1-79"), c("2-282", "2-378", "1-90"), c("2-281", "2-377", "1-89") ) sp <- strsplit(c(mat), "-") mat1 <- sapply(sp, "[", 1) mat2 <- sapply(sp, "[", 2) dim(mat1) <- dim(mat2) <- dim(mat) mat1 mat2 I hope it helps. Best, Dim

[R] strsplit a matrix

2009-08-10 Thread James Perkins
Dear all, I am trying to split a matrix into 2 as efficiently as possible. It is a character matrix: 1 2 3 1 "2-271" "2-367" "1-79" 2 "2-282" "2-378" "1-90" 3 "2-281" "2-377" "1-89" I want to make 2 matrices from this, as succinctly and efficiently as possible. I've tried

Re: [R] strsplit for multiple columns

2009-06-03 Thread Henrique Dallazuanna
Try this: do.call(cbind, lapply(a[2:ncol(a)], function(x)do.call(rbind, strsplit(as.character(x), '' On Wed, Jun 3, 2009 at 10:39 AM, Duijvesteijn, Naomi < naomi.duijveste...@ipg.nl> wrote: > > Hi, > > > I am trying to split multiple columns. One column works just fine, but I > want to

[R] strsplit for multiple columns

2009-06-03 Thread Duijvesteijn, Naomi
Hi, I am trying to split multiple columns. One column works just fine, but I want to do it for multiple columns… Example > a ID V2 V3 V4 V5 V6 V7 V8 V9 V10 1 PBBA0644 -- GG AA -- AA -- AA GG GG 2 PBBA1010 -- GG AA -- AA -- AA GG GG 3 0127ATPR -- GG AA -- AA

Re: [R] strsplit

2009-05-30 Thread Uwe Ligges
Henrique Dallazuanna wrote: Try this: unlist(part)[1] or part[[1]][1] And in order to isnpect your objects, use str(part) at first which tells you about the structure of the object. Then you know you got a list and can look up how to extract a part of a list as Henrique Dallazuanna pon

Re: [R] strsplit

2009-05-29 Thread Henrique Dallazuanna
Try this: unlist(part)[1] or part[[1]][1] On Fri, May 29, 2009 at 2:09 PM, Nair, Murlidharan T wrote: > I am trying split a string and use one part of it to label graphs. I am > using strsplit for that. While I am able to split it, how do I access the > separated parts. > > filName<-"chrI_222

[R] strsplit

2009-05-29 Thread Nair, Murlidharan T
I am trying split a string and use one part of it to label graphs. I am using strsplit for that. While I am able to split it, how do I access the separated parts. > filName<-"chrI_2223" >part<- strsplit(filName,"\\_") > part [[1]] [1] "chrI" "2223" > part[1] [[1]] [1] "chrI" "2223" I looked up

Re: [R] strsplit (regex)

2008-11-11 Thread Gabor Grothendieck
You can do this one even more easily without regular expressions like this: substring(v, 1, 2) substring(v, 3) or with regexps: sub("(..).*", "\\1", v) sub("..(.*)", "\\1", v) or in one line using strapply in the gsubfn package: library(gsubfn) # see http://gsubfn.googlecode.com out <- strapp

Re: [R] strsplit (regex)

2008-11-11 Thread Hans W. Borchers
stephen sefick gmail.com> writes: > > #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? For regular expressions, the perl man pages at are quite good and

[R] strsplit (regex)

2008-11-11 Thread stephen sefick
#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", "

Re: [R] strsplit and regex

2008-10-15 Thread Redding, Matthew
:38 AM >To: Redding, Matthew >Cc: r-help@r-project.org >Subject: Re: [R] strsplit and regex > >Here are several solutions: > >#1 ># replace first three and last 3 characters with nothing x <- >c("23:10:34", "01:02:03") gsub("^...|...$", &q

Re: [R] strsplit and regex

2008-10-15 Thread Gabor Grothendieck
Here are several solutions: #1 # replace first three and last 3 characters with nothing x <- c("23:10:34", "01:02:03") gsub("^...|...$", "", x) #2 # backref = -1 says extract the portion in parens # it would have returned a list so we use simplify = c library(gsubfn) strapply(x, ":(..):", backref

Re: [R] strsplit and regex

2008-10-15 Thread Henrique Dallazuanna
Try this: format(strptime(tst, "%H:%M:%S"), "%M") On Wed, Oct 15, 2008 at 6:54 PM, Redding, Matthew < [EMAIL PROTECTED]> wrote: > 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 > s

Re: [R] strsplit and regex

2008-10-15 Thread Prof Brian Ripley
dding -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Redding, Matthew Sent: Thursday, 16 October 2008 7:54 AM To: r-help@r-project.org Subject: [R] strsplit and regex Hi All, Is there a means to extract the "10" from "23:10:34" in on

Re: [R] strsplit and regex

2008-10-15 Thread Erik Iverson
Matthew - Redding, Matthew wrote: 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" Why not simply, strsplit(tst, ":")

Re: [R] strsplit and regex

2008-10-15 Thread Redding, Matthew
er 2008 7:54 AM >To: r-help@r-project.org >Subject: [R] 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 attem

[R] strsplit and regex

2008-10-15 Thread Redding, Matthew
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

Re: [R] strsplit and regexp

2008-08-30 Thread Gabor Grothendieck
Try this: > library(gsubfn) > strapply(x, "[0-9]+| +[^ ]+ *")[[1]] [1] "2" " Value " "34" " a-c " "45" " t" which keeps the spaces around the non-numeric entries as in your example; however, if keeping the spaces is not important then its even easier: > strsplit(x, " ")[[1]] [1

[R] strsplit and regexp

2008-08-30 Thread Patrick Hausmann
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 " "45" " t" Thanks for any tipp Pat

Re: [R] strsplit, keeping delimiters

2008-06-14 Thread Gabor Grothendieck
On Sat, Jun 14, 2008 at 11:46 AM, hadley wickham <[EMAIL PROTECTED]> wrote: > On Sat, Jun 14, 2008 at 10:20 AM, Martin Morgan <[EMAIL PROTECTED]> wrote: >> "hadley wickham" <[EMAIL PROTECTED]> writes: >> n >>> On Sat, Jun 14, 2008 at 12:55 AM, Gabor Grothendieck >>> <[EMAIL PROTECTED]> wrote:

Re: [R] strsplit, keeping delimiters

2008-06-14 Thread hadley wickham
On Sat, Jun 14, 2008 at 10:20 AM, Martin Morgan <[EMAIL PROTECTED]> wrote: > "hadley wickham" <[EMAIL PROTECTED]> writes: > n >> On Sat, Jun 14, 2008 at 12:55 AM, Gabor Grothendieck >> <[EMAIL PROTECTED]> wrote: >>> Try this: >>> library(gsubfn) x <- "A: 123 B: 456 C: 678" strapply(x

Re: [R] strsplit, keeping delimiters

2008-06-14 Thread Martin Morgan
"hadley wickham" <[EMAIL PROTECTED]> writes: n > On Sat, Jun 14, 2008 at 12:55 AM, Gabor Grothendieck > <[EMAIL PROTECTED]> wrote: >> Try this: >> >>> library(gsubfn) >>> x <- "A: 123 B: 456 C: 678" >>> strapply(x, "[^ :]+[ :]|[^ :]+$") >> [[1]] >> [1] "A:" "123 " "B:" "456 " "C:" "678" Also

Re: [R] strsplit, keeping delimiters

2008-06-14 Thread hadley wickham
On Sat, Jun 14, 2008 at 12:55 AM, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > Try this: > >> library(gsubfn) >> x <- "A: 123 B: 456 C: 678" >> strapply(x, "[^ :]+[ :]|[^ :]+$") > [[1]] > [1] "A:" "123 " "B:" "456 " "C:" "678" > > and check out the gsubfn home page at: > > http://gsubfn.go

Re: [R] strsplit, keeping delimiters

2008-06-13 Thread Gabor Grothendieck
Try this: > library(gsubfn) > x <- "A: 123 B: 456 C: 678" > strapply(x, "[^ :]+[ :]|[^ :]+$") [[1]] [1] "A:" "123 " "B:" "456 " "C:" "678" and check out the gsubfn home page at: http://gsubfn.googlecode.com On Sat, Jun 14, 2008 at 1:35 AM, hadley wickham <[EMAIL PROTECTED]> wrote: > Hi a

[R] strsplit, keeping delimiters

2008-06-13 Thread hadley wickham
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, Hadley -- http://

Re: [R] strsplit and sapply

2008-04-11 Thread Jonathan Baron
Here is a command I wrote to get the part of the email address before the @ sign. It works, but I don't know why. The variable called email is a vector of email addresses (not yet in character form, so that is why I need "as character"). names(Score) <- sapply(email,function(x) (strsplit(as.cha

Re: [R] strsplit and sapply

2008-04-11 Thread Dimitris Rizopoulos
Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: "Dennis Fisher" <[EMAIL PROTECTED]> To: Sent: Friday

Re: [R] strsplit and sapply

2008-04-11 Thread Henrique Dallazuanna
Try: sapply(strsplit(TEXT, ';'), '[', 1) On Fri, Apr 11, 2008 at 8:12 AM, Dennis Fisher <[EMAIL PROTECTED]> wrote: > Colleagues, > > I have some text: >TEXT<- c("a", "bb;ccc", ";e;ff") > > I want to retrieve the portion of each element before the first > semicolon. I can

[R] strsplit and sapply

2008-04-11 Thread Dennis Fisher
Colleagues, I have some text: TEXT<- c("a", "bb;ccc", ";e;ff") I want to retrieve the portion of each element before the first semicolon. I can split each element using strsplit: SPLIT <- strsplit(TEXT, ";") This yields: > SPLIT [[1]] [1] "a" [[2]] [1] "bb

Re: [R] strsplit on comma, with a trailing comma in input

2007-12-03 Thread dankelley
This works perfectly. Thanks! Peter Dalgaard wrote: > >> > Hmm, I don't think strsplit can do that. However: > > > scan(textConnection("a,,b,"), sep=",", what="") > Read 4 items > [1] "a" "" "b" "" > > -- >O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B > c/ /'_

Re: [R] strsplit on comma, with a trailing comma in input

2007-12-03 Thread Peter Dalgaard
dankelley wrote: > I have a comma-separated data file in which trailing commas sometimes occur. > I am using strsplit to extract the data from this file, and it seems great > except in cases with trailing comma characters. > > The example below illustrates. What I'd like is to get a fourth elemen

Re: [R] strsplit on comma, with a trailing comma in input

2007-12-03 Thread Gabor Grothendieck
Try appending another comma: strsplit(paste("a,,b,", ",", sep = ""), ",") On Dec 3, 2007 6:22 PM, dankelley <[EMAIL PROTECTED]> wrote: > > I have a comma-separated data file in which trailing commas sometimes occur. > I am using strsplit to extract the data from this file, and it seems great > e

Re: [R] strsplit on comma, with a trailing comma in input

2007-12-03 Thread Benilton Carvalho
my understanding is that this behavior is known (the help file mentions something along these lines in the example). i'd use something like: theText <- "a,,b," theText <- gsub("\\,$", ", ", theText) and then use strsplit() on "theText" b On Dec 3, 2007, at 6:22 PM, dankelley wrote: I hav

[R] strsplit on comma, with a trailing comma in input

2007-12-03 Thread dankelley
I have a comma-separated data file in which trailing commas sometimes occur. I am using strsplit to extract the data from this file, and it seems great except in cases with trailing comma characters. The example below illustrates. What I'd like is to get a fourth element in the answer, being an

Re: [R] strsplit

2007-10-22 Thread Dirk Eddelbuettel
On 22 October 2007 at 00:43, Edna Bell wrote: | Hello R Gurus: | | I would like to take a character string and split at the $ sign. | | I thought that strsplit would do it, but here are the results: | | > vv | [1] "whine$ts1" | > vv | [1] "whine$ts1" | > strsplit(vv,"$") | [[1]] | [1] "whine$ts

Re: [R] strsplit

2007-10-21 Thread Prof Brian Ripley
On Mon, 22 Oct 2007, Edna Bell wrote: > Hello R Gurus: > > I would like to take a character string and split at the $ sign. > > I thought that strsplit would do it, but here are the results: > >> vv > [1] "whine$ts1" >> vv > [1] "whine$ts1" >> strsplit(vv,"$") > [[1]] > [1] "whine$ts1" > > > Does

Re: [R] strsplit

2007-10-21 Thread Moshe Olshansky
Try strsplit(vv,"$",fixed=TRUE) --- Edna Bell <[EMAIL PROTECTED]> wrote: > Hello R Gurus: > > I would like to take a character string and split at > the $ sign. > > I thought that strsplit would do it, but here are > the results: > > > vv > [1] "whine$ts1" > > vv > [1] "whine$ts1" > > strspli

[R] strsplit

2007-10-21 Thread Edna Bell
Hello R Gurus: I would like to take a character string and split at the $ sign. I thought that strsplit would do it, but here are the results: > vv [1] "whine$ts1" > vv [1] "whine$ts1" > strsplit(vv,"$") [[1]] [1] "whine$ts1" Does anyone have any suggestions, please? Thanks, Edna Bell __