Here is one way of solving it:

> x <-  c('0(a=1)'   ,'0(b=1)'  ,'0.133(b=1)'   ,'0.555(a=1)'
,'>5.32(a=1)')
> # "(" and ")" have special meaning in regular expressions so they have to
be escaped
> (y <- as.numeric(gsub("\\(.*\\ <file://(.*//>)|>", "", x)))
[1] 0.000 0.000 0.133 0.555 5.320
> # find "a=1" to divide by 5
> a.equal <- grep('a=1', x)
> y[a.equal] <- y[a.equal] / 5
> y
[1] 0.000 0.000 0.133 0.111 1.064
>
>


On Sat, May 23, 2009 at 2:25 AM, andyer weng <nzand...@gmail.com> wrote:

> Dear all,
> I need to clean up one variables in a dataset.
> e.g. lets say the dataset is "trial", the variable for cleaning up is "V1"
> >trial$V1
> [1] 0(a=1)   0(b=1)  0.133(b=1)   0.555(a=1)  >5.32(a=1)
> what i need to do is to remove the text (a=1) and (b=1) and the ">" in the
> V1, and then convert to a numeric variable, and als I am aslo requested
> that
> when the value has a=1, the value needs to be divided by 5.
> what I did is:
> trialchara<-as.character(trial$V1)
> trialnum<-gsub("(a=1)|(b=1)|>","",trialchara)
> the result is
> [1] "0 ()" "0 ()" "0.133 ()" "0.555 ()" "5.32 ()"
> How can I get rid of the () symbol?
> How can I do this part "when the value has a=1, the value needs to be
> divided by 5." ?
> Can anyone please give me some hints here?
> Thanks a lot.
> John
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to