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
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
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
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
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
5 matches
Mail list logo