Re: [R] how to extract the 1st field from a vector of strings

2010-05-31 Thread Gabor Grothendieck
Try replacing a space followed by anything (.*) with the empty string: > x <- c("hsa-let-7a MIMAT062 Homo sapiens let-7a", + "hsa-let-7a* MIMAT0004481 Homo sapiens let-7a*", + "hsa-let-7a-2* MIMAT0010195 Homo sapiens let-7a-2*") > > sub(" .*", "", x) [1] "hsa-let-7a""hsa-let-7a*" "hsa-le

Re: [R] how to extract the 1st field from a vector of strings

2010-05-31 Thread Henrique Dallazuanna
My mistake: "\\1" is a backreference - see replacement argument in ?gsub. This work: gsub("(.*) MIMA.*", "\\1", desc) On Mon, May 31, 2010 at 2:00 PM, Juliet Hannah wrote: > What is the meaning of "\\1" here? Thanks. > > desc <- c("hsa-let-7a MIMAT062 Homo sapiens let-7a","hsa-let-7a* > MI

Re: [R] how to extract the 1st field from a vector of strings

2010-05-31 Thread Juliet Hannah
What is the meaning of "\\1" here? Thanks. desc <- c("hsa-let-7a MIMAT062 Homo sapiens let-7a","hsa-let-7a* MIMAT0004481 Homo sapiens let-7a*","hsa-let-7a-2* MIMAT0010195 Homo sapiens let-7a-2*") I'm missing something: > gsub(" MIMA.*", "\\1", desc) [1] "hsa-let-7a""hsa-let-7a*" "hsa-l

Re: [R] how to extract the 1st field from a vector of strings

2010-05-27 Thread Henrique Dallazuanna
Try this: gsub(" MIMA.*", "\\1", desc) On Thu, May 27, 2010 at 11:37 AM, wrote: > I have the following vector of strings (shown only the first 3 elements) > > > desc[1:3] > [1] "hsa-let-7a MIMAT062 Homo sapiens let-7a" > [2] "hsa-let-7a* MIMAT0004481 Homo sapiens let-7a*" > [3] "hsa-let-7a

[R] how to extract the 1st field from a vector of strings

2010-05-27 Thread mauede
I have the following vector of strings (shown only the first 3 elements) > desc[1:3] [1] "hsa-let-7a MIMAT062 Homo sapiens let-7a" [2] "hsa-let-7a* MIMAT0004481 Homo sapiens let-7a*" [3] "hsa-let-7a-2* MIMAT0010195 Homo sapiens let-7a-2*" > is.vector(desc) [1] TRUE > A <- unlist(strs